Search in sources :

Example 31 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 32 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 33 with API

use of com.arm.mbed.cloud.sdk.annotations.API 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 34 with API

use of com.arm.mbed.cloud.sdk.annotations.API in project mbed-cloud-sdk-java by ARMmbed.

the class TestStub method success.

/**
 * Test API that returns the arguments it received, some connection options and adds a day to the date argument it
 * received. I also returns a field 'success': true
 *
 * @throws MbedCloudException
 *             an exception
 */
@SuppressWarnings("boxing")
@API
public Map<String, Object> success(String testArgument0, int testArgument1, String testArgument2, Date testArgument3) throws MbedCloudException {
    Map<String, Object> obj = new HashMap<>(10);
    obj.put("testArgument0", testArgument0);
    obj.put("testArgument1", testArgument1);
    obj.put("testArgument2", testArgument2);
    // Adding a day to testArgument3
    Calendar c = Calendar.getInstance();
    c.setTime(testArgument3);
    c.add(Calendar.DATE, 1);
    obj.put("testArgument3", c.getTime());
    obj.put("success", true);
    obj.put("apiKey", opt.getApiKey());
    obj.put("host", opt.getHost());
    return obj;
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) API(com.arm.mbed.cloud.sdk.annotations.API)

Aggregations

API (com.arm.mbed.cloud.sdk.annotations.API)34 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)26 Call (retrofit2.Call)26 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)23 Resource (com.arm.mbed.cloud.sdk.connect.model.Resource)5 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)4 Certificate (com.arm.mbed.cloud.sdk.certificates.model.Certificate)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 Webhook (com.arm.mbed.cloud.sdk.connect.model.Webhook)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