summaryrefslogtreecommitdiff
path: root/packages/googleapi/src/googleappstate.pp
blob: 5265f8e56ff6317a6d4bc43af4a57cb47d49042a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
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.