Skip to content

Commit

Permalink
Update May 26, 2023
Browse files Browse the repository at this point in the history
- Tested RealtimeDb function
- Adjusted RealitimeDb
- Changed method Version to be static
  • Loading branch information
rafael-figueiredo-alves committed May 27, 2023
1 parent 5009bb3 commit 9523afa
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 24 deletions.
52 changes: 47 additions & 5 deletions Demos/Simple Demo/UnitMain.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ object Form2: TForm2
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnCreate = FormCreate
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 112.000000000000000000
Position.Y = 96.000000000000000000
TabOrder = 0
Text = 'Button1'
Text = 'SignIn'
OnClick = Button1Click
end
object Memo1: TMemo
Expand All @@ -28,10 +29,10 @@ object Form2: TForm2
Viewport.Height = 253.000000000000000000
end
object Button2: TButton
Position.X = 424.000000000000000000
Position.Y = 96.000000000000000000
Position.X = 417.000000000000000000
Position.Y = 98.000000000000000000
TabOrder = 2
Text = 'Button2'
Text = 'Storage'
OnClick = Button2Click
end
object Edit1: TEdit
Expand All @@ -57,7 +58,7 @@ object Form2: TForm2
Position.X = 248.000000000000000000
Position.Y = 8.000000000000000000
TabOrder = 6
Text = 'Button3'
Text = 'Load Picture'
OnClick = Button3Click
end
object OpenDialog1: TOpenDialog
Expand All @@ -66,4 +67,45 @@ object Form2: TForm2
Left = 496
Top = 8
end
object Button4: TButton
Position.X = 112.000000000000000000
Position.Y = 393.000000000000000000
Size.Width = 129.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 8
Text = 'Get Version Endpoint'
OnClick = Button4Click
end
object Button5: TButton
Position.X = 249.000000000000000000
Position.Y = 393.000000000000000000
Size.Width = 201.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 9
Text = 'Get an endpoint that needs auth'
OnClick = Button5Click
end
object Label1: TLabel
Position.X = 472.000000000000000000
Position.Y = 455.000000000000000000
Size.Width = 97.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
Text = 'Vers'#227'o eFirebase:'
TabOrder = 10
end
object Label2: TLabel
StyledSettings = [Family, FontColor]
Position.X = 571.000000000000000000
Position.Y = 455.000000000000000000
Size.Width = 62.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
TextSettings.Font.Size = 14.000000000000000000
TextSettings.Font.StyleExt = {00070000000000000004000000}
Text = 'Label2'
TabOrder = 11
end
end
54 changes: 53 additions & 1 deletion Demos/Simple Demo/UnitMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ TForm2 = class(TForm)
OpenDialog1: TOpenDialog;
Image1: TImage;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
Expand All @@ -32,7 +39,7 @@ TForm2 = class(TForm)
implementation

uses
eFirebase, eFirebase.Interfaces, eFirebase.Types;
eFirebase, eFirebase.Interfaces, eFirebase.Types, System.JSON;

{$R *.fmx}

Expand Down Expand Up @@ -112,4 +119,49 @@ procedure TForm2.Button3Click(Sender: TObject);
end;
end;

procedure TForm2.Button4Click(Sender: TObject);
var
RealTime: ieFirebaseRealtimeResponse;
begin
RealTime := TeFirebase.New
.RealTimeDB('etasks-d6988')
.Endpoint('/etasks/v1')
.Collection('version')
.ReadWithoutFilters;
Memo1.Lines.Add(RealTime.StatusCode.ToString);
Memo1.Lines.Add(RealTime.ETag);
Memo1.Lines.Add(RealTime.AsJSONstr);
end;

procedure TForm2.Button5Click(Sender: TObject);
var
RealTime: ieFirebaseRealtimeResponse;
arrJSON: tjsonarray;
teste: string;
begin
RealTime := TeFirebase.New
.RealTimeDB('etasks-d6988')
.AccessToken(Edit1.Text)
.Endpoint('etasks/v1/categories')
.Collection('X6xl2bc50rTBTjEevxySh1SQaMb2')
.ReadWithoutFilters;
Memo1.Lines.Add(RealTime.StatusCode.ToString);
Memo1.Lines.Add(RealTime.ETag);
Memo1.Lines.Add(RealTime.AsJSONstr);
arrJSON := RealTime.AsJSONArray;
Memo1.Lines.Add(arrJSON.ToString);
if arrJSON.Items[0].TryGetValue<string>('id', teste) then
Memo1.Lines.Add(teste);
if arrJSON.Items[0].TryGetValue<string>('cat_icon', teste) then
Memo1.Lines.Add(teste);
if arrJSON.Items[0].TryGetValue<string>('categoria', teste) then
Memo1.Lines.Add(teste);
arrJSON.DisposeOf;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
Label2.Text := TeFirebase.Version;
end;

end.
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,33 @@ function TeFirebaseRealtimeResponse.AsJSONArray: TJSONArray;
NewObj : TJSONObject;
Par : integer;
Valor : TJsonObject;

function RemoveQuotes(const text: string) : string;
begin
Result := text.Replace('"', '');
Result := Result.TrimLeft;
Result := Result.TrimRight;
end;
begin
Obj := Self.AsJSONObj;
try
Result := TJSONArray.Create;

for Registro := 0 to Obj.Count-1 do
begin
NewObj := TJSONObject.Create;
NewObj.AddPair('id', RemoveQuotes(Obj.Pairs[Registro].JsonString.ToString));
Valor := Obj.Pairs[Registro].JsonValue as TJSONObject;
for Par := 0 to Valor.Count-1 do
begin
NewObj.AddPair(RemoveQuotes(Valor.Pairs[par].JsonString.ToString), RemoveQuotes(Valor.Pairs[par].JsonValue.ToString));
end;
Result.Add(NewObj);
end;
finally
Obj.DisposeOf;
end;

Result := TJSONArray.Create;

for Registro := 0 to Obj.Count-1 do
begin
NewObj := TJSONObject.Create;
NewObj.AddPair('id', Obj.Pairs[Registro].JsonString.ToString);
Valor := Obj.Pairs[Registro].JsonValue as TJSONObject;
for Par := 0 to Valor.Count-1 do
begin
NewObj.AddPair(Valor.Pairs[par].JsonString.ToString, Valor.Pairs[par].JsonValue.ToString);
end;
Result.Add(NewObj);
end;
end;

function TeFirebaseRealtimeResponse.AsDataSet(out DataSet: tDataSet) : integer;
Expand Down
1 change: 0 additions & 1 deletion source/eFirebase.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ interface
function RealTimeDB(const ProjectCode: string): ieFirebaseRealtime;
function Storage(const ProjectCode: string): ieFirebaseStorage;
function Firestore(const API_Key: string): ieFirebaseFirestore;
function Version: string;
end;

implementation
Expand Down
9 changes: 5 additions & 4 deletions source/eFirebase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ interface
function RealTimeDB(const ProjectCode: string): ieFirebaseRealtime;
function Storage(const ProjectCode: string): ieFirebaseStorage;
function Firestore(const API_Key: string): ieFirebaseFirestore;
function Version: string;
class function Version: string;
End;

const
eFirebase_VERSION = '0.0.11-a';
eFirebase_VERSION = '0.0.12-a';

implementation

uses
eFirebase.Auth,
eFirebase.Storage, eFirebase.RealTimeDB;
eFirebase.Storage,
eFirebase.RealTimeDB;

{ TeFirebase }

Expand Down Expand Up @@ -75,7 +76,7 @@ function TeFirebase.Storage(const ProjectCode: string): ieFirebaseStorage;
Result := TeFirebaseStorage.New(ProjectCode);
end;

function TeFirebase.Version: string;
class function TeFirebase.Version: string;
begin
Result := eFirebase_VERSION;
end;
Expand Down

0 comments on commit 9523afa

Please sign in to comment.