googlelicensing.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. unit googlelicensing;
  2. {$MODE objfpc}
  3. {$H+}
  4. interface
  5. uses sysutils, classes, googleservice, restbase, googlebase;
  6. type
  7. //Top-level schema types
  8. TLicenseAssignment = Class;
  9. TLicenseAssignmentInsert = Class;
  10. TLicenseAssignmentList = Class;
  11. TLicenseAssignmentArray = Array of TLicenseAssignment;
  12. TLicenseAssignmentInsertArray = Array of TLicenseAssignmentInsert;
  13. TLicenseAssignmentListArray = Array of TLicenseAssignmentList;
  14. //Anonymous types, using auto-generated names
  15. TLicenseAssignmentListTypeitemsArray = Array of TLicenseAssignment;
  16. { --------------------------------------------------------------------
  17. TLicenseAssignment
  18. --------------------------------------------------------------------}
  19. TLicenseAssignment = Class(TGoogleBaseObject)
  20. Private
  21. Fetags : String;
  22. Fkind : String;
  23. FproductId : String;
  24. FselfLink : String;
  25. FskuId : String;
  26. FuserId : String;
  27. Protected
  28. //Property setters
  29. Procedure Setetags(AIndex : Integer; const AValue : String); virtual;
  30. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  31. Procedure SetproductId(AIndex : Integer; const AValue : String); virtual;
  32. Procedure SetselfLink(AIndex : Integer; const AValue : String); virtual;
  33. Procedure SetskuId(AIndex : Integer; const AValue : String); virtual;
  34. Procedure SetuserId(AIndex : Integer; const AValue : String); virtual;
  35. Public
  36. Published
  37. Property etags : String Index 0 Read Fetags Write Setetags;
  38. Property kind : String Index 8 Read Fkind Write Setkind;
  39. Property productId : String Index 16 Read FproductId Write SetproductId;
  40. Property selfLink : String Index 24 Read FselfLink Write SetselfLink;
  41. Property skuId : String Index 32 Read FskuId Write SetskuId;
  42. Property userId : String Index 40 Read FuserId Write SetuserId;
  43. end;
  44. TLicenseAssignmentClass = Class of TLicenseAssignment;
  45. { --------------------------------------------------------------------
  46. TLicenseAssignmentInsert
  47. --------------------------------------------------------------------}
  48. TLicenseAssignmentInsert = Class(TGoogleBaseObject)
  49. Private
  50. FuserId : String;
  51. Protected
  52. //Property setters
  53. Procedure SetuserId(AIndex : Integer; const AValue : String); virtual;
  54. Public
  55. Published
  56. Property userId : String Index 0 Read FuserId Write SetuserId;
  57. end;
  58. TLicenseAssignmentInsertClass = Class of TLicenseAssignmentInsert;
  59. { --------------------------------------------------------------------
  60. TLicenseAssignmentList
  61. --------------------------------------------------------------------}
  62. TLicenseAssignmentList = Class(TGoogleBaseObject)
  63. Private
  64. Fetag : String;
  65. Fitems : TLicenseAssignmentListTypeitemsArray;
  66. Fkind : String;
  67. FnextPageToken : String;
  68. Protected
  69. //Property setters
  70. Procedure Setetag(AIndex : Integer; const AValue : String); virtual;
  71. Procedure Setitems(AIndex : Integer; const AValue : TLicenseAssignmentListTypeitemsArray); virtual;
  72. Procedure Setkind(AIndex : Integer; const AValue : String); virtual;
  73. Procedure SetnextPageToken(AIndex : Integer; const AValue : String); virtual;
  74. //2.6.4. bug workaround
  75. {$IFDEF VER2_6}
  76. Procedure SetArrayLength(Const AName : String; ALength : Longint); override;
  77. {$ENDIF VER2_6}
  78. Public
  79. Published
  80. Property etag : String Index 0 Read Fetag Write Setetag;
  81. Property items : TLicenseAssignmentListTypeitemsArray Index 8 Read Fitems Write Setitems;
  82. Property kind : String Index 16 Read Fkind Write Setkind;
  83. Property nextPageToken : String Index 24 Read FnextPageToken Write SetnextPageToken;
  84. end;
  85. TLicenseAssignmentListClass = Class of TLicenseAssignmentList;
  86. { --------------------------------------------------------------------
  87. TLicenseAssignmentsResource
  88. --------------------------------------------------------------------}
  89. //Optional query Options for TLicenseAssignmentsResource, method ListForProduct
  90. TLicenseAssignmentsListForProductOptions = Record
  91. customerId : String;
  92. maxResults : integer;
  93. pageToken : String;
  94. end;
  95. //Optional query Options for TLicenseAssignmentsResource, method ListForProductAndSku
  96. TLicenseAssignmentsListForProductAndSkuOptions = Record
  97. customerId : String;
  98. maxResults : integer;
  99. pageToken : String;
  100. end;
  101. TLicenseAssignmentsResource = Class(TGoogleResource)
  102. Public
  103. Class Function ResourceName : String; override;
  104. Class Function DefaultAPI : TGoogleAPIClass; override;
  105. Procedure Delete(productId: string; skuId: string; userId: string);
  106. Function Get(productId: string; skuId: string; userId: string) : TLicenseAssignment;
  107. Function Insert(productId: string; skuId: string; aLicenseAssignmentInsert : TLicenseAssignmentInsert) : TLicenseAssignment;
  108. Function ListForProduct(productId: string; AQuery : string = '') : TLicenseAssignmentList;
  109. Function ListForProduct(productId: string; AQuery : TLicenseAssignmentslistForProductOptions) : TLicenseAssignmentList;
  110. Function ListForProductAndSku(productId: string; skuId: string; AQuery : string = '') : TLicenseAssignmentList;
  111. Function ListForProductAndSku(productId: string; skuId: string; AQuery : TLicenseAssignmentslistForProductAndSkuOptions) : TLicenseAssignmentList;
  112. Function Patch(productId: string; skuId: string; userId: string; aLicenseAssignment : TLicenseAssignment) : TLicenseAssignment;
  113. Function Update(productId: string; skuId: string; userId: string; aLicenseAssignment : TLicenseAssignment) : TLicenseAssignment;
  114. end;
  115. { --------------------------------------------------------------------
  116. TLicensingAPI
  117. --------------------------------------------------------------------}
  118. TLicensingAPI = Class(TGoogleAPI)
  119. Private
  120. FLicenseAssignmentsInstance : TLicenseAssignmentsResource;
  121. Function GetLicenseAssignmentsInstance : TLicenseAssignmentsResource;virtual;
  122. Public
  123. //Override class functions with API info
  124. Class Function APIName : String; override;
  125. Class Function APIVersion : String; override;
  126. Class Function APIRevision : String; override;
  127. Class Function APIID : String; override;
  128. Class Function APITitle : String; override;
  129. Class Function APIDescription : String; override;
  130. Class Function APIOwnerDomain : String; override;
  131. Class Function APIOwnerName : String; override;
  132. Class Function APIIcon16 : String; override;
  133. Class Function APIIcon32 : String; override;
  134. Class Function APIdocumentationLink : String; override;
  135. Class Function APIrootUrl : string; override;
  136. Class Function APIbasePath : string;override;
  137. Class Function APIbaseURL : String;override;
  138. Class Function APIProtocol : string;override;
  139. Class Function APIservicePath : string;override;
  140. Class Function APIbatchPath : String;override;
  141. Class Function APIAuthScopes : TScopeInfoArray;override;
  142. Class Function APINeedsAuth : Boolean;override;
  143. Class Procedure RegisterAPIResources; override;
  144. //Add create function for resources
  145. Function CreateLicenseAssignmentsResource(AOwner : TComponent) : TLicenseAssignmentsResource;virtual;overload;
  146. Function CreateLicenseAssignmentsResource : TLicenseAssignmentsResource;virtual;overload;
  147. //Add default on-demand instances for resources
  148. Property LicenseAssignmentsResource : TLicenseAssignmentsResource Read GetLicenseAssignmentsInstance;
  149. end;
  150. implementation
  151. { --------------------------------------------------------------------
  152. TLicenseAssignment
  153. --------------------------------------------------------------------}
  154. Procedure TLicenseAssignment.Setetags(AIndex : Integer; const AValue : String);
  155. begin
  156. If (Fetags=AValue) then exit;
  157. Fetags:=AValue;
  158. MarkPropertyChanged(AIndex);
  159. end;
  160. Procedure TLicenseAssignment.Setkind(AIndex : Integer; const AValue : String);
  161. begin
  162. If (Fkind=AValue) then exit;
  163. Fkind:=AValue;
  164. MarkPropertyChanged(AIndex);
  165. end;
  166. Procedure TLicenseAssignment.SetproductId(AIndex : Integer; const AValue : String);
  167. begin
  168. If (FproductId=AValue) then exit;
  169. FproductId:=AValue;
  170. MarkPropertyChanged(AIndex);
  171. end;
  172. Procedure TLicenseAssignment.SetselfLink(AIndex : Integer; const AValue : String);
  173. begin
  174. If (FselfLink=AValue) then exit;
  175. FselfLink:=AValue;
  176. MarkPropertyChanged(AIndex);
  177. end;
  178. Procedure TLicenseAssignment.SetskuId(AIndex : Integer; const AValue : String);
  179. begin
  180. If (FskuId=AValue) then exit;
  181. FskuId:=AValue;
  182. MarkPropertyChanged(AIndex);
  183. end;
  184. Procedure TLicenseAssignment.SetuserId(AIndex : Integer; const AValue : String);
  185. begin
  186. If (FuserId=AValue) then exit;
  187. FuserId:=AValue;
  188. MarkPropertyChanged(AIndex);
  189. end;
  190. { --------------------------------------------------------------------
  191. TLicenseAssignmentInsert
  192. --------------------------------------------------------------------}
  193. Procedure TLicenseAssignmentInsert.SetuserId(AIndex : Integer; const AValue : String);
  194. begin
  195. If (FuserId=AValue) then exit;
  196. FuserId:=AValue;
  197. MarkPropertyChanged(AIndex);
  198. end;
  199. { --------------------------------------------------------------------
  200. TLicenseAssignmentList
  201. --------------------------------------------------------------------}
  202. Procedure TLicenseAssignmentList.Setetag(AIndex : Integer; const AValue : String);
  203. begin
  204. If (Fetag=AValue) then exit;
  205. Fetag:=AValue;
  206. MarkPropertyChanged(AIndex);
  207. end;
  208. Procedure TLicenseAssignmentList.Setitems(AIndex : Integer; const AValue : TLicenseAssignmentListTypeitemsArray);
  209. begin
  210. If (Fitems=AValue) then exit;
  211. Fitems:=AValue;
  212. MarkPropertyChanged(AIndex);
  213. end;
  214. Procedure TLicenseAssignmentList.Setkind(AIndex : Integer; const AValue : String);
  215. begin
  216. If (Fkind=AValue) then exit;
  217. Fkind:=AValue;
  218. MarkPropertyChanged(AIndex);
  219. end;
  220. Procedure TLicenseAssignmentList.SetnextPageToken(AIndex : Integer; const AValue : String);
  221. begin
  222. If (FnextPageToken=AValue) then exit;
  223. FnextPageToken:=AValue;
  224. MarkPropertyChanged(AIndex);
  225. end;
  226. //2.6.4. bug workaround
  227. {$IFDEF VER2_6}
  228. Procedure TLicenseAssignmentList.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. TLicenseAssignmentsResource
  239. --------------------------------------------------------------------}
  240. Class Function TLicenseAssignmentsResource.ResourceName : String;
  241. begin
  242. Result:='licenseAssignments';
  243. end;
  244. Class Function TLicenseAssignmentsResource.DefaultAPI : TGoogleAPIClass;
  245. begin
  246. Result:=TlicensingAPI;
  247. end;
  248. Procedure TLicenseAssignmentsResource.Delete(productId: string; skuId: string; userId: string);
  249. Const
  250. _HTTPMethod = 'DELETE';
  251. _Path = '{productId}/sku/{skuId}/user/{userId}';
  252. _Methodid = 'licensing.licenseAssignments.delete';
  253. Var
  254. _P : String;
  255. begin
  256. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId,'userId',userId]);
  257. ServiceCall(_HTTPMethod,_P,'',Nil,Nil);
  258. end;
  259. Function TLicenseAssignmentsResource.Get(productId: string; skuId: string; userId: string) : TLicenseAssignment;
  260. Const
  261. _HTTPMethod = 'GET';
  262. _Path = '{productId}/sku/{skuId}/user/{userId}';
  263. _Methodid = 'licensing.licenseAssignments.get';
  264. Var
  265. _P : String;
  266. begin
  267. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId,'userId',userId]);
  268. Result:=ServiceCall(_HTTPMethod,_P,'',Nil,TLicenseAssignment) as TLicenseAssignment;
  269. end;
  270. Function TLicenseAssignmentsResource.Insert(productId: string; skuId: string; aLicenseAssignmentInsert : TLicenseAssignmentInsert) : TLicenseAssignment;
  271. Const
  272. _HTTPMethod = 'POST';
  273. _Path = '{productId}/sku/{skuId}/user';
  274. _Methodid = 'licensing.licenseAssignments.insert';
  275. Var
  276. _P : String;
  277. begin
  278. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId]);
  279. Result:=ServiceCall(_HTTPMethod,_P,'',aLicenseAssignmentInsert,TLicenseAssignment) as TLicenseAssignment;
  280. end;
  281. Function TLicenseAssignmentsResource.ListForProduct(productId: string; AQuery : string = '') : TLicenseAssignmentList;
  282. Const
  283. _HTTPMethod = 'GET';
  284. _Path = '{productId}/users';
  285. _Methodid = 'licensing.licenseAssignments.listForProduct';
  286. Var
  287. _P : String;
  288. begin
  289. _P:=SubstitutePath(_Path,['productId',productId]);
  290. Result:=ServiceCall(_HTTPMethod,_P,AQuery,Nil,TLicenseAssignmentList) as TLicenseAssignmentList;
  291. end;
  292. Function TLicenseAssignmentsResource.ListForProduct(productId: string; AQuery : TLicenseAssignmentslistForProductOptions) : TLicenseAssignmentList;
  293. Var
  294. _Q : String;
  295. begin
  296. _Q:='';
  297. AddToQuery(_Q,'customerId',AQuery.customerId);
  298. AddToQuery(_Q,'maxResults',AQuery.maxResults);
  299. AddToQuery(_Q,'pageToken',AQuery.pageToken);
  300. Result:=ListForProduct(productId,_Q);
  301. end;
  302. Function TLicenseAssignmentsResource.ListForProductAndSku(productId: string; skuId: string; AQuery : string = '') : TLicenseAssignmentList;
  303. Const
  304. _HTTPMethod = 'GET';
  305. _Path = '{productId}/sku/{skuId}/users';
  306. _Methodid = 'licensing.licenseAssignments.listForProductAndSku';
  307. Var
  308. _P : String;
  309. begin
  310. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId]);
  311. Result:=ServiceCall(_HTTPMethod,_P,AQuery,Nil,TLicenseAssignmentList) as TLicenseAssignmentList;
  312. end;
  313. Function TLicenseAssignmentsResource.ListForProductAndSku(productId: string; skuId: string; AQuery : TLicenseAssignmentslistForProductAndSkuOptions) : TLicenseAssignmentList;
  314. Var
  315. _Q : String;
  316. begin
  317. _Q:='';
  318. AddToQuery(_Q,'customerId',AQuery.customerId);
  319. AddToQuery(_Q,'maxResults',AQuery.maxResults);
  320. AddToQuery(_Q,'pageToken',AQuery.pageToken);
  321. Result:=ListForProductAndSku(productId,skuId,_Q);
  322. end;
  323. Function TLicenseAssignmentsResource.Patch(productId: string; skuId: string; userId: string; aLicenseAssignment : TLicenseAssignment) : TLicenseAssignment;
  324. Const
  325. _HTTPMethod = 'PATCH';
  326. _Path = '{productId}/sku/{skuId}/user/{userId}';
  327. _Methodid = 'licensing.licenseAssignments.patch';
  328. Var
  329. _P : String;
  330. begin
  331. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId,'userId',userId]);
  332. Result:=ServiceCall(_HTTPMethod,_P,'',aLicenseAssignment,TLicenseAssignment) as TLicenseAssignment;
  333. end;
  334. Function TLicenseAssignmentsResource.Update(productId: string; skuId: string; userId: string; aLicenseAssignment : TLicenseAssignment) : TLicenseAssignment;
  335. Const
  336. _HTTPMethod = 'PUT';
  337. _Path = '{productId}/sku/{skuId}/user/{userId}';
  338. _Methodid = 'licensing.licenseAssignments.update';
  339. Var
  340. _P : String;
  341. begin
  342. _P:=SubstitutePath(_Path,['productId',productId,'skuId',skuId,'userId',userId]);
  343. Result:=ServiceCall(_HTTPMethod,_P,'',aLicenseAssignment,TLicenseAssignment) as TLicenseAssignment;
  344. end;
  345. { --------------------------------------------------------------------
  346. TLicensingAPI
  347. --------------------------------------------------------------------}
  348. Class Function TLicensingAPI.APIName : String;
  349. begin
  350. Result:='licensing';
  351. end;
  352. Class Function TLicensingAPI.APIVersion : String;
  353. begin
  354. Result:='v1';
  355. end;
  356. Class Function TLicensingAPI.APIRevision : String;
  357. begin
  358. Result:='20150901';
  359. end;
  360. Class Function TLicensingAPI.APIID : String;
  361. begin
  362. Result:='licensing:v1';
  363. end;
  364. Class Function TLicensingAPI.APITitle : String;
  365. begin
  366. Result:='Enterprise License Manager API';
  367. end;
  368. Class Function TLicensingAPI.APIDescription : String;
  369. begin
  370. Result:='Licensing API to view and manage license for your domain.';
  371. end;
  372. Class Function TLicensingAPI.APIOwnerDomain : String;
  373. begin
  374. Result:='google.com';
  375. end;
  376. Class Function TLicensingAPI.APIOwnerName : String;
  377. begin
  378. Result:='Google';
  379. end;
  380. Class Function TLicensingAPI.APIIcon16 : String;
  381. begin
  382. Result:='http://www.google.com/images/icons/product/search-16.gif';
  383. end;
  384. Class Function TLicensingAPI.APIIcon32 : String;
  385. begin
  386. Result:='http://www.google.com/images/icons/product/search-32.gif';
  387. end;
  388. Class Function TLicensingAPI.APIdocumentationLink : String;
  389. begin
  390. Result:='https://developers.google.com/google-apps/licensing/';
  391. end;
  392. Class Function TLicensingAPI.APIrootUrl : string;
  393. begin
  394. Result:='https://www.googleapis.com/';
  395. end;
  396. Class Function TLicensingAPI.APIbasePath : string;
  397. begin
  398. Result:='/apps/licensing/v1/product/';
  399. end;
  400. Class Function TLicensingAPI.APIbaseURL : String;
  401. begin
  402. Result:='https://www.googleapis.com/apps/licensing/v1/product/';
  403. end;
  404. Class Function TLicensingAPI.APIProtocol : string;
  405. begin
  406. Result:='rest';
  407. end;
  408. Class Function TLicensingAPI.APIservicePath : string;
  409. begin
  410. Result:='apps/licensing/v1/product/';
  411. end;
  412. Class Function TLicensingAPI.APIbatchPath : String;
  413. begin
  414. Result:='batch';
  415. end;
  416. Class Function TLicensingAPI.APIAuthScopes : TScopeInfoArray;
  417. begin
  418. SetLength(Result,1);
  419. Result[0].Name:='https://www.googleapis.com/auth/apps.licensing';
  420. Result[0].Description:='View and manage Google Apps licenses for your domain';
  421. end;
  422. Class Function TLicensingAPI.APINeedsAuth : Boolean;
  423. begin
  424. Result:=True;
  425. end;
  426. Class Procedure TLicensingAPI.RegisterAPIResources;
  427. begin
  428. TLicenseAssignment.RegisterObject;
  429. TLicenseAssignmentInsert.RegisterObject;
  430. TLicenseAssignmentList.RegisterObject;
  431. end;
  432. Function TLicensingAPI.GetLicenseAssignmentsInstance : TLicenseAssignmentsResource;
  433. begin
  434. if (FLicenseAssignmentsInstance=Nil) then
  435. FLicenseAssignmentsInstance:=CreateLicenseAssignmentsResource;
  436. Result:=FLicenseAssignmentsInstance;
  437. end;
  438. Function TLicensingAPI.CreateLicenseAssignmentsResource : TLicenseAssignmentsResource;
  439. begin
  440. Result:=CreateLicenseAssignmentsResource(Self);
  441. end;
  442. Function TLicensingAPI.CreateLicenseAssignmentsResource(AOwner : TComponent) : TLicenseAssignmentsResource;
  443. begin
  444. Result:=TLicenseAssignmentsResource.Create(AOwner);
  445. Result.API:=Self.API;
  446. end;
  447. initialization
  448. TLicensingAPI.RegisterAPI;
  449. end.