@@ -101,6 +101,16 @@ public String toString() {
101
101
}
102
102
103
103
// Sub accounts
104
+ /**
105
+ * Get details of a specific sub account
106
+ *
107
+ * @param subAccountId The id of the sub account
108
+ * @return the sub account details.
109
+ * @throws Exception If the request fails
110
+ */
111
+ public ApiResponse subAccount (String subAccountId ) throws Exception {
112
+ return subAccount (subAccountId , Collections .<String , Object >emptyMap ());
113
+ }
104
114
105
115
/**
106
116
* Get details of a specific sub account
@@ -110,11 +120,24 @@ public String toString() {
110
120
* @return the sub account details.
111
121
* @throws Exception If the request fails
112
122
*/
113
- public ApiResponse getSubAccount (String subAccountId , Map <String , Object > options ) throws Exception {
123
+ public ApiResponse subAccount (String subAccountId , Map <String , Object > options ) throws Exception {
114
124
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , "sub_accounts" , subAccountId );
115
125
return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
116
126
}
117
127
128
+ /**
129
+ * Get a list of sub accounts.
130
+ *
131
+ * @param enabled Optional. Whether to fetch enabled or disabled accounts. Default is all.
132
+ * @param ids Optional. List of sub-account IDs. Up to 100. When provided, other filters are ignored.
133
+ * @param prefix Optional. Search by prefix of the sub-account name. Case-insensitive.
134
+ * @return the list of sub-accounts details.
135
+ * @throws Exception If the request fails
136
+ */
137
+ public ApiResponse subAccounts (Boolean enabled , List <String > ids , String prefix ) throws Exception {
138
+ return subAccounts (enabled , ids , prefix , Collections .<String , Object >emptyMap ());
139
+ }
140
+
118
141
/**
119
142
* Get a list of sub accounts.
120
143
*
@@ -125,7 +148,7 @@ public ApiResponse getSubAccount(String subAccountId, Map<String, Object> option
125
148
* @return the list of sub-accounts details.
126
149
* @throws Exception If the request fails
127
150
*/
128
- public ApiResponse getSubAccounts (Boolean enabled , List <String > ids , String prefix , Map <String , Object > options ) throws Exception {
151
+ public ApiResponse subAccounts (Boolean enabled , List <String > ids , String prefix , Map <String , Object > options ) throws Exception {
129
152
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , "sub_accounts" );
130
153
return callAccountApi (Api .HttpMethod .GET , uri ,
131
154
ObjectUtils .asMap ("accountId" , accountId , "enabled" , enabled , "ids" , ids , "prefix" , prefix ), options );
@@ -134,7 +157,20 @@ public ApiResponse getSubAccounts(Boolean enabled, List<String> ids, String pref
134
157
/**
135
158
* @param name Required. The name displayed in the management console.
136
159
* @param cloudName Optional, unique (case insensitive)
137
- * @param customAttributes Advanced custom attributes for the sub-account.
160
+ * @param customAttributes Custom attributes associated with the sub-account, as a map of key/value pairs.
161
+ * @param enabled Optional. Whether to create the account as enabled (default is enabled).
162
+ * @param baseAccount Optional. ID of sub-account from which to copy settings
163
+ * @return details of the created sub-account
164
+ * @throws Exception If the request fails
165
+ */
166
+ public ApiResponse createSubAccount (String name , String cloudName , Map customAttributes , boolean enabled , String baseAccount ) throws Exception {
167
+ return createSubAccount (name , cloudName , customAttributes , enabled , baseAccount , Collections .<String , Object >emptyMap ());
168
+ }
169
+
170
+ /**
171
+ * @param name Required. The name displayed in the management console.
172
+ * @param cloudName Optional, unique (case insensitive)
173
+ * @param customAttributes Custom attributes associated with the sub-account, as a map of key/value pairs.
138
174
* @param enabled Optional. Whether to create the account as enabled (default is enabled).
139
175
* @param baseAccount Optional. ID of sub-account from which to copy settings
140
176
* @param options Generic advanced options map, see online documentation.
@@ -160,7 +196,20 @@ public ApiResponse createSubAccount(String name, String cloudName, Map customAtt
160
196
* @param subAccountId The id of the sub-account to update
161
197
* @param name The name displayed in the management console.
162
198
* @param cloudName The cloud name to set.
163
- * @param customAttributes Advanced custom attributes for the sub-account.
199
+ * @param customAttributes ACustom attributes associated with the sub-account, as a map of key/value pairs.
200
+ * @param enabled Set the sub-account as enabled or not.
201
+ * @return details of the updated sub-account
202
+ * @throws Exception If the request fails
203
+ */
204
+ public ApiResponse updateSubAccount (String subAccountId , String name , String cloudName , Map <String , String > customAttributes , Boolean enabled ) throws Exception {
205
+ return updateSubAccount (subAccountId , name , cloudName , customAttributes , enabled , Collections .<String , Object >emptyMap ());
206
+ }
207
+
208
+ /**
209
+ * @param subAccountId The id of the sub-account to update
210
+ * @param name The name displayed in the management console.
211
+ * @param cloudName The cloud name to set.
212
+ * @param customAttributes ACustom attributes associated with the sub-account, as a map of key/value pairs.
164
213
* @param enabled Set the sub-account as enabled or not.
165
214
* @param options Generic advanced options map, see online documentation.
166
215
* @return details of the updated sub-account
@@ -180,6 +229,17 @@ public ApiResponse updateSubAccount(String subAccountId, String name, String clo
180
229
options );
181
230
}
182
231
232
+ /**
233
+ * Deletes the sub-account.
234
+ *
235
+ * @param subAccountId The id of the sub-account to delete
236
+ * @return result message.
237
+ * @throws Exception If the request fails.
238
+ */
239
+ public ApiResponse deleteSubAccount (String subAccountId ) throws Exception {
240
+ return deleteSubAccount (subAccountId , Collections .<String , Object >emptyMap ());
241
+ }
242
+
183
243
/**
184
244
* Deletes the sub-account.
185
245
*
@@ -194,6 +254,16 @@ public ApiResponse deleteSubAccount(String subAccountId, Map<String, Object> opt
194
254
}
195
255
196
256
// Users
257
+ /**
258
+ * Get details of a specific user.
259
+ *
260
+ * @param userId The id of the user to fetch
261
+ * @return details of the user.
262
+ * @throws Exception If the request fails.
263
+ */
264
+ public ApiResponse user (String userId ) throws Exception {
265
+ return user (userId ,null );
266
+ }
197
267
198
268
/**
199
269
* Get details of a specific user.
@@ -203,11 +273,25 @@ public ApiResponse deleteSubAccount(String subAccountId, Map<String, Object> opt
203
273
* @return details of the user.
204
274
* @throws Exception If the request fails.
205
275
*/
206
- public ApiResponse getUser (String userId , Map <String , Object > options ) throws Exception {
276
+ public ApiResponse user (String userId , Map <String , Object > options ) throws Exception {
207
277
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS , userId );
208
278
return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
209
279
}
210
280
281
+ /**
282
+ * Get a list of the users according to filters.
283
+ *
284
+ * @param pending Optional. Whether to fetch pending users. Default all.
285
+ * @param userIds Optionals. List of user IDs. Up to 100
286
+ * @param prefix Optional. Search by prefix of the user's name or email. Case-insensitive
287
+ * @param subAccountId Optional. Return only users who have access to the given sub-account
288
+ * @return the users' details.
289
+ * @throws Exception If the request fails.
290
+ */
291
+ public ApiResponse users (Boolean pending , List <String > userIds , String prefix , String subAccountId ) throws Exception {
292
+ return users (pending , userIds , prefix , subAccountId ,null );
293
+ }
294
+
211
295
/**
212
296
* Get a list of the users according to filters.
213
297
*
@@ -219,7 +303,7 @@ public ApiResponse getUser(String userId, Map<String, Object> options) throws Ex
219
303
* @return the users' details.
220
304
* @throws Exception If the request fails.
221
305
*/
222
- public ApiResponse getUsers (Boolean pending , List <String > userIds , String prefix , String subAccountId , Map <String , Object > options ) throws Exception {
306
+ public ApiResponse users (Boolean pending , List <String > userIds , String prefix , String subAccountId , Map <String , Object > options ) throws Exception {
223
307
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS );
224
308
return callAccountApi (Api .HttpMethod .GET , uri ,
225
309
ObjectUtils .asMap ("accountId" , accountId ,
@@ -229,6 +313,21 @@ public ApiResponse getUsers(Boolean pending, List<String> userIds, String prefix
229
313
"sub_account_id" , subAccountId ), options );
230
314
}
231
315
316
+ /**
317
+ * Create a new user.
318
+ *
319
+ * @param name Required. Username.
320
+ * @param email Required. User's email.
321
+ * @param role Required. User's role.
322
+ * @param subAccountsIds Optional. Sub-accounts for which the user should have access.
323
+ * If not provided or empty, user should have access to all accounts.
324
+ * @return The newly created user details.
325
+ * @throws Exception If the request fails.
326
+ */
327
+ public ApiResponse createUser (String name , String email , Role role , List <String > subAccountsIds ) throws Exception {
328
+ return createUser (name , email , role , subAccountsIds );
329
+ }
330
+
232
331
/**
233
332
* Create a new user.
234
333
*
@@ -254,7 +353,23 @@ public ApiResponse createUser(String name, String email, Role role, List<String>
254
353
* @param email User's email.
255
354
* @param role User's role.
256
355
* @param subAccountsIds Sub-accounts for which the user should have access.
257
- * * If not provided or empty, user should have access to all accounts.
356
+ * If not provided or empty, user should have access to all accounts.
357
+ * @return The updated user details
358
+ * @throws Exception If the request fails.
359
+ */
360
+ public ApiResponse updateUser (String userId , String name , String email , Role role , List <String > subAccountsIds ) throws Exception {
361
+ return updateUser (userId , name , email , role , subAccountsIds ,null );
362
+ }
363
+
364
+ /**
365
+ * Update an existing user.
366
+ *
367
+ * @param userId The id of the user to update.
368
+ * @param name Username.
369
+ * @param email User's email.
370
+ * @param role User's role.
371
+ * @param subAccountsIds Sub-accounts for which the user should have access.
372
+ * If not provided or empty, user should have access to all accounts.
258
373
* @param options Generic advanced options map, see online documentation.
259
374
* @return The updated user details
260
375
* @throws Exception If the request fails.
@@ -264,6 +379,17 @@ public ApiResponse updateUser(String userId, String name, String email, Role rol
264
379
return performUserAction (Api .HttpMethod .PUT , uri , email , name , role , subAccountsIds , options );
265
380
}
266
381
382
+ /**
383
+ * Delete a user.
384
+ *
385
+ * @param userId Id of the user to delete.
386
+ * @return result message.
387
+ * @throws Exception
388
+ */
389
+ public ApiResponse deleteUser (String userId ) throws Exception {
390
+ return deleteUser (userId ,null );
391
+ }
392
+
267
393
/**
268
394
* Delete a user.
269
395
*
@@ -278,6 +404,15 @@ public ApiResponse deleteUser(String userId, Map<String, Object> options) throws
278
404
}
279
405
280
406
// Groups
407
+ /**
408
+ * Create a new user group
409
+ * @param name Required. Name for the group.
410
+ * @return The newly created group.
411
+ * @throws Exception If the request fails
412
+ */
413
+ public ApiResponse createUserGroup (String name ) throws Exception {
414
+ return createUserGroup (name ,null );
415
+ }
281
416
282
417
/**
283
418
* Create a new user group
@@ -291,6 +426,18 @@ public ApiResponse createUserGroup(String name, Map<String, Object> options) thr
291
426
return callAccountApi (Api .HttpMethod .POST , uri , ObjectUtils .asMap ("name" , name ), options );
292
427
}
293
428
429
+ /**
430
+ * Update an existing user group
431
+ *
432
+ * @param groupId The id of the group to update
433
+ * @param name The name of the group.
434
+ * @return The updated group.
435
+ * @throws Exception If the request fails
436
+ */
437
+ public ApiResponse updateUserGroup (String groupId , String name ) throws Exception {
438
+ return updateUserGroup (groupId , name ,null );
439
+ }
440
+
294
441
/**
295
442
* Update an existing user group
296
443
*
@@ -305,6 +452,17 @@ public ApiResponse updateUserGroup(String groupId, String name, Map<String, Obje
305
452
return callAccountApi (Api .HttpMethod .PUT , uri , ObjectUtils .asMap ("name" , name ), options );
306
453
}
307
454
455
+ /**
456
+ * Delete a user group
457
+ *
458
+ * @param groupId The group id to delete
459
+ * @return A result message.
460
+ * @throws Exception if the request fails.
461
+ */
462
+ public ApiResponse deleteUserGroup (String groupId ) throws Exception {
463
+ return deleteUserGroup (groupId ,null );
464
+ }
465
+
308
466
/**
309
467
* Delete a user group
310
468
*
@@ -318,6 +476,15 @@ public ApiResponse deleteUserGroup(String groupId, Map<String, Object> options)
318
476
return callAccountApi (Api .HttpMethod .DELETE , uri , Collections .<String , Object >emptyMap (), options );
319
477
}
320
478
479
+ /**
480
+ * Add an existing user to a group.
481
+ * @param groupId The group id.
482
+ * @param userId The user id to add.
483
+ * @throws Exception If the request fails
484
+ */
485
+ public ApiResponse addUserToGroup (String groupId , String userId ) throws Exception {
486
+ return addUserToGroup (groupId , userId ,null );
487
+ }
321
488
/**
322
489
* Add an existing user to a group.
323
490
* @param groupId The group id.
@@ -330,6 +497,16 @@ public ApiResponse addUserToGroup(String groupId, String userId, Map<String, Obj
330
497
return callAccountApi (Api .HttpMethod .POST , uri , Collections .<String , Object >emptyMap (), options );
331
498
}
332
499
500
+ /**
501
+ * Removes a user from a group.
502
+ * @param groupId The group id.
503
+ * @param userId The id of the user to remove
504
+ * @return A result message
505
+ * @throws Exception If the request fails.
506
+ */
507
+ public ApiResponse removeUserFromGroup (String groupId , String userId ) throws Exception {
508
+ return removeUserFromGroup (groupId , userId ,null );
509
+ }
333
510
/**
334
511
* Removes a user from a group.
335
512
* @param groupId The group id.
@@ -343,37 +520,65 @@ public ApiResponse removeUserFromGroup(String groupId, String userId, Map<String
343
520
return callAccountApi (Api .HttpMethod .DELETE , uri , Collections .<String , Object >emptyMap (), options );
344
521
}
345
522
523
+ /**
524
+ * Get details of a group.
525
+ * @param groupId The group id to fetch
526
+ * @return Details of the group.
527
+ * @throws Exception If the request fails.
528
+ */
529
+ public ApiResponse userGroup (String groupId ) throws Exception {
530
+ return userGroup (groupId ,null );
531
+ }
532
+
346
533
/**
347
534
* Get details of a group.
348
535
* @param groupId The group id to fetch
349
536
* @param options Generic advanced options map, see online documentation.
350
537
* @return Details of the group.
351
538
* @throws Exception If the request fails.
352
539
*/
353
- public ApiResponse getUserGroup (String groupId , Map <String , Object > options ) throws Exception {
540
+ public ApiResponse userGroup (String groupId , Map <String , Object > options ) throws Exception {
354
541
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS , groupId );
355
542
return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
356
543
}
357
544
545
+ /**
546
+ * Gets a list of all the user groups.
547
+ * @return The list of the groups.
548
+ * @throws Exception If the request fails.
549
+ */
550
+ public ApiResponse userGroups () throws Exception {
551
+ return userGroups (Collections .<String , Object >emptyMap ());
552
+ }
553
+
358
554
/**
359
555
* Gets a list of all the user groups.
360
556
* @param options Generic advanced options map, see online documentation.
361
557
* @return The list of the groups.
362
558
* @throws Exception If the request fails.
363
559
*/
364
- public ApiResponse listUserGroups (Map <String , Object > options ) throws Exception {
560
+ public ApiResponse userGroups (Map <String , Object > options ) throws Exception {
365
561
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS );
366
562
return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
367
563
}
368
564
565
+ /**
566
+ * Lists the users belonging to this user group.
567
+ * @param groupId The id of the user group.
568
+ * @return The list of users in that group.
569
+ * @throws Exception If the request fails.
570
+ */
571
+ public ApiResponse userGroupUsers (String groupId ) throws Exception {
572
+ return userGroupUsers (groupId ,null );
573
+ }
369
574
/**
370
575
* Lists the users belonging to this user group.
371
576
* @param groupId The id of the user group.
372
577
* @param options Generic advanced options map, see online documentation.
373
578
* @return The list of users in that group.
374
579
* @throws Exception If the request fails.
375
580
*/
376
- public ApiResponse listUserGroupUsers (String groupId , Map <String , Object > options ) throws Exception {
581
+ public ApiResponse userGroupUsers (String groupId , Map <String , Object > options ) throws Exception {
377
582
List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS , groupId , USERS );
378
583
return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
379
584
}
@@ -403,7 +608,7 @@ private ApiResponse performUserAction(Api.HttpMethod method, List<String> uri, S
403
608
}
404
609
405
610
private Map <String , Object > verifyOptions (Map <String , Object > options ) {
406
- if (options == null ) {
611
+ if (options == null || options == Collections . EMPTY_MAP ) {
407
612
return new HashMap <String , Object >(2 ); // Two, since api key and secret will be populated later
408
613
}
409
614
0 commit comments