unit Azure.CognitiveServices.TextAnalytics.HTTP;

interface

uses
  System.Classes,
  System.JSON,
  System.Net.URLClient,
  System.SysUtils,
  Azure.CognitiveServices.Core.HTTP,
  Azure.CognitiveServices.TextAnalytics.Types;

type

  TAcsTextAnalyticsHttpBroker = class(TAcsHttpBroker<TAcsTextAnalyticsRequest, TAcsTextAnalyticsResponse>)
  protected
    procedure DoParseResponseJson(const AJSONObject: TJSONObject;
      out AResponse: TAcsTextAnalyticsResponse); override;
    procedure DoPrepareRequestStream(const ARequest: TAcsTextAnalyticsRequest;
      var AStream: TStream); override;
  end;

implementation

uses
  Azure.CognitiveServices.TextAnalytics.JSON;

procedure TAcsTextAnalyticsHttpBroker.DoParseResponseJson(
  const AJSONObject: TJSONObject;
  out AResponse: TAcsTextAnalyticsResponse);
begin
  inherited;
  TAcsTextAnalyticsJSON.Parse(AJSONObject, AResponse);
end;

procedure TAcsTextAnalyticsHttpBroker.DoPrepareRequestStream(
  const ARequest: TAcsTextAnalyticsRequest; var AStream: TStream);
var
  LBody: TJSONObject;
begin
  inherited;
  LBody := TAcsTextAnalyticsJSON.ToJSON(ARequest);
  try
    AStream := TStringStream.Create(LBody.ToString, TEncoding.UTF8);
  finally
    LBody.Free;
  end;
end;

end.
