diff --git a/Demos/Simple Demo/UnitMain.fmx b/Demos/Simple Demo/UnitMain.fmx index d26d449..d182bbd 100644 --- a/Demos/Simple Demo/UnitMain.fmx +++ b/Demos/Simple Demo/UnitMain.fmx @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Demos/Simple Demo/UnitMain.pas b/Demos/Simple Demo/UnitMain.pas index 9e62fa4..ad453ae 100644 --- a/Demos/Simple Demo/UnitMain.pas +++ b/Demos/Simple Demo/UnitMain.pas @@ -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 @@ -32,7 +39,7 @@ TForm2 = class(TForm) implementation uses - eFirebase, eFirebase.Interfaces, eFirebase.Types; + eFirebase, eFirebase.Interfaces, eFirebase.Types, System.JSON; {$R *.fmx} @@ -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('id', teste) then + Memo1.Lines.Add(teste); + if arrJSON.Items[0].TryGetValue('cat_icon', teste) then + Memo1.Lines.Add(teste); + if arrJSON.Items[0].TryGetValue('categoria', teste) then + Memo1.Lines.Add(teste); + arrJSON.DisposeOf; +end; + +procedure TForm2.FormCreate(Sender: TObject); +begin + Label2.Text := TeFirebase.Version; +end; + end. diff --git a/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas b/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas index 37e268e..8e0ed8c 100644 --- a/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas +++ b/source/FirebaseLib/Response Classes/eFirebase.Responses.RealTimeDB.pas @@ -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; diff --git a/source/eFirebase.Interfaces.pas b/source/eFirebase.Interfaces.pas index 5d69bec..29c0f55 100644 --- a/source/eFirebase.Interfaces.pas +++ b/source/eFirebase.Interfaces.pas @@ -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 diff --git a/source/eFirebase.pas b/source/eFirebase.pas index 4f24440..8c5e81d 100644 --- a/source/eFirebase.pas +++ b/source/eFirebase.pas @@ -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 } @@ -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;