Overview

Features

 
 

API Reference

The CloudBoost API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and to use HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which can be understood by off-the-shelf HTTP clients, and we support cross-origin resource sharing to allow you to interact securely with our API from a client-side web application / mobile application (though you should remember that you should never expose your secret API master key in any public website's client-side code, Client Key can be exposed). JSON will be returned in all responses from the API, including errors (though if you're using API bindings / SDK, we will convert the response to the appropriate language-specific object).

 

Dependencies

This SDK require few external libraries.

All the dependent libraries are included in Cloudboost Sdk zip file. Download and import these libraries in your java project.

 

Apps

In Cloudboost, you create an app each of which has its own AppID, Java Client Key and the Master Key that you apply to your web app. You master key is a secret which should not be shared in your client apps. Your account on CloudBoost can accommodate multiple apps. This is useful even if you have one application, since you can deploy different versions for test and production.

 

CloudApp

This is your CloudApp object, and it is used to initalize your app with CloudBoost.

 

CloudApp.init( appId, appKey )

Initialises the app.

ClientKey and MasterKey are the two keys that are provided for each app your create. If you want a client of your app have access to CloudBoost API, its recommended you only share ClientKey with your app.
We dont recommend initialising your app with MasterKey unless you install our API and make requests from your server.

Package

import io.cloudboost.CloudApp;

Arguments
appId
Application ID with which your app is registered.
appKey
Client/Master key unique for your app
Returns

It doesn't return anything.

final String myAppId = "schoolApp"; final String myKey = "d1bae1c6978e3ecd3d5c8a0095767c9c"; CloudApp.init(myAppId, myKey);
 

CloudObject

Your data in CloudBoost is represented with CloudObjects CloudObject. Each CloudObject belongs to a table in your database with us and each objct represents a row of data in that table. The data you can store in CloudObject has schema which you define in Table Designer in CloudBoost portal. You simply set whatever key-value pairs you want, and our backend will store it for you.

 

Package

import io.cloudboost.CloudObject;

Constructor

Instantiates a CloudObject object.

Argument
tableName
string The name of the table you want to deal with
Returns

It returns an instance of a CloudObject, because its a constructor.

Properties

Every instance of CloudObject has these properties

id
string The id of the CloudObject which is populated after the object is saved.
createdAt
Date The Date and time when the object was saved in the database.
updatedAt
Date The Date and time when the object was updated in the database.
isSearchable
boolean Set this to true if you want this object to be indexe for search and is accessible with CloudSearch
ACL
ACL Access Control List, by defualt this object is publicily readbale and writable. You set object leevel security here. Refer ACL's
/* *creates an object for Student table *all the CloudBoost functionality. */ CloudObject obj = new CloudObject("Student");
 

CloudObject.set( columnName, data )

Sets the value of an attribute of a CloudObject object.

Arguments
columnName
string The name of the column whose value is to be set.
data
Any dataThe value which is to be stored in the column.
Returns

void

CloudObject obj = new CloudObject("Student"); //create a new object. obj.set("name", "John Smith"); //store string obj.set("age", 21); // store number Map<String, Object> address = new HashMap<String,Object>(); address.put("city","Hyderabad"); address.put("state", "Telangana"); address.put("country","India"); address.put("zip", 500046); obj.set("address",address);
 

CloudObject.get( columnName )

Gets the value of an column of an instance of CloudObject object.

Argument
columnName
string The name of the column whose value is to be fetched.
Returns

It returns undefined if the attribute is not set previously otherwise returns the value of column which was previously set. Type of the value is an Object type which can be cast to an aproperiate data type

Map<String,Object> getAddressObject = new HashMap<String,Object>(); getAddressObject = (Map<String, Object>)obj.get("address"); //get the data. address will be a Map Object String city = (String)getAddressObject.get("city"); String state = (String)getAddressObject.get("state"); which was saved using object.set String name = (String)obj.get("name");
 

CloudObject.unset( columnName, [callback] )

Sets the value of an column of a CloudObject object to null.

Argument
columnName
string The name of the column which is to be unset.
Returns

void

CloudObject obj = new CloudObject("Student"); obj.set("name", "John Smith"); obj.get("name"); //returns John Smith. obj.unset("name"); obj.get("name"); //returns null.
 

CloudObject.save()

Saves the CloudObject object to CloudBoost.

Argument
callback
Callback interface object Override the success and error method. both method do not take any argument.
Error Handling

It throws CloudBoostException

CloudObject obj = new CloudObject("Student"); obj.set("name", "Smith"); CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject x,CloudException e){ // } }; obj.save(callbackObj);
 

CloudObject.fetch()

Refreshes a CloudObject object to by fetching its values from the database.

Error Handling

It throws CloudBoostException

CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject x,CloudException e){ // } }; obj.fetch(callbackObj);
 

CloudObject.delete()

Delete a CloudObject object, if it is saved in the database.

Error Handling

It throws CloudBoostException

CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject x,CloudException e){ // } }; obj.delete(callbackObj);
 

CloudObject.isSearchable

Indexes CloudObject for search using CloudSearch.

CloudObject obj = new CloudObject('Student'); obj.set("name", "John Smith"); obj.setIsSearchable(true); //index this object for Search
 

CloudObject.on( tableName, eventType, functionToFire)

Realtime Notifications : Listens to CloudObject events like insert, update, delete in the database.

Argument
tableName
String Name of the table on which you want to listen for events. respective response.
eventType
String / Array Type of an event you want to listen to, Only created, updated, deleted are supported values.
functiontoFire
Function Your custom function to fire when the event occours
Returns

void

//listen to an event //intializing CloudNotificationMethod, and overriding methods CloudNotificationCallback callbackObj = new CloudNotificationCallback(){ @Override public void done(Object data,CloudException e) { // override this function as per your requirnment. System.out.println("message : " + data); } }; CloudObject.on("Student", "created", callbackObj);
 

CloudObject.off( tableName, eventType )

Realtime Notifications : Switches off listening to CloudObject events like insert, update, delete in the database.

Argument
tableName
String Name of the table on which you want to stop listening for events to. respective response.
eventType
String / Array Type of an event you want to stop listening to, Only created, updated, deleted are supported values.
Returns

void

//stop listening to an event CloudObject.off("Student","created");
 

CloudObject.expires

Sets the expiration time for CloudObject. Expiration time is to be given as number of milliseconds from 1 Jan 1970.

CloudObject obj = new CloudObject("Student"); obj.set("name", "John Smith"); Date date = new Date(2015, 12, 25); expire = date.getTime()+1000; obj.setExpires(expires); //Set the expire time for object Student
 

Relationships

This section is dedicated to modelling relationships with CloudBoost.

There are usually three types of relationships.

  • One-to-One Relationship
  • One-to-many Relationship
  • Many-to-many Relationship

 

One-to-One Relationship

If you want to model one-to-one relationship. Then you need to create a new column of type Relation pointed to a table which you want it to be related to and set that column Unique property to true.

CloudObject student = new CloudObject("Student"); CloudObject address = new CloudObject("Address"); /* *here one student can only have one address for example. *address column of Student Table is pointed to the Address Table with unique set to true. */ student.set("address", address); CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; obj.save(callbackObj);
 

One-to-Many Relationship

If you want to model one-to-many relationship. Then you need to create a new column of type Relation pointed to a table which you want it to be related to and set that column Unique property to false.

CloudObject teacher = new CloudObject("Teacher"); CloudObject course = new CloudObject("Course"); /* *here one teacher be assigned to many courses. *address column of Student Table is pointed to the Address Table with unique set to true. */ course.set("teacher", address); CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; obj.save(callbackObj);
 

Many-to-Many Relationship

If you want to model many-to-many relationship. Then you have two options

  1. #1 - Relation Option
  2. #2 - List Option
We will discuss both of these options below.


Relation Option

This option is recommended only if you have huge number of relationships assigned to any one object.

This relationship can be created by creating a third table and having two columns that are relatied to tables you want to have many to many relationships on.









List Option

This option is recommended only if you have small number of relationships assigned to any one object.

This relationship can be created by creating an array and having related objects pushed to that array and having that array saved in any column of the table.

//Type #1 : Relation Option CloudObject student = new CloudObject("Student"); CloudObject course = new CloudObject("Course"); //here one student be into many courses, and vice versa. CloudObject studentCourse = new CloudObject('StudentCourse'); studentCourse.set("student", student); studentCourse.set("teacher", teacher); CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; obj.save(callbackObj); // ====================================================== //Type #2 : List Option. CloudObject student = new CloudObject("Student"); //create an array. ArrayList courseList = []; //a new course CloudObject course = new CloudObject("Course"); //add it to the list. You can push any number of objects you need. courseList.add(course); //here one student be into many courses, and vice versa. student.set("courses", courseList); CloudObjectCallback callbackObj = new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; obj.save(callbackObj);
 

CloudQuery

It encapsulates a set of methods and attributes required to query your data in CloudApp to retrieve desired set of results.

 

Package

import io.cloudboost.CloudQuery;

Constructor

Instantiates a CloudQuery object.

Argument
tableName
string The name of the table you want to query on.
Returns

void

CloudQuery query = new CloudQuery("Student");
 

CloudQuery.equalTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName is equal to data.

Arguments
columnName
string The column on which the contraint is to be applied
data
AnythingThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.equalTo("age", 21); //find all Students who age is 21 query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.containedIn( columnName, data )

If you want to retrieve objects matching several different values, you can use containedIn, providing an array of acceptable values. This is often useful to replace multiple queries with a single query.

Arguments
columnName
string The name of the column whose value is to be checked
data
String, Integer, Double, String Array, Integer Array, Double Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); //Get Student where name is equal to Smith, Max or Lucy String[] list = {"Smith", "Max", "Lucy"}; query.containedIn("name", list); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.containsAll( columnName, data )

Find objects where the array data in columnName contains all of the elements of data.

Arguments
columnName
string The name of the column whose value is to be checked
data
String, Integer, Double, String Array, Integer Array, Double Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); //find Students who are in JavaScript and C# class String[] list = {"java", "javascript"}; query.containsAll("classes", list); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.startsWith( columnName, data )

It adds a contriant to find the data in which value of columnName of each data is starts with data.

Arguments
columnName
string The name of the column whose value is to be checked
data
string The value that is to be checked with.
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); //find all the Students who name starts with letter 'S' query.startsWith("name", "S"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.notEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName does not has the value data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
AnythingThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); //find all Students info except of Smith query.notEqualTo("name", "Smith"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.notContainedIn( columnName, data )

If you want to retrieve objects which doesnot include several different values, you can use notContainedIn, providing an array of acceptable values. This is often useful to replace multiple queries with a single query.

Arguments
columnName
string The name of the column whose value is to be checked
data
Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); //Get all Students except Smith, Max and Lucy String[] list = {"Smith", "Max", "Lucy"}; query.notContainedIn("name", list); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.greaterThan( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value greater than data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string / numberThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Teacher"); //find all the teachers who are old. query.greaterThan("age", 60); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.greaterThanEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value greater than or equals to data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string / numberThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Teacher"); query.greaterThanEqualTo("age", 60); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.lessThan( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value less than data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string/numberThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.lessThan("age", 18); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.lessThanEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value less than or equals to data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string/numberThe value of the equals contraint
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.lessThanEqualTo("age", 17); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.or( query1, query2 )

It adds a logical OR contriant between 2 CloudQuery objects for finding the set of the data satisfying conditions of both query1 and query2.

Both of the CloudQuery objects should be of the same collection otherwise it throws an error.

Arguments
query1
CloudQuery object
query2
CloudQuery object
Returns

It returns a CloudQuery object which contains OR'ed query of both of the CloudQuery objects.

//find all Student such that 10<age<18 CloudQuery query1 = new CloudQuery('Student'); query1.lessThan("age", 18); CloudQuery query2 = new CloudQuery('Student'); query2.greaterThan("age", 10); CloudQuery query = CloudQuery.or(query1, query2); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.orderByAsc( columnName )

It adds a contriant for arranging the subset of the data in ascending order.

Argument
columnName
string The attribute on which the contraint is to be applied
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.orderByAsc("age"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.orderByDesc( columnName )

It adds a contriant for arranging the subset of the data in descending order.

Argument
columnName
string The attribute on which the contraint is to be applied
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.orderByDesc("age"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.setLimit( data )

It adds a contriant to limit no. of the data to be fetched from the database.

If it is not set explicitly, database returns 20 results by default.

Argument
data
number No. of data to be shown
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.setLimit(5); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.setSkip( data )

It adds a constraint to skip data no. of data matching satisfying the query contraints and fetching from the database.

It requires a sort contriant and if none of it is provided by the user then the documents are sorted according to the createdAt attribute associated with the data.

Argument
data
number No. of data to be skipped
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.setSkip(5); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.selectColumn( columnNames )

It adds a contriant limiting the columns that are to fetched for each of the data from the database.

id, createdAt, updatedAt and ACL are always returned unless explicitly provided by the user to discard it using doNotSelectColumn()

Argument
columnNames
string/Object/Array The name of the column(s) that are to be returned
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); String[] list = {"name", "age"}; query.selectColumn(list); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.doNotSelectColumn( columnNames )

It adds a contriant restricting the columns given in columnNames to be fetched for each of the data from the database.

Argument
columnNames
string/Object/Array The name of the column(s) that are not to be returned
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.greaterThan("age", 18); query.doNotSelectColumn("address"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.exists( columnName )

It adds a contriant for finding the subset of the data in which columnName exists irrespective of what its value is.

Argument
columnName
string The column name which is to be checked for existence
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.exists("address"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.doesNotExists( columnName )

It adds a contriant for finding the subset of the data in which columnName does not exists.

Argument
columnName
string The column name which is to be checked for non-existence
Returns

Same query object, which can be helpful in chaining query functions.

CloudQuery query = new CloudQuery("Student"); query.doesNotExists("address"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.find( )

Queries the database on the constraints provided by the CloudQuery object and gets the result as an array of CloudObject objects.

If no. of documents to be returned is not specified using limit() then at max 20 documents are returned in each query by default.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Returns

It returns an array of CloudObject objects.

Error Handling
It throws CloudBoostException, MalformedURLException, IOException
CloudQuery query = new CloudQuery("Student"); query.find(new CloudQueryCallback(){ @Override public void done(CloudObject[] obj,CloudException e) { // } });
 

CloudQuery.findOne( )

Queries the database on the constraints provided by the CloudQuery object and gets a single CloudObject object satisfying the constraint.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Returns

It returns a CloudObject object or an error object if the opertion is successful.It throws an error too if sufficient data is not available to query the database.

Error Handling
It throws CloudBoostException, MalformedURLException, IOException
CloudQuery query = new CloudQuery("Student"); query.exists("address"); query.findOne(new CloudQueryCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

CloudQuery.get( id )

Queries the database gets a CloudObject object whose id field matches id.

Arguments
id
string The ID of the data which is to be matched with _id field in the database.
Returns

It returns a CloudObject object or an error object if the operation is successful. It throws an error too if sufficient data is not available to query the database.

//retrieve a Student detail by his unique ID query.get("54e837d6d51a5ea011aa79ea", new CloudObjectCallback({ @Override public void done(CloudObject obj,CloudException e) { // } ));
 

CloudQuery.count( )

It adds a contriant to find the data in which value of columnName of each data is at least equal to all of the value(s) provided in data.

Returns

It returns an Integer which is the number of documents matching the constraints given in the CloudQuery.

//fetch how many Students are there who age>18 query.greaterThan(18); query.count(new CloudIntegerCallback( @Override public void done(Integer count,CloudException e) { // }) );
 

CloudQuery.distinct( columnName )

It returns distinct objects which have columnName

Sort parameter is required and if not provided by the user ascending order sorting on createdAt field is applied by default.

Argument
columnName
String The column name which should have distinct values in the returned data set.
Returns

It returns an array of CloudObject objects which are documents matching the given query in the CloudQuery object having distinct values of ColumnName

query.distinct("address",new CloudQuery1Callback( @Override public void done(CloudObject[] obj,CloudException e) { // } ));
 

CloudQuery.paginate( pageNo,totalItemsPerPage,callback )

Paginate returns only the specified number of objects from the database. It takes in the current page number and total items in page as parameters and returns list of objects,count,total number of pages.

Argument
pageNo
The page from which to count records to return
totalItemsPerPage
How many items will appear on each page whenever we paginate
Returns

Paginate returns only the specified number of objects from the database

query.paginate(1, null, new PaginatorCallback() { @Override public void done(CloudObject[] objects, Integer count, Integer totalPages, CloudException t) throws CloudException { if(t!=null) // else // } });
 

CloudNotifcations

In Cloudboost, you can create realtime notification channels, publish messages to those channels and have other clients listen to those messages which are being published in real time.

 

CloudNotification.on( channelName, functionToFire )

Listens to notification channels.

Package

import com.cloudboost.CloudNotification;

Arguments
channelName
Stringchannel to listen to.
functionToFire
function function to fire when data on this channel is published.
Returns

void

Error Handling

It throws CloudBoostException

//intializing CloudNotificationMethod, and overriding methods CloudNotificationCallback cloudNotificationMethodObject = new CloudNotificationCallback(){ @Override public void done(Object data,CloudException e) { // override this function as per your requirnment. System.out.println("message : " + data); } }; CloudNotification.on("sample", cloudNotificationMethodObj);
 

CloudNotification.publish( channelName, data )

Publishes data to notification channels.

Arguments
channelName
Stringchannel to publish to.
data
Anything data you want to publish to this channel
Returns

void

Error Handling

It throws CloudBoostException

CloudNotification.publish("sample","data");
 

CloudNotification.off( channelName, functionToFire )

Stops listening to notification channels.

Arguments
channelName
Stringchannel to stop listening to.
Returns

void

Error Handling

It throws CloudBoostException

//intializing CloudNotificationMethod, and overriding methods CloudNotificationCallback cloudNotificationMethodObject = new CloudNotificationCallback(){ @Override public void done(Object data,CloudException e) { // override this function as per your requirnment. System.out.println("Unsubscribed"); } }; CloudNotification.off("sample", cloudNotificationMethodObj);
 

CloudSearch

It encapsulates a set of methods and attributes required to perform search on your data in CloudApp to retrieve desired set of relevant results.

 

Constructor

Instantiates a CloudSearch object.

Package

import com.cloudboost.CloudSearch;

Argument
tableNames
Array/string The name of the table(s) you want to search on.
CloudSearch cs = new CloudSearch("Student");
 

CloudSearch.searchOn( columnName, query )

Used to perform a search query.

Arguments
columnName
string / Array The column on which the contraint is to be applied
data
queryA text query
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

String[] list = {"C++", "Java", "C#"}; CloudSearch cs = new CloudSearch("Student"); cs.searchOn("resume", list); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.equalTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName is equal to data.

Arguments
columnName
string The column on which the contraint is to be applied
data
AnythingThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.equalTo("age", 21); //find all Students who age is 21 CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.notEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName does not has the value data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
AnythingThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining query functions.

CloudSearch cs = new CloudSearch("Student"); //find all Students info except of Smith cs.notEqualTo("name", "Smith"); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.greaterThan( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value greater than data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string / numberThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Teacher"); //find all the teachers who are old. cs.greaterThan("age", 60); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.greaterThanEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value greater than or equals to data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string / numberThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Teacher"); cs.greaterThanEqualTo("age", 60); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.lessThan( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value less than data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string/numberThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.lessThan("age", 18); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.lessThanEqualTo( columnName, data )

It adds a contriant for finding the subset of the data in which columnName has the value less than or equals to data.

Arguments
columnName
string The attribute on which the contraint is to be applied
data
string/numberThe value of the equals contraint
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.lessThanEqualTo("age", 17); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.or( cloudSearch1, cloudSearch2 )

It adds a logical OR contriant between 2 CloudSearch objects for finding the set of the data satisfying conditions of both cloudSearch1 and cloudSearch2.

Arguments
cloudSearch1
CloudSearch object
cloudSearch2
CloudSearch object
Returns

It returns a CloudSearch object which contains OR'ed query of both of the CloudSearch objects.

//find all Student such that 10<age<18 CloudSearch cs1 = new CloudSearch("Student"); cs1.lessThan("age", 18); cs1.searchOn("name", "Sam"); CloudSearch cs2 = new CloudSearch("Student"); cs2.greaterThan("age", 10); cs1.searchOn("name", "Dan"); CloudSearch cs = CloudSearch.or(cs1, cs2); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.orderByAsc( columnName )

It adds a contriant for arranging the subset of the data in ascending order.

Argument
columnName
string The attribute on which the contraint is to be applied
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.orderByAsc("age"); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.orderByDesc( columnName )

It adds a contriant for arranging the subset of the data in descending order.

Argument
columnName
string The attribute on which the contraint is to be applied
Returns

Same search object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.orderByDesc('age'); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.setLimit( data )

It adds a contriant to limit no. of the data to be fetched from the database.

If it is not set explicitly, database returns 20 results by default.

Argument
data
number No. of data to be shown
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.setLimit(5); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.setSkip( data )

It adds a constraint to skip data no. of data matching satisfying the query contraints and fetching from the database.

Argument
data
number No. of data to be skipped
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.setSkip(5); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.exists( columnName )

It adds a contriant for finding the subset of the data in which columnName exists irrespective of what its value is.

Argument
columnName
string The column name which is to be checked for existence
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.exists("address"); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.doesNotExists( columnName )

It adds a contriant for finding the subset of the data in which columnName does not exists.

Argument
columnName
string The column name which is to be checked for non-existence
Returns

Same CloudSearch object, which can be helpful in chaining search functions.

CloudSearch cs = new CloudSearch("Student"); cs.doesNotExists("address"); CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

CloudSearch.search([callback] )

Searches the database on the constraints provided by the CloudSearch object and gets the result as an array of CloudObject objects.

If no. of documents to be returned is not specified using limit() then at max 20 documents are returned in each query by default.

Argument
callback
CloudSearchCallback interface object must override success(Map<String, Object >) method and error method
Returns

It returns an array of CloudObject objects.

Error Handling
It throws CloudBoostException, MalformedURLException, IOException
Map<String, Object > list; //without callback list = cs.search(); //with callback CloudSearchCallback callbackObj = new CloudSearchCallback(){ @Override public void done(CloudObject[] list,CloudException e) { // } }; cs.search(callbackObj);
 

ACL

Each CloudObject namespace has security option by default. By default every object can be read and modified by anyone so for each object change the security option as desidred. For any object, you can specify which users/roles are allowed to read the object, and which users/roles are allowed to modify an object. To support this type of security, each object has an access control list, implemented by the ACL class.

For each object ACL object is a property in CloudObject.ACL class.

All the modifications in the ACL can be reflected only after the object is saved after the changes.

 

Constructor

Instantiates an ACL object.

Package

import com.cloudboost.ACL;

Argument

It takes no argument

Returns

It returns nothing. It is called using a variable of which various parameters are set.

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL();
 

ACL.setPublicWriteAccess( value )

To allow/disallow public to write on a particular CloudObject

Argument
value
boolean
Returns

void

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setPublicWriteAccess(false); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

ACL.setPublicReadAccess( value )

To allow/disallow public to read a particular object

Argument
value
boolean
Returns

void

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setPublicReadAccess(false); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

ACL.setUserWriteAccess( userId, value )

To allow/disallow user having to write on a particular object.

Argument
userId
string The User ID of the user you want to set the access for
value
boolean
Returns

void

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setUserWriteAccess("idOfTheUser",true); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

ACL.setUserReadAccess( userId, value )

To allow/disallow user having _id userId to read a particular object.

Argument
userId
string The user ID of the user you want to set the access for
value
boolean
Returns

It returns nothing.

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setUserReadAccess("idOfTheUser",true); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

ACL.setRoleWriteAccess( roleId, value )

To allow/disallow users of roles roleId to write on a particular object

Argument
roleId
string The role ID of the Role you want to set the access for
value
boolean
Returns

void

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setRoleWriteAccess("roleId", true); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

ACL.setRoleReadAccess( roleId, value )

To allow/disallow users of roles roleId to read a particular object

Argument
roleId
string The role ID of the Role you want to set the access for
value
boolean
Returns

void

CloudObject obj = new CloudObject("Student"); obj.acl = new ACL(); obj.acl.setWriteAccess("roleId", true); obj.save(new CloudObjectCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } });
 

CloudUser

There is a notion of user accounts that lets users access their information in a secure manner. We provide a specialized user class called CloudUser that automatically handles much of the functionality required for user account management.

CloudUser is a subclass of CloudObject, and has all the same features, such as flexible schema, automatic persistence, and a key value interface. All the methods that are on CloudObject also exist in CloudUser. The difference is that CloudUser has some special additions specific to user accounts. With this class, you'll be able to add user account functionality in your app.

There is a special object CloudUser.current which holds the information of the current user logged in.

 

Constructor

Instantiates a CloudUser object.

Package

import com.cloudboost.CloudUser;

Argument

It takes no argument.

CloudUser obj = new CloudUser();
 

CloudUser.signUp( )

It registers new user given its username, email and password. Registration is successful if the given email is not already registered to an existing user.

It sets the attributes of CloudUser.current object with the CloudUser object recieved.

Returns

It returns a CloudUser object which has the user information if registration is successful.

Error Handling
It throws CloudBoostException
CloudUser user = new CloudUser(); user.set("username", "my_username"); user.set("password", "my_solid_password"); user.set("email", "[email protected]"); user.signUp();
 

CloudUser.logIn( )

It logs in user given its username and password. Login is successful if the given username and password pair is already present in the database.

It sets the attributes of CloudUser.current object with the CloudUser object recieved.

Returns

It returns a CloudUser object which has the user information if registration is successful.

Error Handling
It throws CloudBoostException
CloudUser user = new CloudUser(); user.set("username", "my_username"); user.set("password", "my_solid_password"); CloudUserCallback callbackObj = new CloudUserCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; user.logIn(callbackObj);
 

CloudUser.logOut( )

It logs the user out.

It sets the CloudUser.current object to null.

Returns

It returns a CloudUser object having the user information of the user who was logged in.

Error Handling
It throws CloudBoostException
CloudUserCallback callbackObj = new CloudUserCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; CloudUser.getCurrent().logOut(callbackObj);
 

CloudUser.getCurrent( )

Get the current logged in user.

//gets the current user if user is loggedIn, null otherwise. CloudUser currentUser = CloudUser.getCurrent();
 

CloudUser.addToRole( role )

A user can be a part of many roles, like in real world. For this functionality user should get added to a Role.

For this purpose addToRole() of CloudUser comes in handy.

Arguments
role
CloudRole Object The CloudRole object of the role you want to add the user to.
Returns

It returns a CloudUser object having the user information of the user who was logged in.

Error Handling
It throws CloudBoostExceptionn
CloudUserCallback callbackObj = new CloudUserCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; //role is an instance of CloudRole Object. CloudUser.getCurrent().addToRole(role,callbackObj);

Given getRole() is discussed later

 

CloudUser.isInRole( role )

To check if the current user is in the role provided by the role object.

Argument
role
CloudRole Object The CloudRole object of the role you want to check the user to.
Returns

It returns a true/false based on whether the user is in the given role or not respectively.

Error Handling
It throws CloudBoostException
//role is the instance of the CloudRole object. if(CloudUser.getCurrent().isInRole(role)) { //The current user is in the given role. } else { //The user is not in the given role. } }

Given getRole() is discussed later

 

CloudUser.removeFromRole( role )

Removes the user from the given role provided in role object.

Argument
role
CloudRole Object The CloudRole object of the role you want to remove the user from.
Returns

It returns a CloudUser object having the user information of the user who was logged in.

Error Handling
It throws CloudBoostException
CloudUserCallback callbackObj = new CloudUserCallback(){ @Override public void done(CloudObject obj,CloudException e) { // } }; //role is an instance of CloudRole Object. CloudUser.getCurrent().removeFromRole(role,callbackObj);

Given getRole() is discussed later

 

CloudUser.changePassword( )

To change the password of a user you need to call the changePassword function of the CB.CloudUser instance. Before you call the changePassword function make sure the current user is loggedIn and the current session is valid. Please note : Calling change password will not log the user out of its current session.

CloudUser.getCurrentUser().changePassword("oldPassword","newPassword", new CloudUserCallback(){ @Override public void done(CloudUser user,CloudException e){ if(user!=null) //user if(e!=null) //e } });
 

CloudUser.resetPassword( )

To reset the password of a user you need to call the resetPassword function of the CB.CloudUser class. Reset Password takes in an email of the user as first parameter and callback as second parameter. CloudBoost automatically takes care of emailing the user with password reset link. Please note : If you want to change the format the email which CloudBoost sends by default. You can head over to your CloudBoost App Dashboard and change the email settings of an app.

CloudUser.resetPassword("email",new CloudStringCallback(){ @Override public void done(String msg,CloudException e){ if(msg!=null) //reset password email sent if(e!=null) //e } });
 

CloudRole

As your app grows in scope and user-base, you may find yourself needing more coarse-grained control over access to pieces of your data than user-linked ACLs can provide. To address this requirement, CloudBoost supports a form of Role-based Access Control. Roles provide a logical way of grouping users with common access privileges to your CB data. Roles are named objects that contain users and other roles. Any permission granted to a role is implicitly granted to its users as well as to the users of any roles that it contains.

We provide a specialized class called CloudRole that represents these role objects in your client code. CloudRole is a subclass of CloudObject, and has all of the same features, such as a flexible schema, automatic persistence, and a key value interface. All the methods that are on CloudObject also exist on CloudRole. The difference is that CB.CloudRole has some additions specific to management of roles.

 

Constructor

Instantiates a CloudRole object.

Package

import com.cloudboost.CloudRole;

Argument
roleName
string The name of the role you want to deal with
CloudRole role = new CloudRole("Student");
 

CloudRole.getRole( role )

Gets a CloudRole object for a given role object with name field only.

Argument
role
CloudRole object The name of the role you want to deal with
Returns
It returns a CloudRole object having the role information of the role whose name was provided in the object of role argument.
CloudRole role = new CloudRole("my-collaborator"); CloudRole.getRole(new CloudRoleCallback(){ @Override public void done(CloudRole obj,CloudException e){ // } });
 

CloudPush

Push notifications are a very important feature in an android app because it enables seamless communication from your server to your app. In this case your server will be CloudBoost Push notification server.

Not that CloudBoost server uses Google Cloud Messaging to reach your app. So before you start using this feature, ensure that you have created a project for your app on google developer console and obtained credentials like senderID/Project_number and ApiKey.

 

Constructor

Instantiates a CloudPush object.

Package

import io.cloudboost.CloudPush;

Argument
CloudPush push = new CloudPush();
 

CloudPush.addDevice( token,timezone,[channels],callback )

Adds a GCM registered device to your app on CloudBoost so that it can start receiving push messages. However, if you initialise your CloudBoost app as discussed in this demo, then you will have all your devices auto-registered to GCM and the CloudApp by the JavaSDK.

Argument
token
The registrationID you got from GCM's InstanceID API
timezone
An arbitrary string representing your timezone
[channels]
An array of channels you would like to subscribe to upfront. You can still subscribe and unsubscribe from any channel later
Returns
It returns a CloudObject object having the Device information..
String[] channels={"hackers","crackers"}; CloudPush.addDevice([deviceToken],[Timezone as String], channels, new CloudObjectCallback() { @Override public void done(CloudObject x, CloudException t) throws CloudException { // } });
 

CloudPush.subscribe( channel,deviceToken,callback )

This API is used to subscribe a device running your app to a given channel in your CloudApp. If the channel is already subscribed to, you will get an exception stating this.

This method has an overloaded version which takes an array of channels

Argument
channels/channel
A String or an array of channels you'd like to subscribe to
deviceToken
A unique registrationID given to your app by GCM server on registering with the InstanceID API. It is expected that after submitting this data to your CloudApp via the addDevice API, you will keep a copy in sharedPreferences for such an operation
Returns
It returns a CloudObject, showing your new device data plus the new subscriptions.
CloudPush.subscribe("movers", "xxxxxxxxxxxx", new CloudObjectCallback() { @Override public void done(CloudObject x, CloudException t) throws CloudException { // } }); /* *Alternatively, you could specify *an array of channels to subscribe to */ String[] channels={"movers","shakers"}; CloudPush.subscribe(channels, "xxxxxxxxxxxx", new CloudObjectCallback() { @Override public void done(CloudObject x, CloudException t) throws CloudException { // } });
 

CloudPush.unSubscribe( channel,deviceToken,callback )

This API is used to unsubscribe a device running your app from a given channel in your CloudApp. If the channel is not already subscribed to, you will get an exception stating this.

This method has an overloaded version which takes an array of channels

Argument
channels/channel
A String or an array of channels you'd like to subscribe to
deviceToken
A unique registrationID given to your app by GCM server on registering with the InstanceID API. It is expected that after submitting this data to your CloudApp via the addDevice API, you will keep a copy in sharedPreferences for such an operation
Returns
It returns a CloudObject, showing your new device data plus the new subscriptions.
CloudPush.unSubscibe("movers", "xxxxxxxxxxxx", new CloudObjectCallback() { @Override public void done(CloudObject x, CloudException t) throws CloudException { // } }); /* *Alternatively, you could specify *an array of channels to unSubscibe from */ String[] channels={"movers","shakers"}; CloudPush.unSubscibe(channels, "xxxxxxxxxxxx", new CloudObjectCallback() { @Override public void done(CloudObject x, CloudException t) throws CloudException { // } });
 

CloudPush.send( pushData,query/channelArray/oneChannelString,callback )

This API is used to push a message to the devices running your application.

Argument
pushData
A simple POJO containing your message title and body
query
This argument is very dynamic. It can take a CloudQuery specifying which channels you are pushing the message to. It can also take a channel or a channel array and re-create for you a CloudQuery based on them to target specific channels
Returns
It returns a CloudPush Object.
//CloudPush.send with cloudquery String[] channels={"movers","shakers"}; CloudQuery query=new CloudQuery("Device"); query.containedIn("channels", channels); CloudPush.send(new PushData("title", "my message"), query, new CloudPushCallback() { @Override public void done(Object x, CloudException t) throws CloudException { // } }); //CloudPush.send with single channel CloudPush.send(new PushData("title", "my message"), "movers", new CloudPushCallback() { @Override public void done(Object x, CloudException t) throws CloudException { // } }); //CloudPush.send with Channel array String[] channels={"movers","shakers"}; CloudPush.send(new PushData("title", "my message"), channels, new CloudPushCallback() { @Override public void done(Object x, CloudException t) throws CloudException { // } }); /* *or instead of using PushData, you could pass only *a message or only a title and message */ CloudPush.send("message", channels, new CloudPushCallback() { @Override public void done(Object x, CloudException t) throws CloudException { // } }); //title and message CloudPush.send("message","title", channels, new CloudPushCallback() { @Override public void done(Object x, CloudException t) throws CloudException { // } });
 

Contribute

We heart contributors. Love what we do and want to contribute?
JavaScript SDK : GitHub Repository

Our documentation is open source too!

Documentation : GitHub Repository