use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.
the class DeviceDirectoryExamples method manageQueries.
/**
* Creates, updates and deletes a query.
*/
@SuppressWarnings("boxing")
@Example
public void manageQueries() {
ConnectionOptions config = Configuration.get();
DeviceDirectory api = new DeviceDirectory(config);
String queryId = null;
try {
// Creating a query.
String queryName = "test-" + UUID.randomUUID().toString();
log("Query name", queryName);
Query myQuery = new Query(queryName, null);
myQuery.addCreatedAtFilter(new Date(), FilterOperator.LESS_THAN);
// Adding the query.
myQuery = api.addQuery(myQuery);
log("Created query", myQuery);
queryId = myQuery.getId();
// Updating the query.
queryName = "test-" + UUID.randomUUID().toString();
log("Updated Query name", queryName);
myQuery.setName(queryName);
myQuery = api.updateQuery(myQuery);
log("Updated query", myQuery);
queryId = myQuery.getId();
// Fetching the query.
myQuery = api.getQuery(queryId);
log("Retrieved query", myQuery);
// Finding the first 5 devices corresponding to the query.
DeviceListOptions options = new DeviceListOptions();
options.setFilters(myQuery.fetchFilters());
options.setLimit(5);
ListResponse<Device> matchingDevices = api.listDevices(options);
for (Device device : matchingDevices.getData()) {
log("Matching device", device);
}
// Deleting the query.
deleteCreatedQuery(queryId, api);
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
deleteCreatedQuery(queryId, api);
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.
the class DeviceDirectoryExamples method manageDevices.
/**
* Creates, updates and deletes a device.
*/
@SuppressWarnings("boxing")
@Example
public void manageDevices() {
ConnectionOptions config = Configuration.get();
DeviceDirectory api = new DeviceDirectory(config);
String deviceId = null;
try {
// Creating a device.
String certificateIssuerId = UUID.randomUUID().toString();
log("Certificate Issuer Id", certificateIssuerId);
String certificateFingerprint = UUID.randomUUID().toString();
log("Certificate Fingerprint", certificateFingerprint);
Device myDevice = new Device(certificateIssuerId, certificateFingerprint);
myDevice.setName("my-test-device-" + UUID.randomUUID().toString());
myDevice.setDeviceExecutionMode(1);
// Adding the device.
myDevice = api.addDevice(myDevice);
log("Created device", myDevice);
deviceId = myDevice.getId();
// Updating the device.
certificateIssuerId = UUID.randomUUID().toString();
log("Updated Certificate Issuer Id", certificateIssuerId);
myDevice.setCertificateIssuerId(certificateIssuerId);
myDevice = api.updateDevice(myDevice);
log("Updated device", myDevice);
deviceId = myDevice.getId();
// Deleting the device.
deleteCreatedDevice(deviceId, api);
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
deleteCreatedDevice(deviceId, api);
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.
the class AccountManagementExamples method getAccount.
/**
* Gets details of the account associated with this API key.
*/
@Example
public void getAccount() {
ConnectionOptions config = Configuration.get();
AccountManagement api = new AccountManagement(config);
try {
Account thisAccount;
thisAccount = api.getAccount();
log("This account", thisAccount);
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
fail(e.getMessage());
}
}
use of com.arm.mbed.cloud.sdk.common.ConnectionOptions 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());
}
}
use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.
the class AccountManagementExamples method listUsers.
/**
* Lists the first 5 active users.
*/
@SuppressWarnings("boxing")
@Example
public void listUsers() {
ConnectionOptions config = Configuration.get();
AccountManagement api = new AccountManagement(config);
try {
// Defining query options
UserListOptions options = new UserListOptions();
options.setLimit(5);
// Listing users.
Paginator<User> users = api.listAllUsers(options);
for (User user : users) {
log("User", user);
}
} catch (Exception e) {
logError("last API Metadata", api.getLastApiMetadata());
fail(e.getMessage());
}
}
Aggregations