Search in sources :

Example 21 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 22 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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)

Example 23 with API

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

the class Connect method updatePresubscriptions.

/**
 * Updates pre-subscription data.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String deviceId = "015f4ac587f500000000000100100249";
 *
 *     Presubscription presub1 = new Presubscription();
 *     presub1.setDeviceType("default");
 *     List<String> resourceList1 = Arrays.asList("/3201/0/5850", "/3201/0/5853");
 *     presub1.setResourcePaths(resourceList1);
 *
 *     Presubscription presub2 = new Presubscription();
 *     presub2.setDeviceId(deviceId);
 *     List<String> resourceList2 = Arrays.asList("/3200/0/5501");
 *     presub2.setResourcePaths(resourceList2);
 *
 *     List<Presubscription> presubscriptions = Arrays.asList(presub1, presub2);
 *     connectApi.updatePresubscriptions(presubscriptions);
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param presubscriptions
 *            The pre-subscription list to update.
 *            <p>
 *            If you send an empty/null array, the pre-subscription data will be removed @see
 *            {@link #deletePresubscriptions()} for similar action.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
public void updatePresubscriptions(@Nullable List<Presubscription> presubscriptions) throws MbedCloudException {
    final List<Presubscription> finalList = presubscriptions;
    final PresubscriptionArray array = PresubscriptionAdapter.reverseMapList(finalList);
    CloudCaller.call(this, "updatePresubscriptions()", null, new CloudCall<Void>() {

        @Override
        public Call<Void> call() {
            return endpoint.getSubscriptions().v2SubscriptionsPut(array);
        }
    });
}
Also used : Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) PresubscriptionArray(com.arm.mbed.cloud.sdk.internal.mds.model.PresubscriptionArray) Presubscription(com.arm.mbed.cloud.sdk.connect.model.Presubscription) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 24 with API

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

the class Connect method getResource.

/**
 * Gets device's resource.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Device device = new Device();
 *     device.setId("015f4ac587f500000000000100100249");
 *
 *     String resourcePath = "/3201/0/5853";
 *
 *     Resource resource = connectApi.getResource(device, resourcePath);
 *     System.out.println("Confirmed resource path: " + resource.getPath());
 *     assert resourcePath == resource.getPath();
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param device
 *            Device.
 * @param resourcePath
 *            Path of the resource to get
 * @return resource present on the device.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Resource getResource(@NonNull Device device, @NonNull String resourcePath) throws MbedCloudException {
    checkNotNull(device, TAG_DEVICE);
    checkNotNull(device.getId(), TAG_DEVICE_ID);
    checkNotNull(resourcePath, TAG_RESOURCE_PATH);
    final List<Resource> resources = listResources(device);
    if (resources == null || resources.isEmpty()) {
        return null;
    }
    for (final Resource resource : resources) {
        if (ApiUtils.comparePaths(resourcePath, resource.getPath())) {
            return resource;
        }
    }
    return null;
}
Also used : Resource(com.arm.mbed.cloud.sdk.connect.model.Resource) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 25 with API

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

the class Update method addFirmwareManifest.

/**
 * Adds a firmware manifest.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String fileName = "C:\\Users\\mbedUser\\quickstart.manifest";
 *     FirmwareManifest manifest = new FirmwareManifest();
 *     manifest.setDatafile(fileName);
 *     manifest.setDescription("Quick start manifest");
 *     manifest.setName(manifest.getDatafile().getName());
 *
 *     FirmwareManifest newManifest = updateApi.addFirmwareManifest(manifest);
 *     System.out.println("FirmwareManifest URL: " + newManifest.getUrl());
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param manifest
 *            The manifest to add.
 * @return added manifest.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public FirmwareManifest addFirmwareManifest(@NonNull FirmwareManifest manifest) throws MbedCloudException {
    checkNotNull(manifest, TAG_FIRMWARE_MANIFEST);
    checkModelValidity(manifest, TAG_FIRMWARE_MANIFEST);
    final FirmwareManifest finalManifest = manifest;
    return CloudCaller.call(this, "addFirmwareManifest()", FirmwareManifestAdapter.getMapper(), new CloudCall<com.arm.mbed.cloud.sdk.internal.updateservice.model.FirmwareManifest>() {

        @Override
        public Call<com.arm.mbed.cloud.sdk.internal.updateservice.model.FirmwareManifest> call() {
            return endpoint.getUpdate().firmwareManifestCreate(DataFileAdapter.reverseMap(finalManifest.getDataFile()), finalManifest.getName(), finalManifest.getDescription(), DataFileAdapter.reverseMap(finalManifest.getDecryptionKeysFile()));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) FirmwareManifest(com.arm.mbed.cloud.sdk.update.model.FirmwareManifest) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Aggregations

API (com.arm.mbed.cloud.sdk.annotations.API)34 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)26 Call (retrofit2.Call)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)23 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)5 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)4 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)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 Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)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