Search in sources :

Example 16 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method deleteResourceSubscription.

/**
 * Deletes a resource's subscription.
 * <p>
 * Note: this method will deregister all subscription callbacks or observers for this resource if any.
 * <p>
 *
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     String resourcePath = "/3200/0/5501";
 *     Resource buttonResource = new Resource(deviceId, resourcePath);
 *
 *     connectApi.deleteResourceSubscription(buttonResource);
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param resource
 *            resource to subscribe to.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
public void deleteResourceSubscription(@NonNull Resource resource) throws MbedCloudException {
    checkNotNull(resource, TAG_RESOURCE);
    checkModelValidity(resource, TAG_RESOURCE);
    final Resource finalResource = resource;
    CloudCaller.call(this, "deleteResourceSubscription()", null, new CloudCall<Void>() {

        @Override
        public Call<Void> call() {
            return endpoint.getSubscriptions().v2SubscriptionsDeviceIdResourcePathDelete(finalResource.getDeviceId(), ApiUtils.normalisePath(finalResource.getPath()));
        }
    });
    deregisterResourceSubscriptionCallback(finalResource);
    removeResourceSubscriptionObserver(finalResource);
}
Also used : Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Resource(com.arm.mbed.cloud.sdk.connect.model.Resource) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 17 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method addUser.

/**
 * Adds a user.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     User user = new User();
 *     user.setEmail("javaSDK@arm.com");
 *     user.setUsername("javaSDK");
 *     user.setFullName("Java SDK");
 *
 *     User newUser = accountManagementApi.addUser(user);
 *     System.out.println("User ID: " + newUser.getId());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param user
 *            User to add.
 * @return added user.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@NonNull
public User addUser(@NonNull User user) throws MbedCloudException {
    checkNotNull(user, TAG_USER);
    checkModelValidity(user, TAG_USER);
    final User finalUser = user;
    return CloudCaller.call(this, "addUser()", UserAdapter.getMapper(), new CloudCall<UserInfoResp>() {

        @Override
        public Call<UserInfoResp> call() {
            return endpoint.getAdmin().createUser(UserAdapter.reverseMapAdd(finalUser), "create");
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoResp) NonNull(com.arm.mbed.cloud.sdk.annotations.NonNull) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 18 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method listGroupApiKeys.

/**
 * Lists API keys of a group.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String groupId = "015f4ac587f500000000000100109294";
 *     ListOptions options = new ListOptions();
 *     options.setLimit(10);
 *
 *     ListResponse<ApiKey> apiKeys = accountManagementApi.listGroupApiKeys(groupId, options);
 *     for (ApiKey apiKey : apiKeys) {
 *         System.out.println("ApiKey: " + apiKey.getKey());
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param groupId
 *            The group ID of the group.
 * @param options
 *            filter options.
 * @return The list of API keys corresponding to groupId and filter options (One page).
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ListResponse<ApiKey> listGroupApiKeys(@NonNull String groupId, @Nullable ListOptions options) throws MbedCloudException {
    checkNotNull(groupId, TAG_GROUP_ID);
    final ListOptions finalOptions = (options == null) ? new ListOptions() : options;
    final String finalGroupId = groupId;
    return CloudCaller.call(this, "listGroupApiKeys()", ApiKeyAdapter.getListMapper(), new CloudCall<ApiKeyInfoRespList>() {

        @Override
        public Call<ApiKeyInfoRespList> call() {
            return endpoint.getDeveloper().getApiKeysOfGroup(finalGroupId, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString(), finalOptions.encodeInclude());
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) ApiKeyInfoRespList(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoRespList) GroupListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions) ListOptions(com.arm.mbed.cloud.sdk.common.listing.ListOptions) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ApiKeyListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 19 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method listGroupUsers.

/**
 * Lists users of a group.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String groupId = "015f4ac587f500000000000100109294";
 *     ListOptions options = new ListOptions();
 *     options.setLimit(10);
 *
 *     ListResponse<User> users = accountManagementApi.listGroupUsers(groupId, options);
 *     for (User user : users) {
 *         System.out.println("User ID: " + user.getId());
 *         System.out.println("User name: " + user.getFullName());
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param groupId
 *            The group ID.
 * @param options
 *            filter options.
 * @return The list of users corresponding to groupId and filter options (One page).
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public ListResponse<User> listGroupUsers(@NonNull String groupId, @Nullable ListOptions options) throws MbedCloudException {
    checkNotNull(groupId, TAG_GROUP_ID);
    final ListOptions finalOptions = (options == null) ? new ListOptions() : options;
    final String finalGroupId = groupId;
    return CloudCaller.call(this, "listGroupUsers()", UserAdapter.getListMapper(), new CloudCall<UserInfoRespList>() {

        @Override
        public Call<UserInfoRespList> call() {
            return endpoint.getAdmin().getUsersOfGroup(finalGroupId, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString(), finalOptions.encodeInclude());
        }
    });
}
Also used : UserInfoRespList(com.arm.mbed.cloud.sdk.internal.iam.model.UserInfoRespList) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) GroupListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions) ListOptions(com.arm.mbed.cloud.sdk.common.listing.ListOptions) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ApiKeyListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 20 with CloudCall

use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.

the class AccountManagement method updateAccount.

/**
 * Updates details of account associated with current API key.
 * <p>
 * Example:
 *
 * <pre>
 * {@code Account account = accountManagementApi.getAccount()
 *     account.setCity("Austin");
 *     accoujnt.setState("Texas");
 *     account.setCountry("US");
 *
 *     accountManagementApi.updateAccount(account);
 * }
 * </pre>
 *
 * @param account
 *            The account object to update.
 * @return updated account.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Account updateAccount(@NonNull Account account) throws MbedCloudException {
    checkNotNull(account, TAG_ACCOUNT);
    checkModelValidity(account, TAG_ACCOUNT);
    final Account finalAccount = account;
    return CloudCaller.call(this, "updateAccount()", AccountAdapter.getMapper(), new CloudCall<AccountInfo>() {

        @Override
        public Call<AccountInfo> call() {
            return endpoint.getAdmin().updateMyAccount(AccountAdapter.reverseMap(finalAccount));
        }
    });
}
Also used : Account(com.arm.mbed.cloud.sdk.accountmanagement.model.Account) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) AccountInfo(com.arm.mbed.cloud.sdk.internal.iam.model.AccountInfo) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Aggregations

CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)29 Call (retrofit2.Call)29 API (com.arm.mbed.cloud.sdk.annotations.API)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)19 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)3 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)3 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)2 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)2 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)2 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)2 NonNull (com.arm.mbed.cloud.sdk.annotations.NonNull)2 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)2 ListOptions (com.arm.mbed.cloud.sdk.common.listing.ListOptions)2 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)2 Query (com.arm.mbed.cloud.sdk.devicedirectory.model.Query)2 DeviceData (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData)2 DeviceQuery (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery)2 ApiKeyInfoResp (com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp)2