CloudPlugs REST Library  1.0.0
for Objective-C
CloudPlugs Objective-C Client Library

CloudPlugs REST Client for Objective-C is a library to perform HTTP requests to CloudPlugs servers. The official repository is: https://github.com/cloudplugs/rest-objc

The Cloudplugs IoT Platform

Cloudplugs is a cloud based IoT platform to enable the fast prototyping, connection, deployment and management of smart "Things" (sensors, smartphones, home appliances, etc.). Different objects can interact with each other by publishing and/or reading any type of data on shared channels through simple communication protocols. You can learn more at http://www.cloudplugs.com/how-it-works/ and you can sign-up on http://www.cloudplugs.com/register to start connecting your Things.

Library Guide

Requirements

  • ARC
  • iOS 5.0+ (not required for Mac OSX target)

Build and link the framework

To use the library within your project follow this steps:

  • Download the library
  • Open with Xcode
  • Run the project

After executing the compile script a framework will be be created in the 'project_dir/build/' directory.

  • Create new project or Open existing one in Xcode
  • From the "General" tab, scroll down to "Linked Frameworks and Libraries" and include the framework created at the previous steps.

Usage

Include Cloudplugs class:

#import <CloudPlugsRestClient/CloudPlugsRestClient.h>

Create a new session and initialize the data required:

Now you are ready to configure the library and invoke functions to perform REST requests to the server!

Configuration

There are a few configuration parameters available for customization (if needed) before invoking any request. This parameters are:

  • authId: the authentication user
  • authPass: the authentication password
  • authMaster: whether to invoke requests as a master user or not
  • timeout: connection timeout in seconds
  • baseUrl: base URL for HTTP requests

    Example:
    [cp setAuthId:@"dev-xxxxxxxxxxxxxxxxxx"];
    [cp setAuthPass:@"your-password"];
    [cp setAuthMaster:YES];

Execute Rest HTTP requests

After completing the configuration, you can execute HTTP requests to the server by invoking any of the request functions. All the requests are asynchronous and are executed per the Cloudplugs Rest API documentation. For example:

[cp publishData :@"temperature"
body :@{@"data":[NSNumber numberWithInt:getTemp()]}
completionHandler :^(CloudPlugsRequest* req, CloudPlugsResponse* res) {
NSLog(@"publish %@", res ? (res.object ? res.object : res.string) : @"");
}
];