use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class AccountManagement method updateApiKey.
/**
* Updates an API key.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* ApiKey apiKey = new ApiKey();
* String apiKeyId = "015f4ac587f500000000000100100249";
* apiKey.setId(apiKeyId);
* apiKey.setName("NewKeyName");
*
* ApiKey newApiKey = accountManagementApi.updateApiKey(apiKey);
* System.out.println("New Api Key name: " + newApiKey.getName());
* assert apiKeyId == newApiKey.getId();
*
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param apiKey
* The API key to update.
* @return updated API key.
* @throws MbedCloudException
* if a problem occurred during request processing.
*/
@API
@Nullable
public ApiKey updateApiKey(@NonNull ApiKey apiKey) throws MbedCloudException {
checkNotNull(apiKey, TAG_API_KEY);
checkNotNull(apiKey.getId(), TAG_API_KEY_UUID);
checkModelValidity(apiKey, TAG_API_KEY);
ApiKey updatedApiKey = null;
if (apiKey.hasStatusBeenUpdated()) {
updatedApiKey = apiKey;
} else {
updatedApiKey = apiKey.clone();
updatedApiKey.setStatus(null);
}
final ApiKey finalApiKey = updatedApiKey;
return CloudCaller.call(this, "updateApiKey()", ApiKeyAdapter.getMapper(), new CloudCall<ApiKeyInfoResp>() {
@Override
public Call<ApiKeyInfoResp> call() {
return endpoint.getDeveloper().updateApiKey(finalApiKey.getId(), ApiKeyAdapter.reverseMapUpdate(finalApiKey));
}
});
}
use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall 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.common.CloudCaller.CloudCall 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.common.CloudCaller.CloudCall 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));
}
});
}
use of com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall in project mbed-cloud-sdk-java by ARMmbed.
the class Connect method listMetrics.
/**
* Lists metrics.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* Calendar startDate = GregorianCalendar(2017,10,30,10,20,56);
* Calendar endDate = GregorianCalendar(2017,11,31,10,20,56);
*
* MetricsStartEndListOptions listOptions = new MetricsStartEndListOptions();
* listOptions.setStart(startDate.getTime());
* listOptions.setEnd(endDate.getTime());
* listOptions.setInterval(new TimePeriod(360)); //Once an hour
*
* ListResponse<Metric> metrics = connectApi.listMetrics(listOptions);
* //Iterates over a page
* for (Metric metric : metrics.getData()) {
* System.out.println("Time: " + dateFormat.format(metric.getTimestamp()));
* System.out.println("Successful bootstraps: " + metric.getSuccessfulBootstraps());
* System.out.println("Successful api calls: " + metric.getSuccessfulApiCalls());
* System.out.println("");
* }
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param options
* metrics options.
* @param <T>
* Type of metrics list options
* @return list of metrics for the corresponding options.
* @throws MbedCloudException
* if a problem occurred during request processing.
*/
@API
@Nullable
public <T extends AbstractMetricsListOptions> ListResponse<Metric> listMetrics(@NonNull T options) throws MbedCloudException {
checkNotNull(options, TAG_METRIC_OPTIONS);
final T finalOptions = options;
final Date finalStart = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getStart() : null;
final Date finalEnd = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getEnd() : null;
final String finalPeriod = options instanceof MetricsPeriodListOptions ? ((MetricsPeriodListOptions) options).getPeriod().toString() : null;
return CloudCaller.call(this, "listMetrics()", MetricAdapter.getListMapper(), new CloudCall<SuccessfulResponse>() {
@Override
public Call<SuccessfulResponse> call() {
return endpoint.getStatistic().v3MetricsGet(MetricAdapter.mapIncludes(finalOptions.getInclude()), finalOptions.getInterval().toString(), TranslationUtils.toLocalDate(finalStart), TranslationUtils.toLocalDate(finalEnd), finalPeriod, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString());
}
});
}
Aggregations