You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/04/02 17:21:26 UTC

[21/41] git commit: Updated examples and fixed issues where encountered. Updated changelog

Updated examples and fixed issues where encountered. Updated changelog


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/39f0ebeb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/39f0ebeb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/39f0ebeb

Branch: refs/pull/96/head
Commit: 39f0ebeb1883df9bdedfbc5f4e4684a99dc9efad
Parents: 3c47925
Author: ryan bridges <rb...@apigee.com>
Authored: Tue Apr 1 16:40:09 2014 -0400
Committer: ryan bridges <rb...@apigee.com>
Committed: Tue Apr 1 16:40:09 2014 -0400

----------------------------------------------------------------------
 sdks/html5-javascript/changelog.md          | 13 ++++++-
 sdks/html5-javascript/examples/dogs/app.js  |  6 ++--
 sdks/html5-javascript/examples/test/test.js | 46 ++++++++++++------------
 sdks/html5-javascript/index.html            | 12 +++----
 sdks/html5-javascript/lib/modules/Client.js | 21 +++++------
 sdks/html5-javascript/lib/modules/Entity.js | 18 +++++-----
 sdks/html5-javascript/usergrid.js           | 32 ++++++++---------
 sdks/html5-javascript/usergrid.min.js       |  2 +-
 8 files changed, 80 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/changelog.md
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/changelog.md b/sdks/html5-javascript/changelog.md
index a2435cb..692a1a4 100644
--- a/sdks/html5-javascript/changelog.md
+++ b/sdks/html5-javascript/changelog.md
@@ -1,7 +1,18 @@
 ##Change log
 ###0.11.0
 - Removed 'getOnExist' flag from createEntity and createGroup. Handling of duplicate entity errors is now the responsibility of the client.
-
+- Usergrid.Group.prototype.fetch returns self instead of group list
+- Usergrid.Client.prototype.createGroup updated to new callback format
+- Usergrid.Client.prototype.createEntity updated to new callback format
+- Usergrid.Client.prototype.getEntity updated to new callback format
+- Usergrid.Collection instantiation no longer fetches the collection automatically, this no longer takes a callback
+- Usergrid.Entity.prototype.save no longer handles password changes
+- Usergrid.Entity.prototype.changePassword added to handle password requests
+- Usergrid.Counter no longer needs a callback
+- Usergrid.Asset.prototype.download sets appropriate mime type for content
+- Usergrid.Asset.prototype.upload implemented retry interval to mitigate errors when an asset has not fully propagated
+ 
+ 
 ###0.10.8
 - Added support for Events and Counters
 - Added support for Folders and Assets

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/examples/dogs/app.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/examples/dogs/app.js b/sdks/html5-javascript/examples/dogs/app.js
index 17289f3..55b0e17 100755
--- a/sdks/html5-javascript/examples/dogs/app.js
+++ b/sdks/html5-javascript/examples/dogs/app.js
@@ -44,11 +44,11 @@ $(document).ready(function () {
 
   var dogs;
 
-  client.createCollection(options, function (err, dogs) {
+  client.createCollection(options, function (err, response, collection) {
     if (err) {
       $('#mydoglist').html('could not load dogs');
     } else {
-
+      dogs=collection;
       //bind the next button to the proper method in the collection object
       $('#next-button').bind('click', function() {
         $('#message').html('');
@@ -174,4 +174,4 @@ $(document).ready(function () {
     }
   });
 
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/examples/test/test.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/examples/test/test.js b/sdks/html5-javascript/examples/test/test.js
index ff9dc82..fb65d98 100755
--- a/sdks/html5-javascript/examples/test/test.js
+++ b/sdks/html5-javascript/examples/test/test.js
@@ -303,7 +303,7 @@ function makeNewDog(step) {
 		name:'Ralph'+_unique
 	}
 
-	client.createEntity(options, function (err, dog) {
+	client.createEntity(options, function (err, response, dog) {
 		if (err) {
 			error('dog not created');
 		} else {
@@ -414,7 +414,7 @@ function testDogsCollection(step) {
 		qs:{ql:'order by index'}
 	}
 
-	client.createCollection(options, function (err, dogs) {
+	client.createCollection(options, function (err, response, dogs) {
 		if (err) {
 			error('could not make collection');
 		} else {
@@ -519,7 +519,7 @@ function cleanupAllDogs(step){
 		qs:{limit:50} //limit statement set to 50
 	}
 
-	client.createCollection(options, function (err, dogs) {
+	client.createCollection(options, function (err, response, dogs) {
 		if (err) {
 			error('could not get all dogs');
 		} else {
@@ -574,7 +574,7 @@ function prepareDatabaseForNewUser(step) {
 
 function createUser(step) {
 	client.signup(_username, _password, _email, 'Marty McFly',
-		function (err, marty) {
+		function (err, response, marty) {
 			if (err){
 				error('user not created');
 				runner(step, marty);
@@ -608,7 +608,7 @@ function getExistingUser(step, marty) {
 		type:'users',
 		username:_username
 	}
-	client.getEntity(options, function(err, existingUser){
+	client.getEntity(options, function(err, response, existingUser){
 		if (err){
 			error('existing user not retrieved');
 		} else {
@@ -644,7 +644,7 @@ function loginUser(step, marty) {
 	username = _username;
 	password = _password;
 	client.login(username, password,
-		function (err) {
+		function (err, response, user) {
 			if (err) {
 				error('could not log user in');
 			} else {
@@ -659,6 +659,7 @@ function loginUser(step, marty) {
 				//Then make calls against the API.  For example, you can
 				//get the user entity this way:
 				client.getLoggedInUser(function(err, data, user) {
+					console.error(err, data, user);
 					if(err) {
 						error('could not get logged in user');
 					} else {
@@ -680,8 +681,9 @@ function loginUser(step, marty) {
 function changeUsersPassword(step, marty) {
 
 	marty.set('oldpassword', _password);
+	marty.set('password', _newpassword);
 	marty.set('newpassword', _newpassword);
-	marty.save(function(err){
+	marty.changePassword(function(err, response){
 		if (err){
 			error('user password not updated');
 		} else {
@@ -712,13 +714,13 @@ function reloginUser(step, marty) {
 	username = _username
 	password = _newpassword;
 	client.login(username, password,
-		function (err) {
-		if (err) {
-			error('could not relog user in');
-		} else {
-			success('user has been re-logged in');
-			runner(step, marty);
-		}
+		function (err, response, marty) {
+			if (err) {
+				error('could not relog user in');
+			} else {
+				success('user has been re-logged in');
+				runner(step, marty);
+			}
 		}
 	);
 }
@@ -741,7 +743,7 @@ function createDog(step, marty) {
 		breed:'mutt'
 	}
 
-	client.createEntity(options, function (err, dog) {
+	client.createEntity(options, function (err, response, dog) {
 		if (err) {
 			error('POST new dog by logged in user failed');
 		} else {
@@ -754,14 +756,14 @@ function createDog(step, marty) {
 
 function userLikesDog(step, marty, dog) {
 
-	marty.connect('likes', dog, function (err, data) {
+	marty.connect('likes', dog, function (err, response, data) {
 		if (err) {
 			error('connection not created');
 			runner(step, marty);
 		} else {
 
 			//call succeeded, so pull the connections back down
-			marty.getConnections('likes', function (err, data) {
+			marty.getConnections('likes', function (err, response, data) {
 				if (err) {
 						error('could not get connections');
 				} else {
@@ -842,7 +844,7 @@ function createExistingEntity(step, marty) {
 		name:'einstein'
 	}
 
-	client.createEntity(options, function (err, dog) {
+	client.createEntity(options, function (err, response, dog) {
 		if (err) {
 			error('Create new entity to use for existing entity failed');
 		} else {
@@ -858,7 +860,7 @@ function createExistingEntity(step, marty) {
 				name:'einstein',
 				breed:'mutt'
 			}
-			client.createEntity(options, function (err, newdog) {
+			client.createEntity(options, function (err, response, newdog) {
 				if (err) {
 					success('Create new entity to use for existing entity failed');
 				} else {
@@ -887,7 +889,7 @@ function createNewEntityNoName(step, marty) {
    othervalue:"something else"
 	}
 
-	client.createEntity(options, function (err, entity) {
+	client.createEntity(options, function (err, response, entity) {
 		if (err) {
 			error('Create new entity with no name failed');
 		} else {
@@ -907,7 +909,7 @@ function cleanUpUsers(step){
     qs:{limit:50} //limit statement set to 50
   }
 
-  client.createCollection(options, function (err, users) {
+  client.createCollection(options, function (err, response, users) {
     if (err) {
       error('could not get all users');
     } else {
@@ -940,7 +942,7 @@ function cleanUpDogs(step){
       qs:{limit:50} //limit statement set to 50
     }
 
-    client.createCollection(options, function (err, dogs) {
+    client.createCollection(options, function (err, response, dogs) {
       if (err) {
         error('could not get all dogs');
       } else {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/index.html
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/index.html b/sdks/html5-javascript/index.html
index 359e8c8..2019b6c 100755
--- a/sdks/html5-javascript/index.html
+++ b/sdks/html5-javascript/index.html
@@ -8,22 +8,22 @@
    </head>
    <body>
       <div class="header">
-         <img src="examples/resources/images/apigee.png"> App Services (Usergrid) Javascript SDK
+         <img src="examples/resources/images/apigee.png"> Usergrid Javascript SDK
       </div>
       <div id="main" class="main">
          <br/>
          <h2>Javascript SDK</h2>
-         This SDK is designed to enable you to connect your apps to the App Services (Usergrid) API.
+         This SDK is designed to enable you to connect your apps to the Usergrid API.
          <br/>
          <br/>
          <h2>Read me</h2>
          View the read me file for the SDK:
-         <a href="https://github.com/apigee/usergrid-javascript-sdk/blob/master/README.md">https://github.com/apigee/usergrid-javascript-sdk/blob/master/README.md</a>.
+         <a href="https://github.com/usergrid/usergrid/blob/master/sdks/html5-javascript/README.md">https://github.com/usergrid/usergrid/blob/master/sdks/html5-javascript/README.md</a>.
          <br/>
          <br/>
          <h2>API documentation</h2>
-         For more information on App Services, see our docs:
-         <a href="http://apigee.com/docs/app_services">http://apigee.com/docs/app_service</a>
+         For more information on Usergrid, see the Apache docs:
+         <a href="http://usergrid.incubator.apache.org/">http://usergrid.incubator.apache.org/</a>
          <br/>
          <br/>
 
@@ -41,7 +41,7 @@
          <br/>
          <a href="examples/facebook/facebook.html" style="font-size: 20px;">Facebook Login Example</a>
          <br/>
-         This app shows you how to use Facebook to log into App Services (Usergrid).
+         This app shows you how to use Facebook to log into Usergrid.
          <br/>
          <br/>
          <a href="examples/test/test.html" style="font-size: 20px;">Tests for examples in readme file</a>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/lib/modules/Client.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Client.js b/sdks/html5-javascript/lib/modules/Client.js
index a87c935..bc6f39a 100644
--- a/sdks/html5-javascript/lib/modules/Client.js
+++ b/sdks/html5-javascript/lib/modules/Client.js
@@ -519,19 +519,19 @@
         grant_type: 'password'
       }
     };
-    self.request(options, function(err, data) {
+    self.request(options, function(err, response) {
       var user = {};
       if (err) {
         if (self.logging) console.log('error trying to log user in');
       } else {
         var options = {
           client: self,
-          data: data.user
+          data: response.user
         };
         user = new Usergrid.Entity(options);
-        self.setToken(data.access_token);
+        self.setToken(response.access_token);
       }
-      doCallback(callback, [err, data, user]);
+      doCallback(callback, [err, response, user]);
     });
   };
 
@@ -665,27 +665,28 @@
    *  @return {callback} callback(err, data)
    */
   Usergrid.Client.prototype.getLoggedInUser = function(callback) {
+    var self = this;
     if (!this.getToken()) {
-      callback(true, null, null);
+        doCallback(callback, [new UsergridError("Access Token not set"), null, self], self);
     } else {
-      var self = this;
       var options = {
         method: 'GET',
         endpoint: 'users/me'
       };
-      this.request(options, function(err, data) {
+      this.request(options, function(err, response) {
         if (err) {
           if (self.logging) {
             console.log('error trying to log user in');
           }
-          doCallback(callback, [err, data, null], self);
+          console.error(err, response);
+          doCallback(callback, [err, response, self], self);
         } else {
           var options = {
             client: self,
-            data: data.entities[0]
+            data: response.getEntity()
           };
           var user = new Usergrid.Entity(options);
-          doCallback(callback, [null, data, user], self);
+          doCallback(callback, [null, response, user], self);
         }
       });
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/lib/modules/Entity.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Entity.js b/sdks/html5-javascript/lib/modules/Entity.js
index d5dc3ec..48d9e1e 100644
--- a/sdks/html5-javascript/lib/modules/Entity.js
+++ b/sdks/html5-javascript/lib/modules/Entity.js
@@ -351,17 +351,15 @@ Usergrid.Entity.prototype.addOrRemoveConnection = function(method, connection, e
  *
  */
 Usergrid.Entity.prototype.getEntityId = function(entity) {
-  var id = false;
-  if (isUUID(entity.get('uuid'))) {
-    id = entity.get('uuid');
-  } else {
-    if (this.get("type") === 'users') {
-      id = entity.get('username');
-    } else if (entity.get('name')) {
-      id = entity.get('name');
+    var id;
+    if (isUUID(entity.get("uuid"))) {
+        id = entity.get("uuid");
+    } else if (this.get("type") === "users") {
+        id = entity.get("username");
+    } else  {
+        id = entity.get("name");
     }
-  }
-  return id;
+    return id;
 };
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/39f0ebeb/sdks/html5-javascript/usergrid.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/usergrid.js b/sdks/html5-javascript/usergrid.js
index 79ab355..2c4efd7 100644
--- a/sdks/html5-javascript/usergrid.js
+++ b/sdks/html5-javascript/usergrid.js
@@ -1040,19 +1040,19 @@ function doCallback(callback, params, context) {
                 grant_type: "password"
             }
         };
-        self.request(options, function(err, data) {
+        self.request(options, function(err, response) {
             var user = {};
             if (err) {
                 if (self.logging) console.log("error trying to log user in");
             } else {
                 var options = {
                     client: self,
-                    data: data.user
+                    data: response.user
                 };
                 user = new Usergrid.Entity(options);
-                self.setToken(data.access_token);
+                self.setToken(response.access_token);
             }
-            doCallback(callback, [ err, data, user ]);
+            doCallback(callback, [ err, response, user ]);
         });
     };
     Usergrid.Client.prototype.reAuthenticateLite = function(callback) {
@@ -1171,27 +1171,28 @@ function doCallback(callback, params, context) {
    *  @return {callback} callback(err, data)
    */
     Usergrid.Client.prototype.getLoggedInUser = function(callback) {
+        var self = this;
         if (!this.getToken()) {
-            callback(true, null, null);
+            doCallback(callback, [ new UsergridError("Access Token not set"), null, self ], self);
         } else {
-            var self = this;
             var options = {
                 method: "GET",
                 endpoint: "users/me"
             };
-            this.request(options, function(err, data) {
+            this.request(options, function(err, response) {
                 if (err) {
                     if (self.logging) {
                         console.log("error trying to log user in");
                     }
-                    doCallback(callback, [ err, data, null ], self);
+                    console.error(err, response);
+                    doCallback(callback, [ err, response, self ], self);
                 } else {
                     var options = {
                         client: self,
-                        data: data.entities[0]
+                        data: response.getEntity()
                     };
                     var user = new Usergrid.Entity(options);
-                    doCallback(callback, [ null, data, user ], self);
+                    doCallback(callback, [ null, response, user ], self);
                 }
             });
         }
@@ -1671,15 +1672,13 @@ Usergrid.Entity.prototype.addOrRemoveConnection = function(method, connection, e
  *
  */
 Usergrid.Entity.prototype.getEntityId = function(entity) {
-    var id = false;
+    var id;
     if (isUUID(entity.get("uuid"))) {
         id = entity.get("uuid");
+    } else if (this.get("type") === "users") {
+        id = entity.get("username");
     } else {
-        if (this.get("type") === "users") {
-            id = entity.get("username");
-        } else if (entity.get("name")) {
-            id = entity.get("name");
-        }
+        id = entity.get("name");
     }
     return id;
 };
@@ -3006,7 +3005,6 @@ Usergrid.Asset.prototype.upload = function(data, callback) {
     fr.onload = function() {
         var binary = fr.result;
         xhr.overrideMimeType("application/octet-stream");
-        // setTimeout(function() {
         xhr.sendAsBinary(binary);
     };
     fr.readAsBinaryString(data);