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));
}
});
}
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));
}
});
}
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);
}
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();
}
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));
}
});
}
Aggregations