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()));
}
});
}
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;
}
}
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);
}
});
}
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;
}
Aggregations