Search in sources :

Example 1 with AccountManagement

use of com.arm.mbed.cloud.sdk.AccountManagement in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagementExamples method listGroups.

/**
 * Lists the last 5 groups and their contents.
 */
@SuppressWarnings("boxing")
@Example
public void listGroups() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        // Defining query options
        GroupListOptions options = new GroupListOptions();
        options.setLimit(5);
        options.setOrder(Order.DESC);
        // Listing groups.
        ListResponse<Group> groups = api.listGroups(options);
        for (Group group : groups.getData()) {
            log("Group", group);
            Paginator<ApiKey> apiKeyIterator = api.listAllGroupApiKeys(group.getId(), null);
            while (apiKeyIterator.hasNext()) {
                log("API key of group [" + group.getId() + "]", apiKeyIterator.next());
            }
            Paginator<User> userIterator = api.listAllGroupUsers(group.getId(), null);
            while (userIterator.hasNext()) {
                log("User of group [" + group.getId() + "]", userIterator.next());
            }
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : Group(com.arm.mbed.cloud.sdk.accountmanagement.model.Group) ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) GroupListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 2 with AccountManagement

use of com.arm.mbed.cloud.sdk.AccountManagement in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagementExamples method getAccount.

/**
 * Gets details of the account associated with this API key.
 */
@Example
public void getAccount() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        Account thisAccount;
        thisAccount = api.getAccount();
        log("This account", thisAccount);
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : Account(com.arm.mbed.cloud.sdk.accountmanagement.model.Account) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 3 with AccountManagement

use of com.arm.mbed.cloud.sdk.AccountManagement in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagementExamples method listApiKeys.

/**
 * Lists the first 5 API Keys.
 */
@SuppressWarnings("boxing")
@Example
public void listApiKeys() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        // Defining query options
        ApiKeyListOptions options = new ApiKeyListOptions();
        options.setLimit(5);
        // Listing API keys.
        Paginator<ApiKey> apikeys = api.listAllApiKeys(options);
        for (ApiKey apiKey : apikeys) {
            log("API key", apiKey);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) ApiKeyListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 4 with AccountManagement

use of com.arm.mbed.cloud.sdk.AccountManagement in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagementExamples method listUsers.

/**
 * Lists the first 5 active users.
 */
@SuppressWarnings("boxing")
@Example
public void listUsers() {
    ConnectionOptions config = Configuration.get();
    AccountManagement api = new AccountManagement(config);
    try {
        // Defining query options
        UserListOptions options = new UserListOptions();
        options.setLimit(5);
        // Listing users.
        Paginator<User> users = api.listAllUsers(options);
        for (User user : users) {
            log("User", user);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Aggregations

AccountManagement (com.arm.mbed.cloud.sdk.AccountManagement)4 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)4 AbstractExample (utils.AbstractExample)4 Example (utils.Example)4 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)2 Account (com.arm.mbed.cloud.sdk.accountmanagement.model.Account)1 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)1 Group (com.arm.mbed.cloud.sdk.accountmanagement.model.Group)1 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)1 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)1