@@ -101,6 +101,16 @@ public String toString() {
101101 }
102102
103103 // 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+ }
104114
105115 /**
106116 * Get details of a specific sub account
@@ -110,11 +120,24 @@ public String toString() {
110120 * @return the sub account details.
111121 * @throws Exception If the request fails
112122 */
113- public ApiResponse getSubAccount (String subAccountId , Map <String , Object > options ) throws Exception {
123+ public ApiResponse subAccount (String subAccountId , Map <String , Object > options ) throws Exception {
114124 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , "sub_accounts" , subAccountId );
115125 return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
116126 }
117127
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+
118141 /**
119142 * Get a list of sub accounts.
120143 *
@@ -125,7 +148,7 @@ public ApiResponse getSubAccount(String subAccountId, Map<String, Object> option
125148 * @return the list of sub-accounts details.
126149 * @throws Exception If the request fails
127150 */
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 {
129152 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , "sub_accounts" );
130153 return callAccountApi (Api .HttpMethod .GET , uri ,
131154 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
134157 /**
135158 * @param name Required. The name displayed in the management console.
136159 * @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.
138174 * @param enabled Optional. Whether to create the account as enabled (default is enabled).
139175 * @param baseAccount Optional. ID of sub-account from which to copy settings
140176 * @param options Generic advanced options map, see online documentation.
@@ -160,7 +196,20 @@ public ApiResponse createSubAccount(String name, String cloudName, Map customAtt
160196 * @param subAccountId The id of the sub-account to update
161197 * @param name The name displayed in the management console.
162198 * @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.
164213 * @param enabled Set the sub-account as enabled or not.
165214 * @param options Generic advanced options map, see online documentation.
166215 * @return details of the updated sub-account
@@ -180,6 +229,17 @@ public ApiResponse updateSubAccount(String subAccountId, String name, String clo
180229 options );
181230 }
182231
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+
183243 /**
184244 * Deletes the sub-account.
185245 *
@@ -194,6 +254,16 @@ public ApiResponse deleteSubAccount(String subAccountId, Map<String, Object> opt
194254 }
195255
196256 // 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+ }
197267
198268 /**
199269 * Get details of a specific user.
@@ -203,11 +273,25 @@ public ApiResponse deleteSubAccount(String subAccountId, Map<String, Object> opt
203273 * @return details of the user.
204274 * @throws Exception If the request fails.
205275 */
206- public ApiResponse getUser (String userId , Map <String , Object > options ) throws Exception {
276+ public ApiResponse user (String userId , Map <String , Object > options ) throws Exception {
207277 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS , userId );
208278 return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
209279 }
210280
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+
211295 /**
212296 * Get a list of the users according to filters.
213297 *
@@ -219,7 +303,7 @@ public ApiResponse getUser(String userId, Map<String, Object> options) throws Ex
219303 * @return the users' details.
220304 * @throws Exception If the request fails.
221305 */
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 {
223307 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USERS );
224308 return callAccountApi (Api .HttpMethod .GET , uri ,
225309 ObjectUtils .asMap ("accountId" , accountId ,
@@ -229,6 +313,21 @@ public ApiResponse getUsers(Boolean pending, List<String> userIds, String prefix
229313 "sub_account_id" , subAccountId ), options );
230314 }
231315
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+
232331 /**
233332 * Create a new user.
234333 *
@@ -254,7 +353,23 @@ public ApiResponse createUser(String name, String email, Role role, List<String>
254353 * @param email User's email.
255354 * @param role User's role.
256355 * @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.
258373 * @param options Generic advanced options map, see online documentation.
259374 * @return The updated user details
260375 * @throws Exception If the request fails.
@@ -264,6 +379,17 @@ public ApiResponse updateUser(String userId, String name, String email, Role rol
264379 return performUserAction (Api .HttpMethod .PUT , uri , email , name , role , subAccountsIds , options );
265380 }
266381
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+
267393 /**
268394 * Delete a user.
269395 *
@@ -278,6 +404,15 @@ public ApiResponse deleteUser(String userId, Map<String, Object> options) throws
278404 }
279405
280406 // 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+ }
281416
282417 /**
283418 * Create a new user group
@@ -291,6 +426,18 @@ public ApiResponse createUserGroup(String name, Map<String, Object> options) thr
291426 return callAccountApi (Api .HttpMethod .POST , uri , ObjectUtils .asMap ("name" , name ), options );
292427 }
293428
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+
294441 /**
295442 * Update an existing user group
296443 *
@@ -305,6 +452,17 @@ public ApiResponse updateUserGroup(String groupId, String name, Map<String, Obje
305452 return callAccountApi (Api .HttpMethod .PUT , uri , ObjectUtils .asMap ("name" , name ), options );
306453 }
307454
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+
308466 /**
309467 * Delete a user group
310468 *
@@ -318,6 +476,15 @@ public ApiResponse deleteUserGroup(String groupId, Map<String, Object> options)
318476 return callAccountApi (Api .HttpMethod .DELETE , uri , Collections .<String , Object >emptyMap (), options );
319477 }
320478
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+ }
321488 /**
322489 * Add an existing user to a group.
323490 * @param groupId The group id.
@@ -330,6 +497,16 @@ public ApiResponse addUserToGroup(String groupId, String userId, Map<String, Obj
330497 return callAccountApi (Api .HttpMethod .POST , uri , Collections .<String , Object >emptyMap (), options );
331498 }
332499
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+ }
333510 /**
334511 * Removes a user from a group.
335512 * @param groupId The group id.
@@ -343,37 +520,65 @@ public ApiResponse removeUserFromGroup(String groupId, String userId, Map<String
343520 return callAccountApi (Api .HttpMethod .DELETE , uri , Collections .<String , Object >emptyMap (), options );
344521 }
345522
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+
346533 /**
347534 * Get details of a group.
348535 * @param groupId The group id to fetch
349536 * @param options Generic advanced options map, see online documentation.
350537 * @return Details of the group.
351538 * @throws Exception If the request fails.
352539 */
353- public ApiResponse getUserGroup (String groupId , Map <String , Object > options ) throws Exception {
540+ public ApiResponse userGroup (String groupId , Map <String , Object > options ) throws Exception {
354541 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS , groupId );
355542 return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
356543 }
357544
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+
358554 /**
359555 * Gets a list of all the user groups.
360556 * @param options Generic advanced options map, see online documentation.
361557 * @return The list of the groups.
362558 * @throws Exception If the request fails.
363559 */
364- public ApiResponse listUserGroups (Map <String , Object > options ) throws Exception {
560+ public ApiResponse userGroups (Map <String , Object > options ) throws Exception {
365561 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS );
366562 return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
367563 }
368564
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+ }
369574 /**
370575 * Lists the users belonging to this user group.
371576 * @param groupId The id of the user group.
372577 * @param options Generic advanced options map, see online documentation.
373578 * @return The list of users in that group.
374579 * @throws Exception If the request fails.
375580 */
376- public ApiResponse listUserGroupUsers (String groupId , Map <String , Object > options ) throws Exception {
581+ public ApiResponse userGroupUsers (String groupId , Map <String , Object > options ) throws Exception {
377582 List <String > uri = Arrays .asList (PROVISIONING , ACCOUNTS , accountId , USER_GROUPS , groupId , USERS );
378583 return callAccountApi (Api .HttpMethod .GET , uri , Collections .<String , Object >emptyMap (), options );
379584 }
@@ -403,7 +608,7 @@ private ApiResponse performUserAction(Api.HttpMethod method, List<String> uri, S
403608 }
404609
405610 private Map <String , Object > verifyOptions (Map <String , Object > options ) {
406- if (options == null ) {
611+ if (options == null || options == Collections . EMPTY_MAP ) {
407612 return new HashMap <String , Object >(2 ); // Two, since api key and secret will be populated later
408613 }
409614
0 commit comments