diff --git a/ClearBlade.js b/ClearBlade.js
index 0fa0748..c9808f1 100644
--- a/ClearBlade.js
+++ b/ClearBlade.js
@@ -2169,14 +2169,40 @@ n *
{Number} [messagingPort] This is the default port used when connecting
return metrics;
};
+ /**
+ * Creates a representation of devices
+ * @class ClearBlade.Device
+ * @classdesc It does not actually make a connection upon instantiation, but has all the methods necessary to do so.
+ * @example
+ * var device = cb.Device();
+ */
ClearBlade.prototype.Device = function(){
- var device = {};
+ let device = {};
device.user = this.user;
device.URI = this.URI;
device.systemKey = this.systemKey;
device.systemSecret = this.systemSecret;
+ /**
+ * Requests the named device from Devices Auth table
+ * @method ClearBlade.Device.prototype.getDeviceByName
+ * @param {String} name Used to indicate which device to get
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} An object representing the requested device
+ * @example
Fetching data from device
+ * let returnedData = {};
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * } else {
+ * returnedData = data;
+ * }
+ * };
+ *
+ * device.updateDeviceByName(name, callback);
+ * //this will give returnedData the value of what ever was returned from the server.
+ */
device.getDeviceByName = function (name, callback) {
var reqOptions = {
method: 'GET',
@@ -2187,9 +2213,30 @@ n *
{Number} [messagingPort] This is the default port used when connecting
ClearBlade.request(reqOptions, callback);
};
- device.updateDevice = function (name, object, trigger, callback){
+ /**
+ * Updates a device in the Devices Auth table
+ * @method ClearBlade.Device.prototype.updateDevice
+ * @param {String} name Specifies which device to update
+ * @param {Object} object Supplies which columns in the Devices table to update
+ * @param {Boolean} trigger Indicates whether or not to enable trigger
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} A success attribute
+ * @example
Updating device data
+ * var object = {
+ * active_key: "example_active_key",
+ * allow_key_auth: false
+ * }
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * }
+ * };
+ *
+ * device.updateDevice(name, object, trigger, callback);
+ */
+ device.updateDevice = function (name, object, trigger, callback) {
if (typeof object != "object"){
- throw new Error('Invalid object format');
+ throw new Error('Invalid object format');
}
object["causeTrigger"] = trigger;
var reqOptions = {
@@ -2202,6 +2249,64 @@ n *
{Number} [messagingPort] This is the default port used when connecting
ClearBlade.request(reqOptions, callback);
};
+ /**
+ * Requests all devices defined within a system, unless query specifies one item or a set of items.
+ * @method ClearBlade.Device.prototype.fetch
+ * @param {Query} _query Used to request a specific item or subset of items from the devices on the server. Optional.
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} An array of JSON objects, whose attributes correspond to columns in the Devices tables
+ * @example
Fetching data from devices
+ * var returnedData = [];
+ * var query = ClearBlade.Query();
+ * query.equalTo('enabled', 'true');
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * } else {
+ * returnedData = data;
+ * }
+ * };
+ *
+ * device.fetch(query, callback);
+ * //this will give returnedData the value of what ever was returned from the server, every device whose "enabled" attribute is equal to "true".
+ */
+ device.fetch = function (_query, callback) {
+ let query;
+ /*
+ * The following logic may look funny, but it is intentional.
+ * I do this because it is typeical for the callback to be the last parameter.
+ * However, '_query' is an optional parameter, so I have to check if 'callback' is undefined
+ * in order to see weather or not _query is defined.
+ */
+ if (callback === undefined) {
+ callback = _query;
+ query = {
+ FILTERS: []
+ };
+ query = 'query='+ _parseQuery(query);
+ } else {
+ if (Object.keys(_query) < 1) {
+ query = '';
+ } else {
+ query = 'query='+ _parseQuery(_query.query);
+ }
+ }
+
+ var reqOptions = {
+ method: 'GET',
+ user: this.user,
+ endpoint: "api/v/2/devices/" + this.systemKey,
+ qs: query,
+ URI: this.URI
+ };
+
+ if (typeof callback === 'function') {
+ ClearBlade.request(reqOptions, callback);
+ } else {
+ logger("No callback was defined!");
+ }
+ };
+
return device;
};
diff --git a/out/ClearBlade.Analytics.html b/out/ClearBlade.Analytics.html
index 15c1fd7..f490474 100644
--- a/out/ClearBlade.Analytics.html
+++ b/out/ClearBlade.Analytics.html
@@ -28,11 +28,8 @@
This class represents a server-side collection. It does not actully make a connection upon instantiation, but has all the methods necessary to do so. It also has all the methods necessary to do operations on the server-side collections.
@@ -43,30 +40,33 @@
-
-
-
new Collection(collectionID)
-
-
-
+
Constructor
+
-
- Creates a new Collection that represents the server-side collection with the specified collection ID
-
+
new Collection(collectionID)
-
-
+
+ Creates a new Collection that represents the server-side collection with the specified collection ID
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -112,9 +112,10 @@
Parameters:
-
-
+
+
+
@@ -139,6 +140,8 @@
Parameters:
+
+
@@ -156,25 +159,26 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
var col = cb.Collection("12asd3049qwe834qe23asdf1234");
-
-
+
@@ -185,41 +189,44 @@
Example
-
+
-
Methods
-
-
-
-
create(newItem, callback)
+
Methods
+
+
-
-
-
- Creates a new item in the collection and returns the created item to the callback
-
+
create(newItem, callback)
-
-
+
+ Creates a new item in the collection and returns the created item to the callback
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -288,9 +295,10 @@
Parameters:
-
-
+
+
+
@@ -315,6 +323,8 @@
Parameters:
+
+
@@ -332,68 +342,70 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Creating a new item in the collection
//This example assumes a collection of items that have the columns: name, height, and age.
var newPerson = {
- name: 'Jim',
- height: 70,
- age: 32
+ name: 'Jim',
+ height: 70,
+ age: 32
};
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
col.create(newPerson, callback);
//this inserts the the newPerson item into the collection that col represents
+ Reqests an item or a set of items from the collection.
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -462,9 +474,10 @@
Parameters:
-
-
+
+
+
@@ -489,6 +502,8 @@
Parameters:
+
+
@@ -506,20 +521,20 @@
Parameters:
-
-
-
-
-
-
-
Returns:
-
-
+
+
+
+
+
+
+
Returns:
+
+
An array of ClearBlade Items
@@ -538,54 +553,56 @@
Returns:
-
+
+
+
+
+
Example
-
Example
-
Fetching data from a collection
var returnedData = [];
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- returnedData = data;
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ returnedData = data;
+ }
};
col.fetch(query, callback);
//this will give returnedData the value of what ever was returned from the server.
-
-
+
-
-
-
remove(_query, callback)
-
-
-
-
- Removes an item or set of items from the specified collection
-
+
remove(_query, callback)
-
-
+
+ Removes an item or set of items from the specified collection
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -654,9 +671,10 @@
Parameters:
-
-
+
+
+
@@ -681,6 +699,8 @@
Parameters:
+
+
@@ -698,66 +718,68 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Removing an item in a collection
//This example assumes that you have a collection with the item whose 'name' attribute is 'John'
var query = ClearBlade.Query();
query.equalTo('name', 'John');
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
col.remove(query, callback);
//removes every item whose 'name' attribute is equal to 'John'
-
-
+
-
-
-
update(_query, changes, callback)
-
-
-
-
- Updates an existing item or set of items
-
+
update(_query, changes, callback)
-
-
+
+ Updates an existing item or set of items
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -849,9 +871,10 @@
Parameters:
-
-
+
+
+
@@ -876,6 +899,8 @@
Parameters:
+
+
@@ -893,44 +918,45 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Updating a set of items
//This example assumes a collection of items that have the columns name and age.
var query = ClearBlade.Query();
query.equalTo('name', 'John');
var changes = {
- age: 23
+ age: 23
};
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
col.update(query, changes, callback);
//sets John's age to 23
+ An array of JSON objects, whose attributes correspond to columns in the Devices tables
+
+
+
+
+
+
+ Type
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
Example
+
+
Fetching data from devices
+
+
var returnedData = [];
+var query = ClearBlade.Query();
+query.equalTo('enabled', 'true');
+var callback = function (err, data) {
+ if (err) {
+ throw new Error (data);
+ } else {
+ returnedData = data;
+ }
+};
+
+device.fetch(query, callback);
+//this will give returnedData the value of what ever was returned from the server, every device whose "enabled" attribute is equal to "true".
+
+
+
+
+
+
+
+
+
+
getDeviceByName(name, callback) → {Object}
+
+
+
+
+
+
+
+ Requests the named device from Devices Auth table
+
+
+
+
+
+
+
+
+
+
+
Parameters:
+
+
+
+
+
+
+
Name
+
+
+
Type
+
+
+
+
+
+
Description
+
+
+
+
+
+
+
+
+
name
+
+
+
+
+
+String
+
+
+
+
+
+
+
+
+
+
Used to indicate which device to get
+
+
+
+
+
+
+
callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+
+
Supplies processing for what to do with the data that is returned from the devices
let returnedData = {};
+var callback = function (err, data) {
+ if (err) {
+ throw new Error (data);
+ } else {
+ returnedData = data;
+ }
+};
+
+device.updateDeviceByName(name, callback);
+//this will give returnedData the value of what ever was returned from the server.
- Initializes the ClearBlade messaging object and connects to a server.
-
+
new Messaging(options, callback)
-
-
+
+ Initializes the ClearBlade messaging object and connects to a server.
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -147,9 +145,10 @@
Parameters:
-
-
+
+
+
@@ -174,6 +173,8 @@
Parameters:
+
+
@@ -191,31 +192,32 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
A standard connect
var callback = function (data) {
- console.log(data);
+ console.log(data);
};
//A connect with a nonstandard timeout
var cb = ClearBlade.Messaging({"timeout":15}, callback);
-
-
+
@@ -226,41 +228,44 @@
Example
-
+
-
Methods
-
-
-
-
(static) getAndDeleteMessageHistory(topic, last, count, start, stop, callback)
+
Methods
+
+
-
-
-
- Gets the message history from a ClearBlade Messaging topic.
-
+
(static) getAndDeleteMessageHistory(topic, last, count, start, stop, callback)
-
-
+
+ Gets the message history from a ClearBlade Messaging topic.
+
var callback = function (data) {
- console.log(data);
+ console.log(data);
};
var cb = ClearBlade.Messaging({}, callback);
cb.publish("ClearBlade/is awesome!","Totally rules");
//Topics can include spaces and punctuation except "/"
- creates and returns a Query object that can be used in Collection methods or on its own to operate on items on the server
-
+
new Query(options) → {Object}
-
-
+
+ creates and returns a Query object that can be used in Collection methods or on its own to operate on items on the server
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -110,9 +108,10 @@
Parameters:
-
-
+
+
+
@@ -137,6 +136,8 @@
Parameters:
+
+
@@ -154,20 +155,20 @@
Parameters:
-
-
-
-
-
-
-
Returns:
-
-
+
+
+
+
+
+
+
Returns:
+
+
Clearblade.Query the created query
@@ -186,10 +187,11 @@
Returns:
-
-
-
+
+
+
+
@@ -200,41 +202,44 @@
Returns:
-
+
-
Methods
-
-
-
-
columns(Columns, callback)
+
Methods
+
+
-
-
-
- Gets rows of the specified columns
-
+
columns(Columns, callback)
-
-
+
+ Gets rows of the specified columns
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -303,9 +308,10 @@
Parameters:
-
-
+
+
+
@@ -330,6 +336,8 @@
Parameters:
+
+
@@ -347,66 +355,68 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Getting values of columns
//This example assumes a collection of items that have the columns name and age.
var query = ClearBlade.Query({'collectionName': 'COLLECTIONNAME'});
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
query.columns(["name","age"]);
query.fetch(callback);
//gets values in columns name and age
-
-
+
-
-
-
equalTo(field, value)
-
-
-
-
- Creates an equality clause in the query object
-
+
equalTo(field, value)
-
-
+
+ Creates an equality clause in the query object
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -475,9 +485,10 @@
Parameters:
-
-
+
+
+
@@ -502,6 +513,8 @@
Parameters:
+
+
@@ -519,57 +532,59 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Adding an equality clause to a query
var query = ClearBlade.Query();
query.equalTo('name', 'John');
//will only match if an item has an attribute 'name' that is equal to 'John'
Adding a greater than or equality clause to a query
+
+
var query = ClearBlade.Query();
query.greaterThanEqualTo('age', 21);
//will only match if an item has an attribute 'age' that is greater than or equal to 21
-
-
+
-
-
-
lessThan(field, value)
-
-
-
-
- Creates a less than clause in the query object
-
+
lessThan(field, value)
-
-
+
+ Creates a less than clause in the query object
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1129,9 +1159,10 @@
Parameters:
-
-
+
+
+
@@ -1156,6 +1187,8 @@
Parameters:
+
+
@@ -1173,56 +1206,58 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Adding a less than clause to a query
var query = ClearBlade.Query();
query.lessThan('age', 50);
//will only match if an item has an attribute 'age' that is less than 50
-
-
+
-
-
-
lessThanEqualTo(field, value)
-
-
-
-
- Creates a less than or equality clause in the query object
-
+
lessThanEqualTo(field, value)
-
-
+
+ Creates a less than or equality clause in the query object
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1291,9 +1326,10 @@
Parameters:
-
-
+
+
+
@@ -1318,6 +1354,8 @@
Parameters:
+
+
@@ -1335,56 +1373,58 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Adding a less than or equality clause to a query
var query = ClearBlade.Query();
query.lessThanEqualTo('age', 50);
//will only match if an item has an attribute 'age' that is less than or equal to 50
-
-
+
-
-
-
matches(field, pattern)
-
-
-
-
- Creates an regular expression matching clause in the query object
-
+
matches(field, pattern)
-
-
+
+ Creates an regular expression matching clause in the query object
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1453,9 +1493,10 @@
Parameters:
-
-
+
+
+
@@ -1480,6 +1521,8 @@
Parameters:
+
+
@@ -1497,56 +1540,58 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Adding an regex matching clause to a query
var query = ClearBlade.Query();
query.matches('name', 'Smith$');
//will only match if an item has an attribute 'name' that That ends in 'Smith'
-
-
+
-
-
-
notEqualTo(field, value)
-
-
-
-
- Creates a not equal clause in the query object
-
+
notEqualTo(field, value)
-
-
+
+ Creates a not equal clause in the query object
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1615,9 +1660,10 @@
Parameters:
-
-
+
+
+
@@ -1642,6 +1688,8 @@
Parameters:
+
+
@@ -1659,56 +1707,58 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Adding a not equal clause to a query
var query = ClearBlade.Query();
query.notEqualTo('name', 'Jim');
//will only match if an item has an attribute 'name' that is not equal to 'Jim'
-
-
+
-
-
-
or(that)
-
-
-
-
- chains an existing query object to the Query object in an or
-
+
or(that)
-
-
+
+ chains an existing query object to the Query object in an or
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1754,9 +1804,10 @@
Parameters:
-
-
+
+
+
@@ -1781,6 +1832,8 @@
Parameters:
+
+
@@ -1798,21 +1851,23 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Chaining two queries together in an or
var query1 = ClearBlade.Query();
@@ -1822,35 +1877,35 @@
Example
query1.or(query2);
//will match if an item has an attribute 'name' that is equal to 'John' or 'Jim'
-
-
+
-
-
-
remove(callback)
-
-
-
-
- Removes an item or set of items from the Query
-
+
remove(callback)
-
-
+
+ Removes an item or set of items from the Query
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -1896,9 +1951,10 @@
Parameters:
-
-
+
+
+
@@ -1923,6 +1979,8 @@
Parameters:
+
+
@@ -1940,66 +1998,68 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Removing an item in a collection
//This example assumes that you have a collection with the item whose 'name' attribute is 'John'
var query = ClearBlade.Query({'collection': 'COLLECTIONID'});
query.equalTo('name', 'John');
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
query.remove(callback);
//removes every item whose 'name' attribute is equal to 'John'
-
-
+
-
-
-
setPage(pageSize, pageNum)
-
-
-
-
- Set the pagination options for a Query.
-
+
setPage(pageSize, pageNum)
-
-
+
+ Set the pagination options for a Query.
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -2070,9 +2130,10 @@
Parameters:
-
-
+
+
+
@@ -2097,6 +2158,8 @@
Parameters:
+
+
@@ -2114,48 +2177,50 @@
Parameters:
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
update(changes, callback)
-
-
-
-
- Updates an existing item or set of items. Requires that a collection was
-set when the Query was initialized.
-
+
update(changes, callback)
-
-
+
+ Updates an existing item or set of items. Requires that a collection was
+set when the Query was initialized.
+
+
+
+
+
+
+
+
+
+
+
Parameters:
-
Parameters:
-
@@ -2224,9 +2289,10 @@
Parameters:
-
-
+
+
+
@@ -2251,6 +2317,8 @@
Parameters:
+
+
@@ -2268,44 +2336,45 @@
Parameters:
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
Example
-
Example
-
Updating a set of items
//This example assumes a collection of items that have the columns name and age.
var query = ClearBlade.Query({'collection': 'COLLECTIONID'});
query.equalTo('name', 'John');
var changes = {
- age: 23
+ age: 23
};
var callback = function (err, data) {
- if (err) {
- throw new Error (data);
- } else {
- console.log(data);
- }
+ if (err) {
+ throw new Error (data);
+ } else {
+ console.log(data);
+ }
};
query.update(changes, callback);
//sets John's age to 23
*/
ClearBlade.prototype._callTimeout = options.callTimeout;
this._callTimeout = options.callTimeout || 30000; //default to 30 seconds
- /**
- * This property tells us which port to use for websocket mqtt auth.
- * @property messagingAuthPort
- * @type Number
- */
+ /**
+ * This property tells us which port to use for websocket mqtt auth.
+ * @property messagingAuthPort
+ * @type Number
+ */
this.messagingAuthPort = options.messagingAuthPort || 8907;
this.user = null;
@@ -484,8 +484,8 @@
Source: ClearBlade.js
var usrid = getString(body);
body = body.substring(usrid.length+2);
var msgingHost = getString(body);
- _this.setUser(email,tok);
- _this.messagingURI = msgingHost;
+ _this.setUser(email,tok.substring(2, tok.length) + "=="); // first 2 bytes are length
+ // _this.messagingURI = msgingHost; // We will add this back once the backend is fixed. Right now its always "messaging.clearblade.com"
success = true;
client.disconnect();
callback(false,_this.user);
@@ -1735,7 +1735,6 @@
* @param {function} callback The function to be called upon execution of query -- called with a boolean error and the response
*/
messaging.getMessageHistory = function(topic, last, count, callback) {
- messaging.getMessageHistoryWithTimeFrame(topic, count, last, -1, -1);
+ messaging.getMessageHistoryWithTimeFrame(topic, count, last, -1, -1, callback);
};
/**
@@ -2100,10 +2099,10 @@
Source: ClearBlade.js
ClearBlade.request(reqOptions, callback);
};
- /**
- * Gets an array of Edges on the system.
- * @method ClearBlade.getEdges
- * @param {function} callback A function like `function (err, data) {}` to handle the response
+ /**
+ * Gets an array of Edges on the system.
+ * @method ClearBlade.getEdges
+ * @param {function} callback A function like `function (err, data) {}` to handle the response
*/
ClearBlade.prototype.getEdges = function(callback) {
if (!callback || typeof callback !== 'function') {
@@ -2198,14 +2197,40 @@
Source: ClearBlade.js
return metrics;
};
+ /**
+ * Creates a representation of devices
+ * @class ClearBlade.Device
+ * @classdesc It does not actually make a connection upon instantiation, but has all the methods necessary to do so.
+ * @example
+ * var device = cb.Device();
+ */
ClearBlade.prototype.Device = function(){
- var device = {};
+ let device = {};
device.user = this.user;
device.URI = this.URI;
device.systemKey = this.systemKey;
device.systemSecret = this.systemSecret;
+ /**
+ * Requests the named device from Devices Auth table
+ * @method ClearBlade.Device.prototype.getDeviceByName
+ * @param {String} name Used to indicate which device to get
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} An object representing the requested device
+ * @example <caption>Fetching data from device</caption>
+ * let returnedData = {};
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * } else {
+ * returnedData = data;
+ * }
+ * };
+ *
+ * device.updateDeviceByName(name, callback);
+ * //this will give returnedData the value of what ever was returned from the server.
+ */
device.getDeviceByName = function (name, callback) {
var reqOptions = {
method: 'GET',
@@ -2216,9 +2241,30 @@
Source: ClearBlade.js
ClearBlade.request(reqOptions, callback);
};
- device.updateDevice = function (name, object, trigger, callback){
+ /**
+ * Updates a device in the Devices Auth table
+ * @method ClearBlade.Device.prototype.updateDevice
+ * @param {String} name Specifies which device to update
+ * @param {Object} object Supplies which columns in the Devices table to update
+ * @param {Boolean} trigger Indicates whether or not to enable trigger
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} A success attribute
+ * @example <caption>Updating device data</caption>
+ * var object = {
+ * active_key: "example_active_key",
+ * allow_key_auth: false
+ * }
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * }
+ * };
+ *
+ * device.updateDevice(name, object, trigger, callback);
+ */
+ device.updateDevice = function (name, object, trigger, callback) {
if (typeof object != "object"){
- throw new Error('Invalid object format');
+ throw new Error('Invalid object format');
}
object["causeTrigger"] = trigger;
var reqOptions = {
@@ -2231,6 +2277,64 @@
Source: ClearBlade.js
ClearBlade.request(reqOptions, callback);
};
+ /**
+ * Requests all devices defined within a system, unless query specifies one item or a set of items.
+ * @method ClearBlade.Device.prototype.fetch
+ * @param {Query} _query Used to request a specific item or subset of items from the devices on the server. Optional.
+ * @param {function} callback Supplies processing for what to do with the data that is returned from the devices
+ * @return {Object} An array of JSON objects, whose attributes correspond to columns in the Devices tables
+ * @example <caption>Fetching data from devices</caption>
+ * var returnedData = [];
+ * var query = ClearBlade.Query();
+ * query.equalTo('enabled', 'true');
+ * var callback = function (err, data) {
+ * if (err) {
+ * throw new Error (data);
+ * } else {
+ * returnedData = data;
+ * }
+ * };
+ *
+ * device.fetch(query, callback);
+ * //this will give returnedData the value of what ever was returned from the server, every device whose "enabled" attribute is equal to "true".
+ */
+ device.fetch = function (_query, callback) {
+ let query;
+ /*
+ * The following logic may look funny, but it is intentional.
+ * I do this because it is typeical for the callback to be the last parameter.
+ * However, '_query' is an optional parameter, so I have to check if 'callback' is undefined
+ * in order to see weather or not _query is defined.
+ */
+ if (callback === undefined) {
+ callback = _query;
+ query = {
+ FILTERS: []
+ };
+ query = 'query='+ _parseQuery(query);
+ } else {
+ if (Object.keys(_query) < 1) {
+ query = '';
+ } else {
+ query = 'query='+ _parseQuery(_query.query);
+ }
+ }
+
+ var reqOptions = {
+ method: 'GET',
+ user: this.user,
+ endpoint: "api/v/2/devices/" + this.systemKey,
+ qs: query,
+ URI: this.URI
+ };
+
+ if (typeof callback === 'function') {
+ ClearBlade.request(reqOptions, callback);
+ } else {
+ logger("No callback was defined!");
+ }
+ };
+
return device;
};
@@ -2408,13 +2512,13 @@
Source: ClearBlade.js
-
+
diff --git a/out/index.html b/out/index.html
index 67a1466..97c4793 100644
--- a/out/index.html
+++ b/out/index.html
@@ -2,7 +2,7 @@
- JSDoc: Index
+ JSDoc: Home
@@ -17,7 +17,7 @@