Skip to content

Commit

Permalink
Solve issue #22: IFirebaseFunctions.CallFunctionSynchronous does not …
Browse files Browse the repository at this point in the history
…return the resulting JSON Object
  • Loading branch information
SchneiderInfosystems committed Aug 27, 2019
1 parent 1913457 commit 5b2f4df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Source/FB4D.Functions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ TFirebaseFunctions = class(TInterfacedObject, IFirebaseFunctions)
procedure CallFunction(OnSuccess: TOnFunctionSuccess;
OnRequestError: TOnRequestError; const FunctionName: string;
Params: TJSONObject = nil);
procedure CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject = nil);
function CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject = nil): TJSONObject;
end;

implementation
Expand Down Expand Up @@ -134,12 +134,13 @@ procedure TFirebaseFunctions.OnResp(const RequestID: string;
end;
end;

procedure TFirebaseFunctions.CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject);
function TFirebaseFunctions.CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject): TJSONObject;
var
Request: IFirebaseRequest;
Response: IFirebaseResponse;
Data: TJSONObject;
Obj: TJSONObject;
begin
Data := TJSONObject.Create;
try
Expand All @@ -148,6 +149,10 @@ procedure TFirebaseFunctions.CallFunctionSynchronous(const FunctionName: string;
Response := Request.SendRequestSynchronous([FunctionName], rmPost, Data,
nil, tmBearer);
Response.CheckForJSONObj;
Obj := Response.GetContentAsJSONObj;
if not Obj.TryGetValue('result', result) then
raise EFirebaseFunctions.CreateFmt(rsUnexpectedResult,
[FunctionName, Obj.ToJSON]);
finally
Data.Free;
end;
Expand Down
5 changes: 3 additions & 2 deletions Source/FB4D.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,15 @@ EFirebaseAuthentication = class(Exception);
function GetRefreshToken: string;
end;

EFirebaseFunctions = class(Exception);
TOnFunctionSuccess = procedure(const Info: string; ResultObj: TJSONObject) of
object;
IFirebaseFunctions = interface(IInterface)
procedure CallFunction(OnSuccess: TOnFunctionSuccess;
OnRequestError: TOnRequestError; const FunctionName: string;
Params: TJSONObject = nil);
procedure CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject = nil);
function CallFunctionSynchronous(const FunctionName: string;
Params: TJSONObject = nil): TJSONObject;
end;

IStorageObject = interface;
Expand Down

0 comments on commit 5b2f4df

Please sign in to comment.