googleappstate.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. unit googleappstate;
  2. {$MODE objfpc}
  3. {$H+}
  4. interface
  5. uses sysutils, classes, googleservice, restbase, googlebase;
  6. type
  7. //Top-level schema types
  8. TGetResponse = Class;
  9. TListResponse = Class;
  10. TUpdateRequest = Class;
  11. TWriteResult = Class;
  12. TGetResponseArray = Array of TGetResponse;
  13. TListResponseArray = Array of TListResponse;
  14. TUpdateRequestArray = Array of TUpdateRequest;
  15. TWriteResultArray = Array of TWriteResult;
  16. //Anonymous types, using auto-generated names
  17. TListResponseTypeitemsArray = Array of TGetResponse;
  18. { --------------------------------------------------------------------
  19. TGetResponse
  20. --------------------------------------------------------------------}
  21. TGetResponse = Class(TGoogleBaseObject)
  22. Private
  23. FcurrentStateVersion : String;
  24. Fdata : String;
  25. Fkind : String;
  26. FstateKey : integer;
  27. Protected
  28. //Property setters
  29. Procedure SetcurrentStateVersion(AIndex : Integer; const AValue : String); virtual;
  30. Procedure Setdata(AIndex : Integer; const AValue : String); virtual;
  31. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  32. Procedure SetstateKey(AIndex : Integer; const AValue : integer); virtual;
  33. Public
  34. Published
  35. Property currentStateVersion : String Index 0 Read FcurrentStateVersion Write SetcurrentStateVersion;
  36. Property data : String Index 8 Read Fdata Write Setdata;
  37. Property kind : String Index 16 Read Fkind Write Setkind;
  38. Property stateKey : integer Index 24 Read FstateKey Write SetstateKey;
  39. end;
  40. TGetResponseClass = Class of TGetResponse;
  41. { --------------------------------------------------------------------
  42. TListResponse
  43. --------------------------------------------------------------------}
  44. TListResponse = Class(TGoogleBaseObject)
  45. Private
  46. Fitems : TListResponseTypeitemsArray;
  47. Fkind : String;
  48. FmaximumKeyCount : integer;
  49. Protected
  50. //Property setters
  51. Procedure Setitems(AIndex : Integer; const AValue : TListResponseTypeitemsArray); virtual;
  52. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  53. Procedure SetmaximumKeyCount(AIndex : Integer; const AValue : integer); virtual;
  54. //2.6.4. bug workaround
  55. {$IFDEF VER2_6}
  56. Procedure SetArrayLength(Const AName : String; ALength : Longint); override;
  57. {$ENDIF VER2_6}
  58. Public
  59. Published
  60. Property items : TListResponseTypeitemsArray Index 0 Read Fitems Write Setitems;
  61. Property kind : String Index 8 Read Fkind Write Setkind;
  62. Property maximumKeyCount : integer Index 16 Read FmaximumKeyCount Write SetmaximumKeyCount;
  63. end;
  64. TListResponseClass = Class of TListResponse;
  65. { --------------------------------------------------------------------
  66. TUpdateRequest
  67. --------------------------------------------------------------------}
  68. TUpdateRequest = Class(TGoogleBaseObject)
  69. Private
  70. Fdata : String;
  71. Fkind : String;
  72. Protected
  73. //Property setters
  74. Procedure Setdata(AIndex : Integer; const AValue : String); virtual;
  75. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  76. Public
  77. Published
  78. Property data : String Index 0 Read Fdata Write Setdata;
  79. Property kind : String Index 8 Read Fkind Write Setkind;
  80. end;
  81. TUpdateRequestClass = Class of TUpdateRequest;
  82. { --------------------------------------------------------------------
  83. TWriteResult
  84. --------------------------------------------------------------------}
  85. TWriteResult = Class(TGoogleBaseObject)
  86. Private
  87. FcurrentStateVersion : String;
  88. Fkind : String;
  89. FstateKey : integer;
  90. Protected
  91. //Property setters
  92. Procedure SetcurrentStateVersion(AIndex : Integer; const AValue : String); virtual;
  93. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  94. Procedure SetstateKey(AIndex : Integer; const AValue : integer); virtual;
  95. Public
  96. Published
  97. Property currentStateVersion : String Index 0 Read FcurrentStateVersion Write SetcurrentStateVersion;
  98. Property kind : String Index 8 Read Fkind Write Setkind;
  99. Property stateKey : integer Index 16 Read FstateKey Write SetstateKey;
  100. end;
  101. TWriteResultClass = Class of TWriteResult;
  102. { --------------------------------------------------------------------
  103. TStatesResource
  104. --------------------------------------------------------------------}
  105. //Optional query Options for TStatesResource, method Clear
  106. TStatesClearOptions = Record
  107. currentDataVersion : String;
  108. end;
  109. //Optional query Options for TStatesResource, method List
  110. TStatesListOptions = Record
  111. includeData : boolean;
  112. end;
  113. //Optional query Options for TStatesResource, method Update
  114. TStatesUpdateOptions = Record
  115. currentStateVersion : String;
  116. end;
  117. TStatesResource = Class(TGoogleResource)
  118. Public
  119. Class Function ResourceName : String; override;
  120. Class Function DefaultAPI : TGoogleAPIClass; override;
  121. Function Clear(stateKey: integer; AQuery : string = '') : TWriteResult;
  122. Function Clear(stateKey: integer; AQuery : TStatesclearOptions) : TWriteResult;
  123. Procedure Delete(stateKey: integer);
  124. Function Get(stateKey: integer) : TGetResponse;
  125. Function List(AQuery : string = '') : TListResponse;
  126. Function List(AQuery : TStateslistOptions) : TListResponse;
  127. Function Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : string = '') : TWriteResult;
  128. Function Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : TStatesupdateOptions) : TWriteResult;
  129. end;
  130. { --------------------------------------------------------------------
  131. TAppstateAPI
  132. --------------------------------------------------------------------}
  133. TAppstateAPI = Class(TGoogleAPI)
  134. Private
  135. FStatesInstance : TStatesResource;
  136. Function GetStatesInstance : TStatesResource;virtual;
  137. Public
  138. //Override class functions with API info
  139. Class Function APIName : String; override;
  140. Class Function APIVersion : String; override;
  141. Class Function APIRevision : String; override;
  142. Class Function APIID : String; override;
  143. Class Function APITitle : String; override;
  144. Class Function APIDescription : String; override;
  145. Class Function APIOwnerDomain : String; override;
  146. Class Function APIOwnerName : String; override;
  147. Class Function APIIcon16 : String; override;
  148. Class Function APIIcon32 : String; override;
  149. Class Function APIdocumentationLink : String; override;
  150. Class Function APIrootUrl : string; override;
  151. Class Function APIbasePath : string;override;
  152. Class Function APIbaseURL : String;override;
  153. Class Function APIProtocol : string;override;
  154. Class Function APIservicePath : string;override;
  155. Class Function APIbatchPath : String;override;
  156. Class Function APIAuthScopes : TScopeInfoArray;override;
  157. Class Function APINeedsAuth : Boolean;override;
  158. Class Procedure RegisterAPIResources; override;
  159. //Add create function for resources
  160. Function CreateStatesResource(AOwner : TComponent) : TStatesResource;virtual;overload;
  161. Function CreateStatesResource : TStatesResource;virtual;overload;
  162. //Add default on-demand instances for resources
  163. Property StatesResource : TStatesResource Read GetStatesInstance;
  164. end;
  165. implementation
  166. { --------------------------------------------------------------------
  167. TGetResponse
  168. --------------------------------------------------------------------}
  169. Procedure TGetResponse.SetcurrentStateVersion(AIndex : Integer; const AValue : String);
  170. begin
  171. If (FcurrentStateVersion=AValue) then exit;
  172. FcurrentStateVersion:=AValue;
  173. MarkPropertyChanged(AIndex);
  174. end;
  175. Procedure TGetResponse.Setdata(AIndex : Integer; const AValue : String);
  176. begin
  177. If (Fdata=AValue) then exit;
  178. Fdata:=AValue;
  179. MarkPropertyChanged(AIndex);
  180. end;
  181. Procedure TGetResponse.Setkind(AIndex : Integer; const AValue : String);
  182. begin
  183. If (Fkind=AValue) then exit;
  184. Fkind:=AValue;
  185. MarkPropertyChanged(AIndex);
  186. end;
  187. Procedure TGetResponse.SetstateKey(AIndex : Integer; const AValue : integer);
  188. begin
  189. If (FstateKey=AValue) then exit;
  190. FstateKey:=AValue;
  191. MarkPropertyChanged(AIndex);
  192. end;
  193. { --------------------------------------------------------------------
  194. TListResponse
  195. --------------------------------------------------------------------}
  196. Procedure TListResponse.Setitems(AIndex : Integer; const AValue : TListResponseTypeitemsArray);
  197. begin
  198. If (Fitems=AValue) then exit;
  199. Fitems:=AValue;
  200. MarkPropertyChanged(AIndex);
  201. end;
  202. Procedure TListResponse.Setkind(AIndex : Integer; const AValue : String);
  203. begin
  204. If (Fkind=AValue) then exit;
  205. Fkind:=AValue;
  206. MarkPropertyChanged(AIndex);
  207. end;
  208. Procedure TListResponse.SetmaximumKeyCount(AIndex : Integer; const AValue : integer);
  209. begin
  210. If (FmaximumKeyCount=AValue) then exit;
  211. FmaximumKeyCount:=AValue;
  212. MarkPropertyChanged(AIndex);
  213. end;
  214. //2.6.4. bug workaround
  215. {$IFDEF VER2_6}
  216. Procedure TListResponse.SetArrayLength(Const AName : String; ALength : Longint);
  217. begin
  218. Case AName of
  219. 'items' : SetLength(Fitems,ALength);
  220. else
  221. Inherited SetArrayLength(AName,ALength);
  222. end;
  223. end;
  224. {$ENDIF VER2_6}
  225. { --------------------------------------------------------------------
  226. TUpdateRequest
  227. --------------------------------------------------------------------}
  228. Procedure TUpdateRequest.Setdata(AIndex : Integer; const AValue : String);
  229. begin
  230. If (Fdata=AValue) then exit;
  231. Fdata:=AValue;
  232. MarkPropertyChanged(AIndex);
  233. end;
  234. Procedure TUpdateRequest.Setkind(AIndex : Integer; const AValue : String);
  235. begin
  236. If (Fkind=AValue) then exit;
  237. Fkind:=AValue;
  238. MarkPropertyChanged(AIndex);
  239. end;
  240. { --------------------------------------------------------------------
  241. TWriteResult
  242. --------------------------------------------------------------------}
  243. Procedure TWriteResult.SetcurrentStateVersion(AIndex : Integer; const AValue : String);
  244. begin
  245. If (FcurrentStateVersion=AValue) then exit;
  246. FcurrentStateVersion:=AValue;
  247. MarkPropertyChanged(AIndex);
  248. end;
  249. Procedure TWriteResult.Setkind(AIndex : Integer; const AValue : String);
  250. begin
  251. If (Fkind=AValue) then exit;
  252. Fkind:=AValue;
  253. MarkPropertyChanged(AIndex);
  254. end;
  255. Procedure TWriteResult.SetstateKey(AIndex : Integer; const AValue : integer);
  256. begin
  257. If (FstateKey=AValue) then exit;
  258. FstateKey:=AValue;
  259. MarkPropertyChanged(AIndex);
  260. end;
  261. { --------------------------------------------------------------------
  262. TStatesResource
  263. --------------------------------------------------------------------}
  264. Class Function TStatesResource.ResourceName : String;
  265. begin
  266. Result:='states';
  267. end;
  268. Class Function TStatesResource.DefaultAPI : TGoogleAPIClass;
  269. begin
  270. Result:=TappstateAPI;
  271. end;
  272. Function TStatesResource.Clear(stateKey: integer; AQuery : string = '') : TWriteResult;
  273. Const
  274. _HTTPMethod = 'POST';
  275. _Path = 'states/{stateKey}/clear';
  276. _Methodid = 'appstate.states.clear';
  277. Var
  278. _P : String;
  279. begin
  280. _P:=SubstitutePath(_Path,['stateKey',stateKey]);
  281. Result:=ServiceCall(_HTTPMethod,_P,AQuery,Nil,TWriteResult) as TWriteResult;
  282. end;
  283. Function TStatesResource.Clear(stateKey: integer; AQuery : TStatesclearOptions) : TWriteResult;
  284. Var
  285. _Q : String;
  286. begin
  287. _Q:='';
  288. AddToQuery(_Q,'currentDataVersion',AQuery.currentDataVersion);
  289. Result:=Clear(stateKey,_Q);
  290. end;
  291. Procedure TStatesResource.Delete(stateKey: integer);
  292. Const
  293. _HTTPMethod = 'DELETE';
  294. _Path = 'states/{stateKey}';
  295. _Methodid = 'appstate.states.delete';
  296. Var
  297. _P : String;
  298. begin
  299. _P:=SubstitutePath(_Path,['stateKey',stateKey]);
  300. ServiceCall(_HTTPMethod,_P,'',Nil,Nil);
  301. end;
  302. Function TStatesResource.Get(stateKey: integer) : TGetResponse;
  303. Const
  304. _HTTPMethod = 'GET';
  305. _Path = 'states/{stateKey}';
  306. _Methodid = 'appstate.states.get';
  307. Var
  308. _P : String;
  309. begin
  310. _P:=SubstitutePath(_Path,['stateKey',stateKey]);
  311. Result:=ServiceCall(_HTTPMethod,_P,'',Nil,TGetResponse) as TGetResponse;
  312. end;
  313. Function TStatesResource.List(AQuery : string = '') : TListResponse;
  314. Const
  315. _HTTPMethod = 'GET';
  316. _Path = 'states';
  317. _Methodid = 'appstate.states.list';
  318. begin
  319. Result:=ServiceCall(_HTTPMethod,_Path,AQuery,Nil,TListResponse) as TListResponse;
  320. end;
  321. Function TStatesResource.List(AQuery : TStateslistOptions) : TListResponse;
  322. Var
  323. _Q : String;
  324. begin
  325. _Q:='';
  326. AddToQuery(_Q,'includeData',AQuery.includeData);
  327. Result:=List(_Q);
  328. end;
  329. Function TStatesResource.Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : string = '') : TWriteResult;
  330. Const
  331. _HTTPMethod = 'PUT';
  332. _Path = 'states/{stateKey}';
  333. _Methodid = 'appstate.states.update';
  334. Var
  335. _P : String;
  336. begin
  337. _P:=SubstitutePath(_Path,['stateKey',stateKey]);
  338. Result:=ServiceCall(_HTTPMethod,_P,AQuery,aUpdateRequest,TWriteResult) as TWriteResult;
  339. end;
  340. Function TStatesResource.Update(stateKey: integer; aUpdateRequest : TUpdateRequest; AQuery : TStatesupdateOptions) : TWriteResult;
  341. Var
  342. _Q : String;
  343. begin
  344. _Q:='';
  345. AddToQuery(_Q,'currentStateVersion',AQuery.currentStateVersion);
  346. Result:=Update(stateKey,aUpdateRequest,_Q);
  347. end;
  348. { --------------------------------------------------------------------
  349. TAppstateAPI
  350. --------------------------------------------------------------------}
  351. Class Function TAppstateAPI.APIName : String;
  352. begin
  353. Result:='appstate';
  354. end;
  355. Class Function TAppstateAPI.APIVersion : String;
  356. begin
  357. Result:='v1';
  358. end;
  359. Class Function TAppstateAPI.APIRevision : String;
  360. begin
  361. Result:='20160519';
  362. end;
  363. Class Function TAppstateAPI.APIID : String;
  364. begin
  365. Result:='appstate:v1';
  366. end;
  367. Class Function TAppstateAPI.APITitle : String;
  368. begin
  369. Result:='Google App State API';
  370. end;
  371. Class Function TAppstateAPI.APIDescription : String;
  372. begin
  373. Result:='The Google App State API.';
  374. end;
  375. Class Function TAppstateAPI.APIOwnerDomain : String;
  376. begin
  377. Result:='google.com';
  378. end;
  379. Class Function TAppstateAPI.APIOwnerName : String;
  380. begin
  381. Result:='Google';
  382. end;
  383. Class Function TAppstateAPI.APIIcon16 : String;
  384. begin
  385. Result:='http://www.google.com/images/icons/product/search-16.gif';
  386. end;
  387. Class Function TAppstateAPI.APIIcon32 : String;
  388. begin
  389. Result:='http://www.google.com/images/icons/product/search-32.gif';
  390. end;
  391. Class Function TAppstateAPI.APIdocumentationLink : String;
  392. begin
  393. Result:='https://developers.google.com/games/services/web/api/states';
  394. end;
  395. Class Function TAppstateAPI.APIrootUrl : string;
  396. begin
  397. Result:='https://www.googleapis.com/';
  398. end;
  399. Class Function TAppstateAPI.APIbasePath : string;
  400. begin
  401. Result:='/appstate/v1/';
  402. end;
  403. Class Function TAppstateAPI.APIbaseURL : String;
  404. begin
  405. Result:='https://www.googleapis.com/appstate/v1/';
  406. end;
  407. Class Function TAppstateAPI.APIProtocol : string;
  408. begin
  409. Result:='rest';
  410. end;
  411. Class Function TAppstateAPI.APIservicePath : string;
  412. begin
  413. Result:='appstate/v1/';
  414. end;
  415. Class Function TAppstateAPI.APIbatchPath : String;
  416. begin
  417. Result:='batch';
  418. end;
  419. Class Function TAppstateAPI.APIAuthScopes : TScopeInfoArray;
  420. begin
  421. SetLength(Result,1);
  422. Result[0].Name:='https://www.googleapis.com/auth/appstate';
  423. Result[0].Description:='View and manage your data for this application';
  424. end;
  425. Class Function TAppstateAPI.APINeedsAuth : Boolean;
  426. begin
  427. Result:=True;
  428. end;
  429. Class Procedure TAppstateAPI.RegisterAPIResources;
  430. begin
  431. TGetResponse.RegisterObject;
  432. TListResponse.RegisterObject;
  433. TUpdateRequest.RegisterObject;
  434. TWriteResult.RegisterObject;
  435. end;
  436. Function TAppstateAPI.GetStatesInstance : TStatesResource;
  437. begin
  438. if (FStatesInstance=Nil) then
  439. FStatesInstance:=CreateStatesResource;
  440. Result:=FStatesInstance;
  441. end;
  442. Function TAppstateAPI.CreateStatesResource : TStatesResource;
  443. begin
  444. Result:=CreateStatesResource(Self);
  445. end;
  446. Function TAppstateAPI.CreateStatesResource(AOwner : TComponent) : TStatesResource;
  447. begin
  448. Result:=TStatesResource.Create(AOwner);
  449. Result.API:=Self.API;
  450. end;
  451. initialization
  452. TAppstateAPI.RegisterAPI;
  453. end.