Search in sources :

Example 26 with CloudCall

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

the class Connect method addResourceSubscription.

/**
 * Subscribes to a resource.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     String resourcePath = "/3200/0/5501";
 *     Resource buttonResource = new Resource(deviceId, resourcePath);
 *
 *     connectApi.addResourceSubscription(buttonResource);
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param resource
 *            resource to subscribe to.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
public void addResourceSubscription(@NonNull Resource resource) throws MbedCloudException {
    checkNotNull(resource, TAG_RESOURCE);
    checkModelValidity(resource, TAG_RESOURCE);
    final Resource finalResource = resource;
    CloudCaller.call(this, "addResourceSubscription()", null, new CloudCall<Void>() {

        @Override
        public Call<Void> call() {
            return endpoint.getSubscriptions().v2SubscriptionsDeviceIdResourcePathPut(finalResource.getDeviceId(), ApiUtils.normalisePath(finalResource.getPath()));
        }
    });
}
Also used : Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Resource(com.arm.mbed.cloud.sdk.connect.model.Resource) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 27 with CloudCall

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

the class Connect method getResourceSubscription.

/**
 * Gets the status of a resource's subscription.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     String resourcePath = "/3200/0/5501";
 *     Resource buttonResource = new Resource(deviceId, resourcePath);
 *
 *     boolean subscribed = connectApi.getResourceSubscription(buttonResource);
 *     System.out.println("Is " + deviceId + " subscribed to: " + resourcePath + "? " + (subscribed ? "yes" : "no"));
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param resource
 *            resource
 * @return true if resource is subscribed. false otherwise.
 * @throws MbedCloudException
 *             if a parameter is incorrect
 */
@API
public boolean getResourceSubscription(@NonNull Resource resource) throws MbedCloudException {
    checkNotNull(resource, TAG_RESOURCE);
    checkModelValidity(resource, TAG_RESOURCE);
    final Resource finalResource = resource;
    try {
        CloudCaller.call(this, "getResourceSubscription()", null, new CloudCall<Void>() {

            @Override
            public Call<Void> call() {
                return endpoint.getSubscriptions().v2SubscriptionsDeviceIdResourcePathGet(finalResource.getDeviceId(), ApiUtils.normalisePath(finalResource.getPath()));
            }
        }, true);
        return true;
    } catch (MbedCloudException exception) {
        return false;
    }
}
Also used : Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) Resource(com.arm.mbed.cloud.sdk.connect.model.Resource) API(com.arm.mbed.cloud.sdk.annotations.API)

Example 28 with CloudCall

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

the class Enrollment method addEnrollmentClaim.

/**
 * Places an enrolment claim for one or several devices.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     String claimId = "A-35:e7:72:8a:07:50:3b:3d:75:96:57:52:72:41:0d:78:cc:c6:e5:53:48:c6:65:58:5b:fa:af:4d:2d:73:95:c5";
 *     EnrollmentClaim claim = enrollmentApi.addEnrollmentClaim(claimId)
 *     System.out.println(claim);
 *
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param claimId
 *            Claim Id. Pattern: '^[A-Z]{1}-[A-Za-z0-9:]{1, 256}' e.g.
 *            A-35:e7:72:8a:07:50:3b:3d:75:96:57:52:72:41:0d:78:cc:c6:e5:53:48:c6:65:58:5b:fa:af:4d:2d:73:95:c5
 * @return enrollment claim.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public EnrollmentClaim addEnrollmentClaim(@NonNull String claimId) throws MbedCloudException {
    checkNotNull(claimId, TAG_ENROLLMENT_ID);
    final EnrollmentId finalEnrollmentId = new EnrollmentId().enrollmentIdentity(claimId);
    return CloudCaller.call(this, "addEnrollmentClaim()", EnrollmentAdapter.getMapper(), new CloudCall<EnrollmentIdentity>() {

        @Override
        public Call<EnrollmentIdentity> call() {
            return endpoint.getEnrollment().createDeviceEnrollment(finalEnrollmentId);
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) EnrollmentIdentity(com.arm.mbed.cloud.sdk.internal.enrollment.model.EnrollmentIdentity) EnrollmentId(com.arm.mbed.cloud.sdk.internal.enrollment.model.EnrollmentId) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 29 with CloudCall

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

the class NotificationHandlersStore method createCachingSingleAction.

private Runnable createCachingSingleAction() {
    return new Runnable() {

        private final ExponentialBackoff backoffPolicy = new ExponentialBackoff(api.getLogger());

        @Override
        public void run() {
            try {
                final CallFeedback<NotificationMessage> feedback = CloudCaller.callWithFeedback(api, "NotificationPullGet()", getIdentityMapper(), new CloudCall<NotificationMessage>() {

                    @Override
                    public Call<NotificationMessage> call() {
                        return endpoint.getNotifications().v2NotificationPullGet();
                    }
                }, false, true);
                final NotificationMessage notificationMessage = feedback.getResult();
                if (notificationMessage == null) {
                    api.getLogger().logInfo("Notification pull did not receive any notification during last call. Call information: " + feedback.getMetadata());
                    return;
                }
                storeResponses(notificationMessage.getAsyncResponses());
                handleSubscriptions(notificationMessage.getNotifications());
                handleDeviceStateChanges(notificationMessage);
            } catch (MbedCloudException exception) {
                backoffPolicy.backoff();
                logPullError(exception);
            }
        }
    };
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) NotificationMessage(com.arm.mbed.cloud.sdk.internal.mds.model.NotificationMessage) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException)

Aggregations

CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)29 Call (retrofit2.Call)29 API (com.arm.mbed.cloud.sdk.annotations.API)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)19 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)3 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)3 TrustedCertificateResp (com.arm.mbed.cloud.sdk.internal.iam.model.TrustedCertificateResp)3 ApiKey (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKey)2 ApiKeyListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.ApiKeyListOptions)2 GroupListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.GroupListOptions)2 User (com.arm.mbed.cloud.sdk.accountmanagement.model.User)2 UserListOptions (com.arm.mbed.cloud.sdk.accountmanagement.model.UserListOptions)2 NonNull (com.arm.mbed.cloud.sdk.annotations.NonNull)2 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)2 ListOptions (com.arm.mbed.cloud.sdk.common.listing.ListOptions)2 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)2 Query (com.arm.mbed.cloud.sdk.devicedirectory.model.Query)2 DeviceData (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData)2 DeviceQuery (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceQuery)2 ApiKeyInfoResp (com.arm.mbed.cloud.sdk.internal.iam.model.ApiKeyInfoResp)2