googleappstate.pp 16 KB

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