123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639 |
- unit googleappstate;
- {$MODE objfpc}
- {$H+}
- interface
- uses sysutils, classes, googleservice, restbase, googlebase;
- type
-
- //Top-level schema types
- TGetResponse = Class;
- TListResponse = Class;
- TUpdateRequest = Class;
- TWriteResult = Class;
- TGetResponseArray = Array of TGetResponse;
- TListResponseArray = Array of TListResponse;
- TUpdateRequestArray = Array of TUpdateRequest;
- TWriteResultArray = Array of TWriteResult;
- //Anonymous types, using auto-generated names
- TListResponseTypeitemsArray = Array of TGetResponse;
-
- { --------------------------------------------------------------------
- TGetResponse
- --------------------------------------------------------------------}
-
- TGetResponse = Class(TGoogleBaseObject)
- Private
- FcurrentStateVersion : String;
- Fdata : String;
- Fkind : String;
- FstateKey : integer;
- Protected
- //Property setters
- Procedure SetcurrentStateVersion(AIndex : Integer; const AValue : String); virtual;
- Procedure Setdata(AIndex : Integer; const AValue : String); virtual;
- Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
- Procedure SetstateKey(AIndex : Integer; const AValue : integer); virtual;
- Public
- Published
- Property currentStateVersion : String Index 0 Read FcurrentStateVersion Write SetcurrentStateVersion;
- Property data : String Index 8 Read Fdata Write Setdata;
- Property kind : String Index 16 Read Fkind Write Setkind;
- Property stateKey : integer Index 24 Read FstateKey Write SetstateKey;
- end;
- TGetResponseClass = Class of TGetResponse;
-
- { --------------------------------------------------------------------
- TListResponse
- --------------------------------------------------------------------}
-
- TListResponse = Class(TGoogleBaseObject)
- Private
- Fitems : TListResponseTypeitemsArray;
- Fkind : String;
- FmaximumKeyCount : integer;
- Protected
- //Property setters
- Procedure Setitems(AIndex : Integer; const AValue : TListResponseTypeitemsArray); virtual;
- Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
- Procedure SetmaximumKeyCount(AIndex : Integer; const AValue : integer); virtual;
- //2.6.4. bug workaround
- {$IFDEF VER2_6}
- Procedure SetArrayLength(Const AName : String; ALength : Longint); override;
- {$ENDIF VER2_6}
- Public
- Published
- Property items : TListResponseTypeitemsArray Index 0 Read Fitems Write Setitems;
- Property kind : String Index 8 Read Fkind Write Setkind;
- Property maximumKeyCount : integer Index 16 Read FmaximumKeyCount Write SetmaximumKeyCount;
- end;
- TListResponseClass = Class of TListResponse;
-
- { --------------------------------------------------------------------
- TUpdateRequest
- --------------------------------------------------------------------}
-
- TUpdateRequest = Class(TGoogleBaseObject)
- Private
- Fdata : String;
- Fkind : String;
- Protected
- //Property setters
- Procedure Setdata(AIndex : Integer; const AValue : String); virtual;
- Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
- Public
- Published
- Property data : String Index 0 Read Fdata Write Setdata;
- Property kind : String Index 8 Read Fkind Write Setkind;
- end;
- TUpdateRequestClass = Class of TUpdateRequest;
-
- { --------------------------------------------------------------------
- TWriteResult
- --------------------------------------------------------------------}
-
- TWriteResult = Class(TGoogleBaseObject)
- Private
- FcurrentStateVersion : String;
- Fkind : String;
- FstateKey : integer;
- Protected
- //Property setters
- Procedure SetcurrentStateVersion(AIndex : Integer; const AValue : String); virtual;
- Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
- Procedure SetstateKey(AIndex : Integer; const AValue : integer); virtual;
- Public
- Published
- Property currentStateVersion : String Index 0 Read FcurrentStateVersion Write SetcurrentStateVersion;
- Property kind : String Index 8 Read Fkind Write Setkind;
- Property stateKey : integer Index 16 Read FstateKey Write SetstateKey;
- end;
- TWriteResultClass = Class of TWriteResult;
-
- { --------------------------------------------------------------------
- TStatesResource
- --------------------------------------------------------------------}
-
-
- //Optional query Options for TStatesResource, method Clear
-
- TStatesClearOptions = Record
- currentDataVersion : String;
- end;
-
-
- //Optional query Options for TStatesResource, method List
-
- TStatesListOptions = Record
- includeData : boolean;
- end;
-
-
- //Optional query Options for TStatesResource, method Update
-
- TStatesUpdateOptions = Record
- currentStateVersion : String;
- end;
-
- TStatesResource = Class(TGoogleResource)
- Public
- Class Function ResourceName : String; override;
- Class Function DefaultAPI : TGoogleAPIClass; override;
- Function Clear(stateKey: integer; AQuery : string = '') : TWriteResult;
- Function Clear(stateKey: integer; AQuery : TStatesclearOptions) : TWriteResult;
- Procedure Delete(stateKey: integer);
- Function Get(stateKey: integer) : TGetResponse;
- Function List(AQuery : string = '') : TListResponse;
- Function List(AQuery : TStateslistOptions) : TListResponse;
- Function Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : string = '') : TWriteResult;
- Function Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : TStatesupdateOptions) : TWriteResult;
- end;
-
-
- { --------------------------------------------------------------------
- TAppstateAPI
- --------------------------------------------------------------------}
-
- TAppstateAPI = Class(TGoogleAPI)
- Private
- FStatesInstance : TStatesResource;
- Function GetStatesInstance : TStatesResource;virtual;
- Public
- //Override class functions with API info
- Class Function APIName : String; override;
- Class Function APIVersion : String; override;
- Class Function APIRevision : String; override;
- Class Function APIID : String; override;
- Class Function APITitle : String; override;
- Class Function APIDescription : String; override;
- Class Function APIOwnerDomain : String; override;
- Class Function APIOwnerName : String; override;
- Class Function APIIcon16 : String; override;
- Class Function APIIcon32 : String; override;
- Class Function APIdocumentationLink : String; override;
- Class Function APIrootUrl : string; override;
- Class Function APIbasePath : string;override;
- Class Function APIbaseURL : String;override;
- Class Function APIProtocol : string;override;
- Class Function APIservicePath : string;override;
- Class Function APIbatchPath : String;override;
- Class Function APIAuthScopes : TScopeInfoArray;override;
- Class Function APINeedsAuth : Boolean;override;
- Class Procedure RegisterAPIResources; override;
- //Add create function for resources
- Function CreateStatesResource(AOwner : TComponent) : TStatesResource;virtual;overload;
- Function CreateStatesResource : TStatesResource;virtual;overload;
- //Add default on-demand instances for resources
- Property StatesResource : TStatesResource Read GetStatesInstance;
- end;
- implementation
- { --------------------------------------------------------------------
- TGetResponse
- --------------------------------------------------------------------}
- Procedure TGetResponse.SetcurrentStateVersion(AIndex : Integer; const AValue : String);
- begin
- If (FcurrentStateVersion=AValue) then exit;
- FcurrentStateVersion:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TGetResponse.Setdata(AIndex : Integer; const AValue : String);
- begin
- If (Fdata=AValue) then exit;
- Fdata:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TGetResponse.Setkind(AIndex : Integer; const AValue : String);
- begin
- If (Fkind=AValue) then exit;
- Fkind:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TGetResponse.SetstateKey(AIndex : Integer; const AValue : integer);
- begin
- If (FstateKey=AValue) then exit;
- FstateKey:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- { --------------------------------------------------------------------
- TListResponse
- --------------------------------------------------------------------}
- Procedure TListResponse.Setitems(AIndex : Integer; const AValue : TListResponseTypeitemsArray);
- begin
- If (Fitems=AValue) then exit;
- Fitems:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TListResponse.Setkind(AIndex : Integer; const AValue : String);
- begin
- If (Fkind=AValue) then exit;
- Fkind:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TListResponse.SetmaximumKeyCount(AIndex : Integer; const AValue : integer);
- begin
- If (FmaximumKeyCount=AValue) then exit;
- FmaximumKeyCount:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- //2.6.4. bug workaround
- {$IFDEF VER2_6}
- Procedure TListResponse.SetArrayLength(Const AName : String; ALength : Longint);
- begin
- Case AName of
- 'items' : SetLength(Fitems,ALength);
- else
- Inherited SetArrayLength(AName,ALength);
- end;
- end;
- {$ENDIF VER2_6}
- { --------------------------------------------------------------------
- TUpdateRequest
- --------------------------------------------------------------------}
- Procedure TUpdateRequest.Setdata(AIndex : Integer; const AValue : String);
- begin
- If (Fdata=AValue) then exit;
- Fdata:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TUpdateRequest.Setkind(AIndex : Integer; const AValue : String);
- begin
- If (Fkind=AValue) then exit;
- Fkind:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- { --------------------------------------------------------------------
- TWriteResult
- --------------------------------------------------------------------}
- Procedure TWriteResult.SetcurrentStateVersion(AIndex : Integer; const AValue : String);
- begin
- If (FcurrentStateVersion=AValue) then exit;
- FcurrentStateVersion:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TWriteResult.Setkind(AIndex : Integer; const AValue : String);
- begin
- If (Fkind=AValue) then exit;
- Fkind:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- Procedure TWriteResult.SetstateKey(AIndex : Integer; const AValue : integer);
- begin
- If (FstateKey=AValue) then exit;
- FstateKey:=AValue;
- MarkPropertyChanged(AIndex);
- end;
- { --------------------------------------------------------------------
- TStatesResource
- --------------------------------------------------------------------}
- Class Function TStatesResource.ResourceName : String;
- begin
- Result:='states';
- end;
- Class Function TStatesResource.DefaultAPI : TGoogleAPIClass;
- begin
- Result:=TappstateAPI;
- end;
- Function TStatesResource.Clear(stateKey: integer; AQuery : string = '') : TWriteResult;
- Const
- _HTTPMethod = 'POST';
- _Path = 'states/{stateKey}/clear';
- _Methodid = 'appstate.states.clear';
- Var
- _P : String;
- begin
- _P:=SubstitutePath(_Path,['stateKey',stateKey]);
- Result:=ServiceCall(_HTTPMethod,_P,AQuery,Nil,TWriteResult) as TWriteResult;
- end;
- Function TStatesResource.Clear(stateKey: integer; AQuery : TStatesclearOptions) : TWriteResult;
- Var
- _Q : String;
- begin
- _Q:='';
- AddToQuery(_Q,'currentDataVersion',AQuery.currentDataVersion);
- Result:=Clear(stateKey,_Q);
- end;
- Procedure TStatesResource.Delete(stateKey: integer);
- Const
- _HTTPMethod = 'DELETE';
- _Path = 'states/{stateKey}';
- _Methodid = 'appstate.states.delete';
- Var
- _P : String;
- begin
- _P:=SubstitutePath(_Path,['stateKey',stateKey]);
- ServiceCall(_HTTPMethod,_P,'',Nil,Nil);
- end;
- Function TStatesResource.Get(stateKey: integer) : TGetResponse;
- Const
- _HTTPMethod = 'GET';
- _Path = 'states/{stateKey}';
- _Methodid = 'appstate.states.get';
- Var
- _P : String;
- begin
- _P:=SubstitutePath(_Path,['stateKey',stateKey]);
- Result:=ServiceCall(_HTTPMethod,_P,'',Nil,TGetResponse) as TGetResponse;
- end;
- Function TStatesResource.List(AQuery : string = '') : TListResponse;
- Const
- _HTTPMethod = 'GET';
- _Path = 'states';
- _Methodid = 'appstate.states.list';
- begin
- Result:=ServiceCall(_HTTPMethod,_Path,AQuery,Nil,TListResponse) as TListResponse;
- end;
- Function TStatesResource.List(AQuery : TStateslistOptions) : TListResponse;
- Var
- _Q : String;
- begin
- _Q:='';
- AddToQuery(_Q,'includeData',AQuery.includeData);
- Result:=List(_Q);
- end;
- Function TStatesResource.Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : string = '') : TWriteResult;
- Const
- _HTTPMethod = 'PUT';
- _Path = 'states/{stateKey}';
- _Methodid = 'appstate.states.update';
- Var
- _P : String;
- begin
- _P:=SubstitutePath(_Path,['stateKey',stateKey]);
- Result:=ServiceCall(_HTTPMethod,_P,AQuery,aUpdateRequest,TWriteResult) as TWriteResult;
- end;
- Function TStatesResource.Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : TStatesupdateOptions) : TWriteResult;
- Var
- _Q : String;
- begin
- _Q:='';
- AddToQuery(_Q,'currentStateVersion',AQuery.currentStateVersion);
- Result:=Update(stateKey,aUpdateRequest,_Q);
- end;
- { --------------------------------------------------------------------
- TAppstateAPI
- --------------------------------------------------------------------}
- Class Function TAppstateAPI.APIName : String;
- begin
- Result:='appstate';
- end;
- Class Function TAppstateAPI.APIVersion : String;
- begin
- Result:='v1';
- end;
- Class Function TAppstateAPI.APIRevision : String;
- begin
- Result:='20160519';
- end;
- Class Function TAppstateAPI.APIID : String;
- begin
- Result:='appstate:v1';
- end;
- Class Function TAppstateAPI.APITitle : String;
- begin
- Result:='Google App State API';
- end;
- Class Function TAppstateAPI.APIDescription : String;
- begin
- Result:='The Google App State API.';
- end;
- Class Function TAppstateAPI.APIOwnerDomain : String;
- begin
- Result:='google.com';
- end;
- Class Function TAppstateAPI.APIOwnerName : String;
- begin
- Result:='Google';
- end;
- Class Function TAppstateAPI.APIIcon16 : String;
- begin
- Result:='http://www.google.com/images/icons/product/search-16.gif';
- end;
- Class Function TAppstateAPI.APIIcon32 : String;
- begin
- Result:='http://www.google.com/images/icons/product/search-32.gif';
- end;
- Class Function TAppstateAPI.APIdocumentationLink : String;
- begin
- Result:='https://developers.google.com/games/services/web/api/states';
- end;
- Class Function TAppstateAPI.APIrootUrl : string;
- begin
- Result:='https://www.googleapis.com/';
- end;
- Class Function TAppstateAPI.APIbasePath : string;
- begin
- Result:='/appstate/v1/';
- end;
- Class Function TAppstateAPI.APIbaseURL : String;
- begin
- Result:='https://www.googleapis.com/appstate/v1/';
- end;
- Class Function TAppstateAPI.APIProtocol : string;
- begin
- Result:='rest';
- end;
- Class Function TAppstateAPI.APIservicePath : string;
- begin
- Result:='appstate/v1/';
- end;
- Class Function TAppstateAPI.APIbatchPath : String;
- begin
- Result:='batch';
- end;
- Class Function TAppstateAPI.APIAuthScopes : TScopeInfoArray;
- begin
- SetLength(Result,1);
- Result[0].Name:='https://www.googleapis.com/auth/appstate';
- Result[0].Description:='View and manage your data for this application';
-
- end;
- Class Function TAppstateAPI.APINeedsAuth : Boolean;
- begin
- Result:=True;
- end;
- Class Procedure TAppstateAPI.RegisterAPIResources;
- begin
- TGetResponse.RegisterObject;
- TListResponse.RegisterObject;
- TUpdateRequest.RegisterObject;
- TWriteResult.RegisterObject;
- end;
- Function TAppstateAPI.GetStatesInstance : TStatesResource;
- begin
- if (FStatesInstance=Nil) then
- FStatesInstance:=CreateStatesResource;
- Result:=FStatesInstance;
- end;
- Function TAppstateAPI.CreateStatesResource : TStatesResource;
- begin
- Result:=CreateStatesResource(Self);
- end;
- Function TAppstateAPI.CreateStatesResource(AOwner : TComponent) : TStatesResource;
- begin
- Result:=TStatesResource.Create(AOwner);
- Result.API:=Self.API;
- end;
- initialization
- TAppstateAPI.RegisterAPI;
- end.
|