use of utils.Example 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());
}
}
use of utils.Example 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());
}
}
use of utils.Example 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);
}
}
use of utils.Example in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method listLast2DaysMetric.
/**
* Lists metrics from last 2 days in 3-hour intervals.
*/
@Example
public void listLast2DaysMetric() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
try {
// Defining query options.
MetricsPeriodListOptions options = new MetricsPeriodListOptions();
options.setPeriod("2d");
options.setInterval("3h");
// 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());
}
}
use of utils.Example in project mbed-cloud-sdk-java by ARMmbed.
the class ConnectExamples method switchNotificationChannelWithForceClear.
/**
* Switches between notification channels using forceClear.
* <p>
* forceClear parameter forces a notification channel to stop before a new one is started.
*/
@Example
public void switchNotificationChannelWithForceClear() {
ConnectionOptions config = Configuration.get();
Connect api = new Connect(config);
try {
// Setting forceClear to true
api.setForceClear(true);
// Using Notification pull channel.
api.startNotifications();
Thread.sleep(5000);
// 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);
// Using Notification pull channel again.
api.startNotifications();
Thread.sleep(5000);
// Shutting down connect service.
api.shutdownConnectService();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
try {
api.shutdownConnectService();
Thread.sleep(100);
} catch (Exception e1) {
e1.printStackTrace();
}
deleteWebhook(api);
}
}
Aggregations