Search in sources :

Example 1 with ApiKeyInfoResp

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));
        }
    });
}
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) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 2 with ApiKeyInfoResp

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));
        }
    });
}
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 3 with ApiKeyInfoResp

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());
}
Also used : ApiKeyInfoRespList(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoRespList) ApiKeyInfoResp(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp) ApiKeyInfoRespList(com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoRespList) RespList(com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)

Aggregations

ApiKeyInfoResp (com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp)3 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 API (com.arm.mbed.cloud.sdk.annotations.API)2 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)2 Call (retrofit2.Call)2 NonNull (com.arm.mbed.cloud.sdk.annotations.NonNull)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 RespList (com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)1 ApiKeyInfoRespList (com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoRespList)1