Search in sources :

Example 11 with API

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

the class AccountManagement method updateUser.

/**
 * Updates a user.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     User user = new User();
 *     String userId = "015f4ac587f500000000000100109294";
 *     user.setId(userId);
 *     user.setEmail("javaSDK@arm.com");
 *     user.setUsername("javaSDK");
 *     user.setFullName("New JavaSDK");
 *
 *     User newUser = accountManagementApi.updateUser(user);
 *     System.out.println("New User name: " + newUser.getFullName());
 *     assert userId == newUser.getId();
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param user
 *            User to update.
 * @return updated user.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public User updateUser(@NonNull User user) throws MbedCloudException {
    checkNotNull(user, TAG_USER);
    checkNotNull(user.getId(), TAG_USER_UUID);
    // checkModelValidity(user, TAG_USER);
    User updatedUser = null;
    if (user.hasEmailBeenUpdated()) {
        updatedUser = user;
    } else {
        updatedUser = user.clone();
        updatedUser.setEmail(null);
    }
    final User finalUser = updatedUser;
    return CloudCaller.call(this, "updateUser()", UserAdapter.getMapper(), new CloudCall<UserInfoResp>() {

        @Override
        public Call<UserInfoResp> call() {
            return endpoint.getAdmin().updateUser(finalUser.getId(), UserAdapter.reverseMapUpdate(finalUser));
        }
    });
}
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) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 12 with API

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

the class AccountManagement method addApiKey.

/**
 * Adds an API key.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     ApiKey apiKey = new ApiKey();
 *     apiKey.setName("QuickstartKey");
 *
 *     ApiKey newApiKey = accountManagementApi.addApiKey(apiKey);
 *     System.out.println("Api Key: " + newApiKey.getKey());
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param apiKey
 *            The API key to add.
 * @return added API Key.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@NonNull
public ApiKey addApiKey(@NonNull ApiKey apiKey) throws MbedCloudException {
    checkNotNull(apiKey, TAG_API_KEY);
    checkModelValidity(apiKey, TAG_API_KEY);
    final ApiKey finalApiKey = apiKey;
    return CloudCaller.call(this, "addApiKey()", ApiKeyAdapter.getMapper(), new CloudCall<ApiKeyInfoResp>() {

        @Override
        public Call<ApiKeyInfoResp> call() {
            return endpoint.getDeveloper().createApiKey(ApiKeyAdapter.reverseMapAdd(finalApiKey));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) ApiKeyInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp) NonNull(com.arm.mbed.cloud.sdk.annotations.NonNull) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 13 with API

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

the class Connect method createResourceSubscriptionObserver.

/**
 * Creates an observer for resource subscriptions.
 * <p>
 * Note: for more information about observers @see <a href="http://reactivex.io/">Reactive X</a> or
 * <a href="https://github.com/ReactiveX/RxJava">RxJava</a> *
 * <p>
 * Example:
 *
 * <pre>
 * {
 * {@code String resourcePath = "/3200/0/5501";
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     Resource resource = new Resource(deviceId, path);
 *     connectApi.createResourceSubscriptionObserver(resource, BackpressureStrategy.BUFFER)
 *                   .subscribe(System.out::println);
 *     connectApi.addResourceSubscription(resource);
 * }
 * </pre>
 *
 * @param resource
 *            resource to subscribe to.
 * @param strategy
 *            backpressure strategy to apply @see {@link BackpressureStrategy}
 * @return Observable which can be subscribed to. @see {@link Flowable}
 * @throws MbedCloudException
 *             if an error occurred in the process.
 */
@API
@Nullable
public Flowable<NotificationMessageValue> createResourceSubscriptionObserver(@NonNull Resource resource, @Nullable @DefaultValue("BUFFER") BackpressureStrategy strategy) throws MbedCloudException {
    checkNotNull(resource, TAG_RESOURCE);
    checkModelValidity(resource, TAG_RESOURCE);
    final BackpressureStrategy finalStrategy = (strategy == null) ? BackpressureStrategy.BUFFER : strategy;
    return handlersStore.createResourceSubscriptionObserver(resource, finalStrategy);
}
Also used : BackpressureStrategy(io.reactivex.BackpressureStrategy) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 14 with API

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

the class Connect method deleteSubscriptions.

/**
 * Removes all subscriptions.
 * <p>
 * Note: this method will deregister all subscription callbacks or observers if any.
 * <p>
 * Warning: Please note that this operation is potentially really expensive and hence, use wisely.
 * <p>
 * It could be slow for large numbers of connected devices. If possible, explicitly delete subscriptions known to
 * have been created.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     connectApi.deleteSubscriptions();
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
public void deleteSubscriptions() throws MbedCloudException {
    // The following is a workaround until there is a Mbed Cloud endpoint providing such an action.
    logger.logWarn("deleteSubscriptions() could be slow for large numbers of connected devices. " + "If possible, explicitly delete subscriptions known to have been created.");
    final Paginator<Device> connectedDevices = listAllConnectedDevices(null);
    if (connectedDevices != null) {
        for (final Device connectedDevice : connectedDevices) {
            deleteDeviceSubscriptions(connectedDevice);
        }
    }
// When such an endpoint is created, use some code similar to below.
// CloudCaller.call(this, "deleteSubscriptions()", null, new CloudCall<Void>() {
// 
// @Override
// public Call<Void> call() {
// return endpoint.getSubscriptions().v2SubscriptionsDelete();
// }
// });
// deregisterAllResourceSubscriptionObserversOrCallbacks();
}
Also used : Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 15 with API

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

the class Connect method updateWebhook.

/**
 * Registers new webhook for incoming subscriptions.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Webhook webhook = new Webhook();
 *     webhook.setUrl("https://goo.gl/testwh");
 *     webhook.addHeader("Auth","token");
 *     connectApi.updateWebhook(webhook);
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param webhook
 *            Webhook to set.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
public void updateWebhook(@NonNull Webhook webhook) throws MbedCloudException {
    checkNotNull(webhook, TAG_WEBHOOK);
    checkModelValidity(webhook, TAG_WEBHOOK);
    if (isForceClear()) {
        stopNotifications();
    }
    final Webhook finalWebhook = webhook;
    CloudCaller.call(this, "updateWebhook()", null, new CloudCall<Void>() {

        @Override
        public Call<Void> call() {
            return endpoint.getNotifications().v2NotificationCallbackPut(WebhookAdapter.reverseMap(finalWebhook));
        }
    });
}
Also used : Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Webhook(com.arm.mbed.cloud.sdk.connect.model.Webhook) API(com.arm.mbed.cloud.sdk.annotations.API)

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