Search in sources :

Example 26 with ConnectionOptions

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());
    }
}
Also used : DeviceDirectory(com.arm.mbed.cloud.sdk.DeviceDirectory) Query(com.arm.mbed.cloud.sdk.devicedirectory.model.Query) Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) DeviceListOptions(com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions) Date(java.util.Date) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 27 with ConnectionOptions

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());
    }
}
Also used : DeviceDirectory(com.arm.mbed.cloud.sdk.DeviceDirectory) Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 28 with ConnectionOptions

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());
    }
}
Also used : Account(com.arm.mbed.cloud.sdk.accountmanagement.model.Account) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 29 with ConnectionOptions

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());
    }
}
Also used : ApiKey(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey) ApiKeyListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 30 with ConnectionOptions

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());
    }
}
Also used : User(com.arm.mbed.cloud.sdk.accountmanagement.model.User) UserListOptions(com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) AccountManagement(com.arm.mbed.cloud.sdk.AccountManagement) AbstractExample(utils.AbstractExample) Example(utils.Example)

Aggregations

ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)35 AbstractExample (utils.AbstractExample)31 Example (utils.Example)31 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)27 Connect (com.arm.mbed.cloud.sdk.Connect)15 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)12 DeviceListOptions (com.arm.mbed.cloud.sdk.devicedirectory.model.DeviceListOptions)10 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)8 DeviceDirectory (com.arm.mbed.cloud.sdk.DeviceDirectory)7 AccountManagement (com.arm.mbed.cloud.sdk.AccountManagement)4 Update (com.arm.mbed.cloud.sdk.Update)4 Metric (com.arm.mbed.cloud.sdk.connect.model.Metric)3 Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)3 Query (com.arm.mbed.cloud.sdk.devicedirectory.model.Query)3 Certificates (com.arm.mbed.cloud.sdk.Certificates)2 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)2 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)2 TimePeriod (com.arm.mbed.cloud.sdk.common.TimePeriod)2 MetricsPeriodListOptions (com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions)2