Skip to content

Commit

Permalink
Compatibilidade com Lazarus
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Oct 9, 2023
1 parent 3413bff commit 354a2b2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 40 deletions.
16 changes: 7 additions & 9 deletions samples/client/lazarus/Samples.lpi
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="Samples"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
Expand All @@ -24,15 +25,11 @@
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<RequiredPackages Count="1">
<Item1>
<PackageName Value="indylaz"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
Expand All @@ -43,6 +40,7 @@
<Filename Value="src\samples.main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="FrmMain"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Samples.Main"/>
</Unit1>
Expand Down
13 changes: 6 additions & 7 deletions src/RESTRequest4D.Request.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ TRequestClient = class(TInterfacedObject, IRequest)
FRESTResponse: TRESTResponse;
FRESTClient: TRESTClient;
FRetries: Integer;
FOnBeforeExecute: TProc<IRequest>;
FOnAfterExecute: TProc<IRequest,IResponse>;
FOnBeforeExecute: TRR4DCallbackOnBeforeExecute;
FOnAfterExecute: TRR4DCallbackOnAfterExecute;
procedure ExecuteRequest;
procedure DoJoinComponents;
function PrepareUrlSegments(const AValue: string): string;
Expand Down Expand Up @@ -47,8 +47,8 @@ TRequestClient = class(TInterfacedObject, IRequest)
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down Expand Up @@ -347,7 +347,6 @@ procedure TRequestClient.DoAfterExecute(Sender: TCustomRESTRequest);
begin
if Assigned(FOnAfterExecute) then
FOnAfterExecute(Self, FResponse);

for LAdapter in FAdapters do
LAdapter.Execute(FRESTResponse.Content);
end;
Expand Down Expand Up @@ -444,13 +443,13 @@ function TRequestClient.Retry(const ARetries: Integer): IRequest;
FRetries := ARetries;
end;

function TRequestClient.OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function TRequestClient.OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
begin
Result := Self;
FOnBeforeExecute := AOnBeforeExecute;
end;

function TRequestClient.OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function TRequestClient.OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
begin
Result := Self;
FOnAfterExecute := AOnAfterExecute;
Expand Down
14 changes: 12 additions & 2 deletions src/RESTRequest4D.Request.Contract.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ interface
{$ENDIF}

type
IRequest = interface;

{$IF DEFINED(FPC)}
TRR4DCallbackOnBeforeExecute = procedure(const Req: IRequest);
TRR4DCallbackOnAfterExecute = procedure(const Req: IRequest; const Res: IResponse);
{$ELSE}
TRR4DCallbackOnBeforeExecute = reference to procedure(const Req: IRequest);
TRR4DCallbackOnAfterExecute = reference to procedure(const Req: IRequest; const Res: IResponse);
{$ENDIF}

IRequest = interface
['{2C882459-F4C3-4854-8F7A-F68E8F8DE98E}']
function AcceptEncoding: string; overload;
Expand Down Expand Up @@ -49,8 +59,8 @@ interface
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down
23 changes: 22 additions & 1 deletion src/RESTRequest4D.Request.FPHTTPClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ TFile = class
destructor Destroy; override;
end;

{ TRequestFPHTTPClient }

TRequestFPHTTPClient = class(TInterfacedObject, IRequest)
private
FHeaders: Tstrings;
Expand All @@ -36,6 +38,8 @@ TRequestFPHTTPClient = class(TInterfacedObject, IRequest)
FResponse: IResponse;
FStreamSend: TStream;
FRetries: Integer;
FOnBeforeExecute: TRR4DCallbackOnBeforeExecute;
FOnAfterExecute: TRR4DCallbackOnAfterExecute;
procedure ExecuteRequest(const AMethod: TMethodRequest);
function AcceptEncoding: string; overload;
function AcceptEncoding(const AAcceptEncoding: string): IRequest; overload;
Expand All @@ -60,6 +64,8 @@ TRequestFPHTTPClient = class(TInterfacedObject, IRequest)
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down Expand Up @@ -304,6 +310,18 @@ function TRequestFPHTTPClient.Retry(const ARetries: Integer): IRequest;
FRetries := ARetries;
end;

function TRequestFPHTTPClient.OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
begin
Result := Self;
FOnBeforeExecute := AOnBeforeExecute;
end;

function TRequestFPHTTPClient.OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
begin
Result := Self;
FOnAfterExecute := AOnAfterExecute;
end;

function TRequestFPHTTPClient.Get: IResponse;
begin
Result := FResponse;
Expand Down Expand Up @@ -592,13 +610,16 @@ procedure TRequestFPHTTPClient.DoAfterExecute(const Sender: TObject; const AResp
var
LAdapter: IRequestAdapter;
begin
if Assigned(FOnAfterExecute) then
FOnAfterExecute(Self, FResponse);
for LAdapter in FAdapters do
LAdapter.Execute(FResponse.Content);
end;

procedure TRequestFPHTTPClient.DoBeforeExecute(const Sender: TFPHTTPClient);
begin
// virtual method
if Assigned(FOnBeforeExecute) then
FOnBeforeExecute(Self);
end;

constructor TRequestFPHTTPClient.Create;
Expand Down
13 changes: 6 additions & 7 deletions src/RESTRequest4D.Request.Indy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ TRequestIndy = class(TInterfacedObject, IRequest)
FStreamSend: TStream;
FStreamResult: TStringStream;
FRetries: Integer;
FOnBeforeExecute: TProc<IRequest>;
FOnAfterExecute: TProc<IRequest,IResponse>;
FOnBeforeExecute: TRR4DCallbackOnBeforeExecute;
FOnAfterExecute: TRR4DCallbackOnAfterExecute;
procedure ExecuteRequest(const AMethod: TMethodRequest);
function AcceptEncoding: string; overload;
function AcceptEncoding(const AAcceptEncoding: string): IRequest; overload;
Expand All @@ -57,8 +57,8 @@ TRequestIndy = class(TInterfacedObject, IRequest)
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down Expand Up @@ -232,7 +232,6 @@ procedure TRequestIndy.DoAfterExecute;
begin
if Assigned(FOnAfterExecute) then
FOnAfterExecute(Self, FResponse);

for LAdapter in FAdapters do
LAdapter.Execute(FResponse.Content);
end;
Expand Down Expand Up @@ -674,13 +673,13 @@ function TRequestIndy.Retry(const ARetries: Integer): IRequest;
FRetries := ARetries;
end;

function TRequestIndy.OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function TRequestIndy.OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
begin
Result := Self;
FOnBeforeExecute := AOnBeforeExecute;
end;

function TRequestIndy.OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function TRequestIndy.OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
begin
Result := Self;
FOnAfterExecute := AOnAfterExecute;
Expand Down
13 changes: 6 additions & 7 deletions src/RESTRequest4D.Request.NetHTTP.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ TRequestNetHTTP = class(TInterfacedObject, IRequest)
FStreamSend: TStream;
FStreamResult: TStringStream;
FRetries: Integer;
FOnBeforeExecute: TProc<IRequest>;
FOnAfterExecute: TProc<IRequest,IResponse>;
FOnBeforeExecute: TRR4DCallbackOnBeforeExecute;
FOnAfterExecute: TRR4DCallbackOnAfterExecute;
function ExecuteRequest(const AMethod: TMethodRequest): IHTTPResponse;
function AcceptEncoding: string; overload;
function AcceptEncoding(const AAcceptEncoding: string): IRequest; overload;
Expand All @@ -48,8 +48,8 @@ TRequestNetHTTP = class(TInterfacedObject, IRequest)
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down Expand Up @@ -446,7 +446,6 @@ procedure TRequestNetHTTP.DoAfterExecute(const Sender: TObject; const AResponse:
begin
if Assigned(FOnAfterExecute) then
FOnAfterExecute(Self, FResponse);

for LAdapter in FAdapters do
LAdapter.Execute(FResponse.Content);
end;
Expand Down Expand Up @@ -632,13 +631,13 @@ function TRequestNetHTTP.Retry(const ARetries: Integer): IRequest;
FRetries := ARetries;
end;

function TRequestNetHTTP.OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function TRequestNetHTTP.OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
begin
Result := Self;
FOnBeforeExecute := AOnBeforeExecute;
end;

function TRequestNetHTTP.OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function TRequestNetHTTP.OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
begin
Result := Self;
FOnAfterExecute := AOnAfterExecute;
Expand Down
13 changes: 6 additions & 7 deletions src/RESTRequest4D.Request.Synapse.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ TRequestSynapse = class(TInterfacedObject, IRequest)
FResponse: IResponse;
FStreamSend: TStream;
FRetries: Integer;
FOnBeforeExecute: TProc<IRequest>;
FOnAfterExecute: TProc<IRequest,IResponse>;
FOnBeforeExecute: TRR4DCallbackOnBeforeExecute;
FOnAfterExecute: TRR4DCallbackOnAfterExecute;
procedure ExecuteRequest(const AMethod: TMethodRequest);
function AcceptEncoding: string; overload;
function AcceptEncoding(const AAcceptEncoding: string): IRequest; overload;
Expand All @@ -70,8 +70,8 @@ TRequestSynapse = class(TInterfacedObject, IRequest)
function TokenBearer(const AToken: string): IRequest;
function BasicAuthentication(const AUsername, APassword: string): IRequest;
function Retry(const ARetries: Integer): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
function OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
function Get: IResponse;
function Post: IResponse;
function Put: IResponse;
Expand Down Expand Up @@ -325,13 +325,13 @@ function TRequestSynapse.Retry(const ARetries: Integer): IRequest;
FRetries := ARetries;
end;

function TRequestSynapse.OnBeforeExecute(const AOnBeforeExecute: TProc<IRequest>): IRequest;
function TRequestSynapse.OnBeforeExecute(const AOnBeforeExecute: TRR4DCallbackOnBeforeExecute): IRequest;
begin
Result := Self;
FOnBeforeExecute := AOnBeforeExecute;
end;

function TRequestSynapse.OnAfterExecute(const AOnAfterExecute: TProc<IRequest,IResponse>): IRequest;
function TRequestSynapse.OnAfterExecute(const AOnAfterExecute: TRR4DCallbackOnAfterExecute): IRequest;
begin
Result := Self;
FOnAfterExecute := AOnAfterExecute;
Expand Down Expand Up @@ -668,7 +668,6 @@ procedure TRequestSynapse.DoAfterExecute(const Sender: TObject; const AResponse:
begin
if Assigned(FOnAfterExecute) then
FOnAfterExecute(Self, FResponse);

for LAdapter in FAdapters do
LAdapter.Execute(FResponse.Content);
end;
Expand Down

0 comments on commit 354a2b2

Please sign in to comment.