Search in sources :

Example 16 with ConnectionOptions

use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.

the class NotificationHandlersStore method createNotificationPull.

private EndPoints createNotificationPull(EndPoints endpoint2) {
    if (endpoint2 == null) {
        return null;
    }
    final ConnectionOptions options = endpoint2.getConnectionOptions();
    options.setRequestTimeout(REQUEST_TIMEOUT);
    return new EndPoints(options);
}
Also used : ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) EndPoints(com.arm.mbed.cloud.sdk.connect.model.EndPoints)

Example 17 with ConnectionOptions

use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.

the class UpdateExamples method listCampaigns.

/**
 * Lists the first 5 update campaigns.
 */
@SuppressWarnings("boxing")
@Example
public void listCampaigns() {
    ConnectionOptions config = Configuration.get();
    Update api = new Update(config);
    try {
        // Defining query options.
        CampaignListOptions options = new CampaignListOptions();
        options.setLimit(5);
        // Listing campaigns.
        Paginator<Campaign> campaigns = api.listAllCampaigns(options);
        for (Campaign campaign : campaigns) {
            log("Update campaign", campaign);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : Campaign(com.arm.mbed.cloud.sdk.update.model.Campaign) CampaignListOptions(com.arm.mbed.cloud.sdk.update.model.CampaignListOptions) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Update(com.arm.mbed.cloud.sdk.Update) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 18 with ConnectionOptions

use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.

the class UpdateExamples method listFirmwareManifests.

/**
 * Lists the first 5 firmware manifests.
 */
@SuppressWarnings("boxing")
@Example
public void listFirmwareManifests() {
    ConnectionOptions config = Configuration.get();
    Update api = new Update(config);
    try {
        // Defining query options.
        FirmwareManifestListOptions options = new FirmwareManifestListOptions();
        options.setLimit(5);
        // Listing firmware manifests.
        Paginator<FirmwareManifest> manifests = api.listAllFirmwareManifests(options);
        for (FirmwareManifest manifest : manifests) {
            log("Firmware manifest", manifest);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : FirmwareManifestListOptions(com.arm.mbed.cloud.sdk.update.model.FirmwareManifestListOptions) FirmwareManifest(com.arm.mbed.cloud.sdk.update.model.FirmwareManifest) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Update(com.arm.mbed.cloud.sdk.Update) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 19 with ConnectionOptions

use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.

the class ConnectExamples method listLast30DaysMetric.

/**
 * Lists metrics from last 30 days in 1-day intervals.
 */
@Example
public void listLast30DaysMetric() {
    ConnectionOptions config = Configuration.get();
    Connect api = new Connect(config);
    try {
        // Defining query options.
        MetricsPeriodListOptions options = new MetricsPeriodListOptions();
        options.setPeriod("30d");
        options.setInterval("1d");
        // Listing metrics data.
        Paginator<Metric> metrics = api.listAllMetrics(options);
        for (Metric metric : metrics) {
            log("Metric", metric);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : MetricsPeriodListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions) Connect(com.arm.mbed.cloud.sdk.Connect) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Metric(com.arm.mbed.cloud.sdk.connect.model.Metric) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 20 with ConnectionOptions

use of com.arm.mbed.cloud.sdk.common.ConnectionOptions in project mbed-cloud-sdk-java by ARMmbed.

the class ConnectExamples method switchNotificationChannel.

/**
 * Switches between notification channels.
 */
@Example
public void switchNotificationChannel() {
    ConnectionOptions config = Configuration.get();
    Connect api = new Connect(config);
    try {
        // Using Notification pull channel.
        api.startNotifications();
        Thread.sleep(5000);
        // Stopping notification pull channel.
        api.stopNotifications();
        Thread.sleep(100);
        // Starting a webhook channel.
        // Creating a webhook.
        Webhook webhook = new Webhook(new URL("http://mbedcloudjavawebhooktest.requestcatcher.com/test"));
        log("Webhook", webhook);
        // Setting up the webhook.
        api.updateWebhook(webhook);
        Thread.sleep(2000);
        // Stopping webhook channel.
        deleteWebhook(api);
        // Shutting down connect service.
        api.shutdownConnectService();
        Thread.sleep(100);
    } catch (Exception e) {
        e.printStackTrace();
        try {
            api.stopNotifications();
            Thread.sleep(100);
            api.shutdownConnectService();
            Thread.sleep(100);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        deleteWebhook(api);
    }
}
Also used : Connect(com.arm.mbed.cloud.sdk.Connect) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Webhook(com.arm.mbed.cloud.sdk.connect.model.Webhook) URL(java.net.URL) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) 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