Skip to content

Commit 156c185

Browse files
committed
added more docs
1 parent 4c5c43d commit 156c185

12 files changed

Lines changed: 5445 additions & 2091 deletions

ClearBlade.js

Lines changed: 173 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if (!window.console) {
2222
* @namespace ClearBlade
2323
* @example <caption>Initialize ClearBladeAPI</caption>
2424
* initOptions = {systemKey: 'asdfknafikjasd3853n34kj2vc', systemSecret: 'SHHG245F6GH7SDFG823HGSDFG9'};
25-
* ClearBlade.init(initOptions);
25+
* var cb = ClearBlade();
26+
* cb.init(initOptions);
2627
*
2728
*/
2829

@@ -38,7 +39,17 @@ if (!window.console) {
3839
/**
3940
* This method initializes the ClearBlade module with the values needed to connect to the platform
4041
* @method ClearBlade.init
41-
* @param options {Object} the `options` Object
42+
* @param {Object} options This value contains the config object for initializing the ClearBlade module. A number of reasonable defaults are set for the option if none are set.
43+
*<p>
44+
*The connect options and their defaults are:
45+
* <p>{String} [systemKey] This is the app key that will identify your app in order to connect to the Platform</p>
46+
* <p>{String} [systemSecret] This is the app secret that will be used in combination with the systemKey to authenticate your app</p>
47+
* <p>{String} [URI] This is the URI used to identify where the Platform is located. Default is https://platform.clearblade.com</p>
48+
* <p>{String} [messagingURI] This is the URI used to identify where the Messaging server is located. Default is platform.clearblade.com</p>
49+
* <p>{Number} [messagingPort] This is the default port used when connecting to the messaging server. Default is 8904</p>
50+
* <p>{Boolean} [logging] This is the property that tells the API whether or not the API will log to the console. This should be left `false` in production. Default is false</p>
51+
* <p>{Number} [callTimeout] This is the amount of time that the API will use to determine a timeout. Default is 30 seconds</p>
52+
*</p>
4253
*/
4354
ClearBlade.prototype.init = function (options) {
4455
var _this = this;
@@ -182,14 +193,34 @@ if (!window.console) {
182193
throw new Error("Password must be given and must be a string");
183194
}
184195
};
185-
196+
/**
197+
* Used when assuming the role of a user to make subsequent requests
198+
* @method ClearBlade.setUser
199+
* @param email {String} the email of the user
200+
* @param authToken {String} the authToken for the user
201+
*/
186202
ClearBlade.prototype.setUser = function(email, authToken) {
187203
this.user = {
188204
"email": email,
189205
"authToken": authToken
190206
};
191207
};
192208

209+
/**
210+
* Method to register a user with the ClearBlade Platform
211+
* @method ClearBlade.registerUser
212+
* @param email {String} the users email
213+
* @param password {String} the password for the user
214+
* @param callback {function} returns a Boolean error value and a response as parameters
215+
* @example <caption> Register User </caption>
216+
* cb.registerUser("newUser@domain.com", "qwerty", function(err, body) {
217+
* if(err) {
218+
* //handle error
219+
* } else {
220+
* console.log(body);
221+
* }
222+
* });
223+
*/
193224
ClearBlade.prototype.registerUser = function(email, password, callback) {
194225
_validateEmailPassword(email, password);
195226
ClearBlade.request({
@@ -209,7 +240,19 @@ if (!window.console) {
209240
}
210241
});
211242
};
212-
243+
/**
244+
* Method to check if the current user has an active server session
245+
* @method ClearBlade.isCurrentUserAuthenticated
246+
* @param {Function} callback
247+
* @example
248+
* cb.isCurrentUserAuthenticated(function(err, body) {
249+
* if(err) {
250+
* //handle error
251+
* } else {
252+
* //check authentication boolean
253+
* }
254+
* })
255+
*/
213256
ClearBlade.prototype.isCurrentUserAuthenticated = function(callback) {
214257
ClearBlade.request({
215258
method: 'POST',
@@ -227,7 +270,19 @@ if (!window.console) {
227270
}
228271
});
229272
};
230-
273+
/**
274+
* Method to end the server session for the current user
275+
* @method ClearBlade.logoutUser
276+
* @param {Function} callback
277+
* @example
278+
* cb.logoutUser(function(err, body) {
279+
* if(err) {
280+
* //handle error
281+
* } else {
282+
* //do post logout stuff
283+
* }
284+
* })
285+
*/
231286
ClearBlade.prototype.logoutUser = function(callback) {
232287
ClearBlade.request({
233288
method: 'POST',
@@ -246,6 +301,19 @@ if (!window.console) {
246301
});
247302
};
248303

304+
/**
305+
* Method to create an anonymous session with the ClearBlade Platform
306+
* @method ClearBlade.loginAnon
307+
* @param {Function} callback
308+
* @example
309+
* cb.loginAnon(function(err, body) {
310+
* if(err) {
311+
* //handle error
312+
* } else {
313+
* //do post login stuff
314+
* }
315+
* })
316+
*/
249317
ClearBlade.prototype.loginAnon = function(callback) {
250318
var _this = this;
251319
ClearBlade.request({
@@ -265,7 +333,21 @@ if (!window.console) {
265333
}
266334
});
267335
};
268-
336+
/**
337+
* Method to create an authenticated session with the ClearBlade Platform
338+
* @method
339+
* @param {String} email
340+
* @param {String} password
341+
* @param {Function} callback
342+
* @example
343+
* cb.loginUser("existentUser@domain.com", "qwerty", function(err, body) {
344+
* if(err) {
345+
* //handle error
346+
* } else {
347+
* //do post login stuff
348+
* }
349+
* })
350+
*/
269351
ClearBlade.prototype.loginUser = function(email, password, callback) {
270352
var _this = this;
271353
_validateEmailPassword(email, password);
@@ -500,6 +582,8 @@ if (!window.console) {
500582
* @class ClearBlade.Collection
501583
* @classdesc 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.
502584
* @param {String} collectionID The string ID for the collection you want to represent.
585+
* @example
586+
* var col = cb.Collection("12asd3049qwe834qe23asdf1234");
503587
*/
504588
ClearBlade.prototype.Collection = function(collectionID) {
505589
var collection = {};
@@ -513,6 +597,7 @@ if (!window.console) {
513597
* @method ClearBlade.Collection.prototype.fetch
514598
* @param {Query} _query Used to request a specific item or subset of items from the collection on the server. Optional.
515599
* @param {function} callback Supplies processing for what to do with the data that is returned from the collection
600+
* @return {ClearBlade.Item} An array of ClearBlade Items
516601
* @example <caption>Fetching data from a collection</caption>
517602
* var returnedData = [];
518603
* var callback = function (err, data) {
@@ -887,6 +972,7 @@ if (!window.console) {
887972
* the Query object was initialized with a collection.
888973
* @method ClearBlade.Query.prototype.fetch
889974
* @param {function} callback Supplies processing for what to do with the data that is returned from the collection
975+
* @return {ClearBlade.Item} An array of ClearBlade Items
890976
* @example <caption>The typical callback</caption>
891977
* var query = ClearBlade.Query({'collection': 'COLLECTIONID'});
892978
* var callback = function (err, data) {
@@ -897,7 +983,6 @@ if (!window.console) {
897983
* }
898984
* };
899985
* query.fetch(callback);
900-
* //this will give returnedData the value of what ever was returned from the server.
901986
*/
902987
query.fetch = function (callback) {
903988
var reqOptions = {
@@ -1034,7 +1119,11 @@ if (!window.console) {
10341119

10351120
return query;
10361121
};
1037-
1122+
/**
1123+
* @class ClearBlade.Item
1124+
* @param {Object} data Object that contains necessary data for an item in a ClearBlade Collection
1125+
* @param {String} collection Collection ID of the collection the item belongs to
1126+
*/
10381127
ClearBlade.prototype.Item = function (data, collection) {
10391128
var item = {};
10401129
if (!(data instanceof Object)) {
@@ -1097,15 +1186,33 @@ if (!window.console) {
10971186

10981187
return item;
10991188
};
1100-
1189+
/**
1190+
* creates and returns a Code object that can be used to execute ClearBlade Code Services
1191+
* @class ClearBlade.Code
1192+
* @returns {Object} ClearBlade.Code
1193+
*/
11011194
ClearBlade.prototype.Code = function(){
11021195
var code = {};
11031196
code.user = this.user;
11041197
code.URI = this.URI;
11051198
code.systemKey = this.systemKey;
11061199
code.systemSecret = this.systemSecret;
11071200
code.callTimeout = this._callTimeout;
1108-
1201+
/**
1202+
* Executes a ClearBlade Code Service
1203+
* @method ClearBlade.Code.prototype.execute
1204+
* @param {String} name name of the ClearBlade service
1205+
* @param {Object} params object containing parameters to be used in service
1206+
* @param {Function} callback
1207+
* @example
1208+
* cb.Code().execute("ServiceName", {stringParam: "stringVal", numParam: 1, objParam: {"key": "val"}, arrayParam: ["ClearBlade", "is", "awesome"]}, function(err, body) {
1209+
* if(err) {
1210+
* //handle error
1211+
* } else {
1212+
* console.log(body);
1213+
* }
1214+
* })
1215+
*/
11091216
code.execute = function(name, params, callback){
11101217
var reqOptions = {
11111218
method: 'POST',
@@ -1122,7 +1229,10 @@ if (!window.console) {
11221229

11231230
return code;
11241231
};
1125-
1232+
/**
1233+
* @class ClearBlade.User
1234+
* @returns {Object} ClearBlade.User the created User object
1235+
*/
11261236
ClearBlade.prototype.User = function(){
11271237
var user = {};
11281238
user.user = this.user;
@@ -1131,6 +1241,20 @@ if (!window.console) {
11311241
user.systemSecret = this.systemSecret;
11321242
user.callTimeout = this._callTimeout;
11331243

1244+
/**
1245+
* Retrieves info on the current user
1246+
* @method ClearBlade.User.prototype.getUser
1247+
* @param {Function} callback
1248+
* @example
1249+
* var user = cb.User();
1250+
* user.getUser(function(err, body) {
1251+
* if(err) {
1252+
* //handle error
1253+
* } else {
1254+
* //do stuff with user info
1255+
* }
1256+
* });
1257+
*/
11341258
user.getUser = function(callback){
11351259
var reqOptions = {
11361260
method: 'GET',
@@ -1143,7 +1267,25 @@ if (!window.console) {
11431267
logger("No callback was defined!");
11441268
}
11451269
};
1146-
1270+
/**
1271+
* Performs a put on the current users row
1272+
* @method ClearBlade.User.prototype.setUser
1273+
* @param {Object} data Object containing the data to update
1274+
* @param {Function} callback
1275+
* @example
1276+
* var newUserInfo = {
1277+
* "name": "newName",
1278+
* "age": 76
1279+
* }
1280+
* var user = cb.User();
1281+
* user.setUser(newUserInfo, function(err, body) {
1282+
* if(err) {
1283+
* //handle error
1284+
* } else {
1285+
* console.log(body);
1286+
* }
1287+
* });
1288+
*/
11471289
user.setUser = function(data, callback){
11481290
var reqOptions = {
11491291
method: 'PUT',
@@ -1157,7 +1299,25 @@ if (!window.console) {
11571299
logger("No callback was defined!");
11581300
}
11591301
};
1160-
1302+
/**
1303+
* Method to retrieve all the users in a system
1304+
* @method ClearBlade.User.prototype.allUsers
1305+
* @param {ClearBlade.Query} _query ClearBlade query used to filter users
1306+
* @param {Function} callback
1307+
* @example
1308+
* var user = cb.User();
1309+
* var query = cb.Query();
1310+
* query.equalTo("name", "John");
1311+
* query.setPage(0,0);
1312+
* user.allUsers(query, function(err, body) {
1313+
* if(err) {
1314+
* //handle error
1315+
* } else {
1316+
* console.log(body);
1317+
* }
1318+
* });
1319+
* //returns all the users with a name property equal to "John"
1320+
*/
11611321
user.allUsers = function(_query, callback) {
11621322
var query;
11631323
if (callback === undefined) {

0 commit comments

Comments
 (0)