use of com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey in project mbed-cloud-sdk-java by ARMmbed.
the class ApiKeyAdapter method map.
/**
* Maps API keys.
*
* @param apiKeyInfo
* an API key.
* @return an API Key.
*/
public static ApiKey map(ApiKeyInfoResp apiKeyInfo) {
if (apiKeyInfo == null) {
return null;
}
final ApiKey apiKey = new ApiKey(apiKeyInfo.getId(), apiKeyInfo.getKey(), TranslationUtils.toDate(apiKeyInfo.getCreatedAt()), TranslationUtils.toTimeStamp(apiKeyInfo.getCreationTime()), TranslationUtils.toTimeStamp(apiKeyInfo.getLastLoginTime()));
apiKey.setName(apiKeyInfo.getName());
apiKey.setOwnerId(apiKeyInfo.getOwner());
apiKey.setGroup(apiKeyInfo.getGroups());
apiKey.setStatus(toStatus(apiKeyInfo.getStatus()));
return apiKey;
}
use of com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey 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.accountmanagement.model.ApiKey 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.accountmanagement.model.ApiKey in project mbed-cloud-sdk-java by ARMmbed.
the class AccountManagementExamples method listGroups.
/**
* Lists the last 5 groups and their contents.
*/
@SuppressWarnings("boxing")
@Example
public void listGroups() {
ConnectionOptions config = Configuration.get();
AccountManagement api = new AccountManagement(config);
try {
// Defining query options
GroupListOptions options = new GroupListOptions();
options.setLimit(5);
options.setOrder(Order.DESC);
// Listing groups.
ListResponse<Group> groups = api.listGroups(options);
for (Group group : groups.getData()) {
log("Group", group);
Paginator<ApiKey> apiKeyIterator = api.listAllGroupApiKeys(group.getId(), null);
while (apiKeyIterator.hasNext()) {
log("API key of group [" + group.getId() + "]", apiKeyIterator.next());
}
Paginator<User> userIterator = api.listAllGroupUsers(group.getId(), null);
while (userIterator.hasNext()) {
log("User of group [" + group.getId() + "]", userIterator.next());
}
}
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey in project mbed-cloud-sdk-java by ARMmbed.
the class AccountManagementExamples method listApiKeys.
/**
* Lists the first 5 API Keys.
*/
@SuppressWarnings("boxing")
@Example
public void listApiKeys() {
ConnectionOptions config = Configuration.get();
AccountManagement api = new AccountManagement(config);
try {
// Defining query options
ApiKeyListOptions options = new ApiKeyListOptions();
options.setLimit(5);
// Listing API keys.
Paginator<ApiKey> apikeys = api.listAllApiKeys(options);
for (ApiKey apiKey : apikeys) {
log("API key", apiKey);
}
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
fail(e.getMessage());
}
}
Aggregations