Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB7741035D for ; Tue, 11 Feb 2014 23:21:14 +0000 (UTC) Received: (qmail 92845 invoked by uid 500); 11 Feb 2014 23:20:55 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 92578 invoked by uid 500); 11 Feb 2014 23:20:51 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 92370 invoked by uid 99); 11 Feb 2014 23:20:46 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Feb 2014 23:20:46 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 814E2924A33; Tue, 11 Feb 2014 23:20:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: snoopdave@apache.org To: commits@usergrid.apache.org Date: Tue, 11 Feb 2014 23:20:53 -0000 Message-Id: <6da4153067d940eeaa7bf03966199eb0@git.apache.org> In-Reply-To: <224034ca503843da8ef74ff4aa0085fd@git.apache.org> References: <224034ca503843da8ef74ff4aa0085fd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/41] git commit: code cleanup code cleanup Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/4245f53a Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/4245f53a Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/4245f53a Branch: refs/heads/master Commit: 4245f53aa6190304822f28649e48ca0d61ad885a Parents: 9166895 Author: ryan bridges Authored: Mon Feb 3 09:07:08 2014 -0500 Committer: ryan bridges Committed: Mon Feb 3 09:07:08 2014 -0500 ---------------------------------------------------------------------- sdks/html5-javascript/lib/Client.js | 55 +++++++++++--------------- sdks/html5-javascript/lib/Entity.js | 66 ++++++++++++++++---------------- 2 files changed, 56 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4245f53a/sdks/html5-javascript/lib/Client.js ---------------------------------------------------------------------- diff --git a/sdks/html5-javascript/lib/Client.js b/sdks/html5-javascript/lib/Client.js index f29a51e..7b5a425 100644 --- a/sdks/html5-javascript/lib/Client.js +++ b/sdks/html5-javascript/lib/Client.js @@ -531,12 +531,13 @@ Usergrid.Client.prototype.getObject = function(key) { Usergrid.Client.prototype.get = function (key) { var keyStore = 'apigee_' + key; + var value=null; if (this[key]) { - return this[key]; + value= this[key]; } else if(typeof(Storage)!=="undefined") { - return localStorage.getItem(keyStore); + value= localStorage.getItem(keyStore); } - return null; + return value; }; /* @@ -778,10 +779,7 @@ Usergrid.Client.prototype.getLoggedInUser = function (callback) { * @return {boolean} Returns true the user is logged in (has token and uuid), false if not */ Usergrid.Client.prototype.isLoggedIn = function () { - if (this.getToken() && this.getToken() != 'null') { - return true; - } - return false; + return "undefined" !== typeof this.getToken(); }; /* @@ -804,32 +802,23 @@ Usergrid.Client.prototype.logout = function () { * @return {string} curl */ Usergrid.Client.prototype.buildCurlCall = function (options) { - var curl = 'curl'; + var curl = ['curl']; var method = (options.method || 'GET').toUpperCase(); - var body = options.body || {}; + var body = options.body; var uri = options.uri; //curl - add the method to the command (no need to add anything for GET) - if (method === 'POST') { - curl += ' -X POST'; - } else if (method === 'PUT') { - curl += ' -X PUT'; - } else if (method === 'DELETE') { - curl += ' -X DELETE'; - } else { - curl += ' -X GET'; - } + curl.push('-X'); + curl.push((['POST','PUT','DELETE'].indexOf(method)>=0)?method:'GET'); //curl - append the path - curl += ' ' + uri; + curl.push(uri); - //curl - add the body - if("undefined"!== typeof window){body = JSON.stringify(body);}//only in node module - if (body !== '"{}"' && method !== 'GET' && method !== 'DELETE') { - //curl - add in the json obj - curl += " -d '" + body + "'"; + if("object"===typeof body && Object.keys(body).length>0 && ['POST','PUT'].indexOf(method)!==-1){ + curl.push('-d'); + curl.push("'"+JSON.stringify(body)+"'"); } - + curl=curl.join(' '); //log the curl command to the console console.log(curl); @@ -837,18 +826,18 @@ Usergrid.Client.prototype.buildCurlCall = function (options) { } Usergrid.Client.prototype.getDisplayImage = function (email, picture, size) { + size = size || 50; + var image='https://apigee.com/usergrid/images/user_profile.png'; try { if (picture) { - return picture; - } - var size = size || 50; - if (email.length) { - return 'https://secure.gravatar.com/avatar/' + MD5(email) + '?s=' + size + encodeURI("&d=https://apigee.com/usergrid/images/user_profile.png"); - } else { - return 'https://apigee.com/usergrid/images/user_profile.png'; + image= picture; + }else if (email.length) { + image= 'https://secure.gravatar.com/avatar/' + MD5(email) + '?s=' + size + encodeURI("&d=https://apigee.com/usergrid/images/user_profile.png"); } } catch(e) { - return 'https://apigee.com/usergrid/images/user_profile.png'; + //TODO do something with this error? + }finally{ + return image; } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4245f53a/sdks/html5-javascript/lib/Entity.js ---------------------------------------------------------------------- diff --git a/sdks/html5-javascript/lib/Entity.js b/sdks/html5-javascript/lib/Entity.js index c4fe016..cb728be 100644 --- a/sdks/html5-javascript/lib/Entity.js +++ b/sdks/html5-javascript/lib/Entity.js @@ -20,7 +20,7 @@ Usergrid.Entity = function(options) { * @params {any} obj - any variable * @return {boolean} Returns true or false */ -Usergrid.isEntity = function(obj){ +Usergrid.Entity.isEntity = function(obj){ return (obj && obj instanceof Usergrid.Entity); } @@ -33,7 +33,7 @@ Usergrid.isEntity = function(obj){ * @params {any} obj - any variable * @return {boolean} Returns true or false */ -Usergrid.isPersistedEntity = function(obj){ +Usergrid.Entity.isPersistedEntity = function(obj){ return (isEntity(obj) && isUUID(obj.get('uuid'))); } @@ -58,11 +58,7 @@ Usergrid.Entity.prototype.serialize = function () { * @return {string} || {object} data */ Usergrid.Entity.prototype.get = function (field) { - if (field) { - return this._data[field]; - } else { - return this._data; - } + return (field) ? this._data[field] : this._data; }; /* @@ -100,33 +96,39 @@ Usergrid.Entity.prototype.set = function (key, value) { * @return {callback} callback(err, data) */ Usergrid.Entity.prototype.save = function (callback) { - var type = this.get('type'); - var method = 'POST'; - if (isUUID(this.get('uuid'))) { - method = 'PUT'; - type += '/' + this.get('uuid'); - } + var self = this, + type = this.get('type'), + method = 'POST', + entityId=this.get("uuid"), + data = {}, + entityData = this.get(), + password = this.get('password'), + oldpassword = this.get('oldpassword'), + newpassword = this.get('newpassword'), + SYSTEM_PROPERTIES=['metadata','created','modified','oldpassword','newpassword','type','activated','uuid'], + options={ + method:method, + endpoint:type + }; //update the entity - var self = this; - var data = {}; - var entityData = this.get(); - var password = this.get('password'); - var oldpassword = this.get('oldpassword'); - var newpassword = this.get('newpassword'); - var SYSTEM_PROPERTIES=['metadata','created','modified','oldpassword','newpassword','type','activated','uuid']; - //remove system specific properties - for (var item in entityData) { - if (SYSTEM_PROPERTIES.indexOf(item) !== -1) { - continue; - } - data[item] = entityData[item]; + console.log("entityId", entityId); + if (entityId) { + options.method = 'PUT'; + options.endpoint += '/' + entityId; } - var options = { - method:method, - endpoint:type, - body:data - }; + + //remove system-specific properties + Object + .keys(entityData) /* get the list of properties we have */ + .filter(function(key){ + return (SYSTEM_PROPERTIES.indexOf(key)===-1) /* remove system properties from the payload */ + }) + .forEach(function(key){ + data[key]= entityData[key]; + }); + options.body=data; + console.log(options.body); //save the entity first this._client.request(options, function (err, retdata) { //clear out pw info if present @@ -353,7 +355,7 @@ Usergrid.Entity.prototype.getEntityId = function (entity) { if (isUUID(entity.get('uuid'))) { id = entity.get('uuid'); } else { - if (type === 'users') { + if (this.get("type") === 'users') { id = entity.get('username'); } else if (entity.get('name')) { id = entity.get('name');