use of com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp 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.internal.iam.model.ApiKeyInfoResp 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.internal.iam.model.ApiKeyInfoResp in project mbed-cloud-sdk-java by ARMmbed.
the class ApiKeyAdapter method mapList.
/**
* Maps a list of API keys.
*
* @param list
* list of API keys.
* @return list of API keys.
*/
public static ListResponse<ApiKey> mapList(ApiKeyInfoRespList list) {
final ApiKeyInfoRespList apiKeyList = list;
final RespList<ApiKeyInfoResp> respList = new RespList<ApiKeyInfoResp>() {
@Override
public Boolean getHasMore() {
return (apiKeyList == null) ? null : apiKeyList.isHasMore();
}
@Override
public Integer getTotalCount() {
return (apiKeyList == null) ? null : apiKeyList.getTotalCount();
}
@Override
public String getAfter() {
return (apiKeyList == null) ? null : apiKeyList.getAfter();
}
@Override
public Integer getLimit() {
return (apiKeyList == null) ? null : apiKeyList.getLimit();
}
@Override
public String getOrder() {
return (apiKeyList == null) ? null : apiKeyList.getOrder().toString();
}
@Override
public List<ApiKeyInfoResp> getData() {
return (apiKeyList == null) ? null : apiKeyList.getData();
}
};
return GenericAdapter.mapList(respList, getMapper());
}
Aggregations