usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [01/51] [abbrv] Revert "updating with the lastest from usergrid-javascript-sdk"
Date Thu, 16 Jan 2014 17:29:57 GMT
Updated Branches:
  refs/heads/USERGRID-2771-graph-edges [created] 667184985
  refs/heads/USERGRID-2862-limitfix [created] b2a48c35f
  refs/heads/master e2ee790de -> 52172132b
  refs/heads/mergebranch [created] e482adbe9
  refs/heads/mergebranch-2 [created] 8339866ff
  refs/heads/two-dot-o ce2bfd82d -> df272cb6e
  refs/pull/1/head 214d546f9 -> 6dfdaef50 (forced update)
  refs/pull/1/merge [deleted] 712b393b4
  refs/pull/10/head [created] 29b354686
  refs/pull/11/head [created] 348f62ca8
  refs/pull/12/head [created] 4b58a3d8b
  refs/pull/13/head [created] f0974e754
  refs/pull/14/head [created] 8a3489ef6
  refs/pull/14/merge [created] a750c0a3d
  refs/pull/15/head [created] ff183bd12
  refs/pull/15/merge [created] 0060a7956
  refs/pull/16/head [created] 89d42887d
  refs/pull/17/head [created] 17eb8e79d
  refs/pull/18/head [created] 265d7dfed
  refs/pull/18/merge [created] 5e631c3cd
  refs/pull/19/head [created] 3fff2966c
  refs/pull/19/merge [created] 304165b5e
  refs/pull/2/head [created] 0d4fcfd8e
  refs/pull/20/head [created] 5c8ccb460
  refs/pull/21/head [created] 4def2d7ec
  refs/pull/22/head [created] d3cda2568
  refs/pull/23/head [created] b2a48c35f
  refs/pull/24/head [created] 014531eba
  refs/pull/24/merge [created] 0512dbfc2
  refs/pull/25/head [created] 609570e1a
  refs/pull/26/head [created] 89b9f502a
  refs/pull/27/head [created] 46dbb163e
  refs/pull/27/merge [created] c8c995257
  refs/pull/28/head [created] bb52e1c2c
  refs/pull/3/head [created] 60cd8e5a6
  refs/pull/4/head [created] 4914785fd
  refs/pull/5/head [created] c6ea35603
  refs/pull/6/head [created] 2463f5051
  refs/pull/7/head [created] 1d50c4489
  refs/pull/8/head [created] 51622166e
  refs/pull/9/head [created] b5d5ebb74
Updated Tags:  refs/tags/0.0.26r1 [created] 1d881241b
  refs/tags/0.0.27.r1 [created] 2fc7c5d55
  refs/tags/0.0.27.r2 [created] 9ca8cb5ea
  refs/tags/0.0.28.r1 [created] 3e768a452
  refs/tags/0.0.29r1 [created] 8581a17b1
  refs/tags/0.0.31r1 [created] 912de6309
  refs/tags/0.0.31r2 [created] 62653971d
  refs/tags/0.0.32r1 [created] dcb860d19
  refs/tags/0.0.32r2 [created] 8c432168a
  refs/tags/0.0.32r3 [created] 165a2e63c
  refs/tags/0.0.33r1 [created] 2991b73cf
  refs/tags/0.0.35r1 [created] 8413c5ec6
  refs/tags/0.0.35r2 [created] 553ea5741
  refs/tags/0.0.36.r3 [created] 6afd19288
  refs/tags/0.0.36.r4 [created] 2f355815a
  refs/tags/0.0.36.r5 [created] 27d4450cb
  refs/tags/0.0.36r1 [created] 8ddd81bab
  refs/tags/0.0.36r2 [created] 986c1cb60
  refs/tags/0.0.40.r1 [created] 9e8973c4c
  refs/tags/0.0.40.r2 [created] 52ca54ed5
  refs/tags/usergrid-0.0.26 [created] 730db400b
  refs/tags/usergrid-0.0.26.1 [created] 69a81e507
  refs/tags/usergrid-0.0.27.1 [created] 6699208cf
  refs/tags/v0.0.23.r2 [created] f1787008e
  refs/tags/v20130502-1300 [created] c8ce8f67d


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4def2d7e/sdks/html5-javascript/usergrid.min.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/usergrid.min.js b/sdks/html5-javascript/usergrid.min.js
index 26925c8..edcdb4a 100644
--- a/sdks/html5-javascript/usergrid.min.js
+++ b/sdks/html5-javascript/usergrid.min.js
@@ -1,2 +1 @@
-(function(){var name="Usergrid",global=global||this,overwrittenName=global[name];var AUTH_CLIENT_ID="CLIENT_ID";var AUTH_APP_USER="APP_USER";var AUTH_NONE="NONE";if("undefined"===typeof console){global.console={log:function(){},warn:function(){},error:function(){},dir:function(){}}}function Usergrid(){}Usergrid.Client=function(options){this.URI=options.URI||"https://api.usergrid.com";if(options.orgName){this.set("orgName",options.orgName)}if(options.appName){this.set("appName",options.appName)}if(options.appVersion){this.set("appVersion",options.appVersion)}this.authType=options.authType||AUTH_NONE;this.clientId=options.clientId;this.clientSecret=options.clientSecret;this.setToken(options.token||null);this.buildCurl=options.buildCurl||false;this.logging=options.logging||false;this._callTimeout=options.callTimeout||3e4;this._callTimeoutCallback=options.callTimeoutCallback||null;this.logoutCallback=options.logoutCallback||null};Usergrid.Client.prototype._request_node=function(options,
 callback){global.request=global.request||require("request");var request=global.request;var self=this;var method=options.method||"GET";var endpoint=options.endpoint;var body=options.body||{};var qs=options.qs||{};var mQuery=options.mQuery||false;var orgName=this.get("orgName");var appName=this.get("appName");if(!mQuery&&!orgName&&!appName){if(typeof this.logoutCallback==="function"){return this.logoutCallback(true,"no_org_or_app_name_specified")}}if(mQuery){uri=this.URI+"/"+endpoint}else{uri=this.URI+"/"+orgName+"/"+appName+"/"+endpoint}if(this.authType===AUTH_CLIENT_ID){qs.client_id=this.clientId;qs.client_secret=this.clientSecret}else if(this.authType===AUTH_APP_USER){qs.access_token=self.getToken()}if(this.logging){console.log("calling: "+method+" "+uri)}this._start=(new Date).getTime();var callOptions={method:method,uri:uri,json:body,qs:qs};request(callOptions,function(err,r,data){if(self.buildCurl){options.uri=r.request.uri.href;self.buildCurlCall(options)}self._end=(new Date).g
 etTime();if(r.statusCode===200){if(self.logging){console.log("success (time: "+self.calcTimeDiff()+"): "+method+" "+uri)}callback(err,data)}else{err=true;if(r.error==="auth_expired_session_token"||r.error==="auth_missing_credentials"||r.error=="auth_unverified_oath"||r.error==="expired_token"||r.error==="unauthorized"||r.error==="auth_invalid"){var error=r.body.error;var errorDesc=r.body.error_description;if(self.logging){console.log("Error ("+r.statusCode+")("+error+"): "+errorDesc)}if(typeof self.logoutCallback==="function"){self.logoutCallback(err,data)}else if(typeof callback==="function"){callback(err,data)}}else{var error=r.body.error;var errorDesc=r.body.error_description;if(self.logging){console.log("Error ("+r.statusCode+")("+error+"): "+errorDesc)}if(typeof callback==="function"){callback(err,data)}}}})};Usergrid.Client.prototype._request_xhr=function(options,callback){var self=this;var method=options.method||"GET";var endpoint=options.endpoint;var body=options.body||{};va
 r qs=options.qs||{};var mQuery=options.mQuery||false;var orgName=this.get("orgName");var appName=this.get("appName");if(!mQuery&&!orgName&&!appName){if(typeof this.logoutCallback==="function"){return this.logoutCallback(true,"no_org_or_app_name_specified")}}var uri;if(mQuery){uri=this.URI+"/"+endpoint}else{uri=this.URI+"/"+orgName+"/"+appName+"/"+endpoint}if(self.getToken()){qs.access_token=self.getToken()}var encoded_params=encodeParams(qs);if(encoded_params){uri+="?"+encoded_params}body=JSON.stringify(body);var xhr=new XMLHttpRequest;xhr.open(method,uri,true);if(body){xhr.setRequestHeader("Content-Type","application/json");xhr.setRequestHeader("Accept","application/json")}xhr.onerror=function(response){self._end=(new Date).getTime();if(self.logging){console.log("success (time: "+self.calcTimeDiff()+"): "+method+" "+uri)}if(self.logging){console.log("Error: API call failed at the network level.")}clearTimeout(timeout);var err=true;if(typeof callback==="function"){callback(err,respo
 nse)}};xhr.onload=function(response){self._end=(new Date).getTime();if(self.logging){console.log("success (time: "+self.calcTimeDiff()+"): "+method+" "+uri)}clearTimeout(timeout);try{response=JSON.parse(xhr.responseText)}catch(e){response={error:"unhandled_error",error_description:xhr.responseText};xhr.status=xhr.status===200?400:xhr.status;console.error(e)}if(xhr.status!=200){var error=response.error;var error_description=response.error_description;if(self.logging){console.log("Error ("+xhr.status+")("+error+"): "+error_description)}if(error=="auth_expired_session_token"||error=="auth_missing_credentials"||error=="auth_unverified_oath"||error=="expired_token"||error=="unauthorized"||error=="auth_invalid"){if(typeof self.logoutCallback==="function"){return self.logoutCallback(true,response)}}if(typeof callback==="function"){callback(true,response)}}else{if(typeof callback==="function"){callback(false,response)}}};var timeout=setTimeout(function(){xhr.abort();if(self._callTimeoutCall
 back==="function"){self._callTimeoutCallback("API CALL TIMEOUT")}else{self.callback("API CALL TIMEOUT")}},self._callTimeout);if(this.logging){console.log("calling: "+method+" "+uri)}if(this.buildCurl){var curlOptions={uri:uri,body:body,method:method};this.buildCurlCall(curlOptions)}this._start=(new Date).getTime();xhr.send(body)};Usergrid.Client.prototype.request=function(options,callback){if("undefined"!==typeof window){Usergrid.Client.prototype._request_xhr.apply(this,arguments)}else{Usergrid.Client.prototype._request_node.apply(this,arguments)}};Usergrid.Client.prototype.buildAssetURL=function(uuid){var self=this;var qs={};var assetURL=this.URI+"/"+this.orgName+"/"+this.appName+"/assets/"+uuid+"/data";if(self.getToken()){qs.access_token=self.getToken()}var encoded_params=encodeParams(qs);if(encoded_params){assetURL+="?"+encoded_params}return assetURL};Usergrid.Client.prototype.createGroup=function(options,callback){var getOnExist=options.getOnExist||false;options={path:options.pa
 th,client:this,data:options};var group=new Usergrid.Group(options);group.fetch(function(err,data){var okToSave=err&&"service_resource_not_found"===data.error||"no_name_specified"===data.error||"null_pointer"===data.error||!err&&getOnExist;if(okToSave){group.save(function(err,data){if(typeof callback==="function"){callback(err,group)}})}else{if(typeof callback==="function"){callback(err,group)}}})};Usergrid.Client.prototype.createEntity=function(options,callback){var getOnExist=options.getOnExist||false;options={client:this,data:options};var entity=new Usergrid.Entity(options);entity.fetch(function(err,data){var okToSave=err&&"service_resource_not_found"===data.error||"no_name_specified"===data.error||"null_pointer"===data.error||!err&&getOnExist;if(okToSave){entity.set(options.data);entity.save(function(err,data){if(typeof callback==="function"){callback(err,entity,data)}})}else{if(typeof callback==="function"){callback(err,entity,data)}}})};Usergrid.Client.prototype.getEntity=funct
 ion(options,callback){options={client:this,data:options};var entity=new Usergrid.Entity(options);entity.fetch(function(err,data){if(typeof callback==="function"){callback(err,entity,data)}})};Usergrid.Client.prototype.restoreEntity=function(serializedObject){var data=JSON.parse(serializedObject);options={client:this,data:data};var entity=new Usergrid.Entity(options);return entity};Usergrid.Client.prototype.createCollection=function(options,callback){options.client=this;var collection=new Usergrid.Collection(options,function(err,data){if(typeof callback==="function"){callback(err,collection,data)}})};Usergrid.Client.prototype.restoreCollection=function(serializedObject){var data=JSON.parse(serializedObject);data.client=this;var collection=new Usergrid.Collection(data);return collection};Usergrid.Client.prototype.getFeedForUser=function(username,callback){var options={method:"GET",endpoint:"users/"+username+"/feed"};this.request(options,function(err,data){if(typeof callback==="functio
 n"){if(err){callback(err)}else{callback(err,data,data.entities)}}})};Usergrid.Client.prototype.createUserActivity=function(user,options,callback){options.type="users/"+user+"/activities";options={client:this,data:options};var entity=new Usergrid.Entity(options);entity.save(function(err,data){if(typeof callback==="function"){callback(err,entity)}})};Usergrid.Client.prototype.createUserActivityWithEntity=function(user,content,callback){var username=user.get("username");var options={actor:{displayName:username,uuid:user.get("uuid"),username:username,email:user.get("email"),picture:user.get("picture"),image:{duration:0,height:80,url:user.get("picture"),width:80}},verb:"post",content:content};this.createUserActivity(username,options,callback)};Usergrid.Client.prototype.calcTimeDiff=function(){var seconds=0;var time=this._end-this._start;try{seconds=(time/10/60).toFixed(2)}catch(e){return 0}return seconds};Usergrid.Client.prototype.setToken=function(token){this.set("token",token)};Usergri
 d.Client.prototype.getToken=function(){return this.get("token")};Usergrid.Client.prototype.setObject=function(key,value){if(value){value=JSON.stringify(value)}this.set(key,value)};Usergrid.Client.prototype.set=function(key,value){var keyStore="apigee_"+key;this[key]=value;if(typeof Storage!=="undefined"){if(value){localStorage.setItem(keyStore,value)}else{localStorage.removeItem(keyStore)}}};Usergrid.Client.prototype.getObject=function(key){return JSON.parse(this.get(key))};Usergrid.Client.prototype.get=function(key){var keyStore="apigee_"+key;if(this[key]){return this[key]}else if(typeof Storage!=="undefined"){return localStorage.getItem(keyStore)}return null};Usergrid.Client.prototype.signup=function(username,password,email,name,callback){var self=this;var options={type:"users",username:username,password:password,email:email,name:name};this.createEntity(options,callback)};Usergrid.Client.prototype.login=function(username,password,callback){var self=this;var options={method:"POST",
 endpoint:"token",body:{username:username,password:password,grant_type:"password"}};this.request(options,function(err,data){var user={};if(err&&self.logging){console.log("error trying to log user in")}else{options={client:self,data:data.user};user=new Usergrid.Entity(options);self.setToken(data.access_token)}if(typeof callback==="function"){callback(err,data,user)}})};Usergrid.Client.prototype.reAuthenticateLite=function(callback){var self=this;var options={method:"GET",endpoint:"management/me",mQuery:true};this.request(options,function(err,response){if(err&&self.logging){console.log("error trying to re-authenticate user")}else{self.setToken(response.access_token)}if(typeof callback==="function"){callback(err)}})};Usergrid.Client.prototype.reAuthenticate=function(email,callback){var self=this;var options={method:"GET",endpoint:"management/users/"+email,mQuery:true};this.request(options,function(err,response){var organizations={};var applications={};var user={};var data;if(err&&self.l
 ogging){console.log("error trying to full authenticate user")}else{data=response.data;self.setToken(data.token);self.set("email",data.email);localStorage.setItem("accessToken",data.token);localStorage.setItem("userUUID",data.uuid);localStorage.setItem("userEmail",data.email);var userData={username:data.username,email:data.email,name:data.name,uuid:data.uuid};options={client:self,data:userData};user=new Usergrid.Entity(options);organizations=data.organizations;var org="";try{var existingOrg=self.get("orgName");org=organizations[existingOrg]?organizations[existingOrg]:organizations[Object.keys(organizations)[0]];self.set("orgName",org.name)}catch(e){err=true;if(self.logging){console.log("error selecting org")}}applications=self.parseApplicationsArray(org);self.selectFirstApp(applications);self.setObject("organizations",organizations);self.setObject("applications",applications)}if(typeof callback==="function"){callback(err,data,user,organizations,applications)}})};Usergrid.Client.proto
 type.loginFacebook=function(facebookToken,callback){var self=this;var options={method:"GET",endpoint:"auth/facebook",qs:{fb_access_token:facebookToken}};this.request(options,function(err,data){var user={};if(err&&self.logging){console.log("error trying to log user in")}else{var options={client:self,data:data.user};user=new Usergrid.Entity(options);self.setToken(data.access_token)}if(typeof callback==="function"){callback(err,data,user)}})};Usergrid.Client.prototype.getLoggedInUser=function(callback){if(!this.getToken()){callback(true,null,null)}else{var self=this;var options={method:"GET",endpoint:"users/me"};this.request(options,function(err,data){if(err){if(self.logging){console.log("error trying to log user in")}if(typeof callback==="function"){callback(err,data,null)}}else{var options={client:self,data:data.entities[0]};var user=new Usergrid.Entity(options);if(typeof callback==="function"){callback(err,data,user)}}})}};Usergrid.Client.prototype.isLoggedIn=function(){if(this.getT
 oken()&&this.getToken()!="null"){return true}return false};Usergrid.Client.prototype.logout=function(){this.setToken(null)};Usergrid.Client.prototype.buildCurlCall=function(options){var curl="curl";var method=(options.method||"GET").toUpperCase();var body=options.body||{};var uri=options.uri;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+=" "+uri;if("undefined"!==typeof window){body=JSON.stringify(body)}if(body!=='"{}"'&&method!=="GET"&&method!=="DELETE"){curl+=" -d '"+body+"'"}console.log(curl);return curl};Usergrid.Client.prototype.getDisplayImage=function(email,picture,size){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"}}catch(e){return"https://apigee.com/usergrid/
 images/user_profile.png"}};Usergrid.Entity=function(options){if(options){this._data=options.data||{};this._client=options.client||{}}};Usergrid.Entity.prototype.serialize=function(){return JSON.stringify(this._data)};Usergrid.Entity.prototype.get=function(field){if(field){return this._data[field]}else{return this._data}};Usergrid.Entity.prototype.set=function(key,value){if(typeof key==="object"){for(var field in key){this._data[field]=key[field]}}else if(typeof key==="string"){if(value===null){delete this._data[key]}else{this._data[key]=value}}else{this._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;var data={};var entityData=this.get();for(var item in entityData){if(item==="metadata"||item==="created"||item==="modified"||item==="type"||item==="activated"||item==="uuid"){continue}data[item]=entityData[item]}var options={method:method,endpoint:t
 ype,body:data};this._client.request(options,function(err,retdata){if(err&&self._client.logging){console.log("could not save entity");if(typeof callback==="function"){return callback(err,retdata,self)}}else{if(retdata.entities){if(retdata.entities.length){var entity=retdata.entities[0];self.set(entity);var path=retdata.path;while(path.substring(0,1)==="/"){path=path.substring(1)}self.set("type",path)}}var needPasswordChange=(self.get("type")==="user"||self.get("type")==="users")&&entityData.oldpassword&&entityData.newpassword;if(needPasswordChange){var pwdata={};pwdata.oldpassword=entityData.oldpassword;pwdata.newpassword=entityData.newpassword;var options={method:"PUT",endpoint:type+"/password",body:pwdata};self._client.request(options,function(err,data){if(err&&self._client.logging){console.log("could not update user")}self.set("oldpassword",null);self.set("newpassword",null);if(typeof callback==="function"){callback(err,data,self)}})}else if(typeof callback==="function"){callback(
 err,retdata,self)}}})};Usergrid.Entity.prototype.fetch=function(callback){var type=this.get("type");var self=this;try{if(type===undefined){throw"cannot fetch entity, no entity type specified"}else if(this.get("uuid")){type+="/"+this.get("uuid")}else if(type==="users"&&this.get("username")){type+="/"+this.get("username")}else if(this.get("name")){type+="/"+encodeURIComponent(this.get("name"))}else if(typeof callback==="function"){throw"no_name_specified"}}catch(e){if(self._client.logging){console.log(e)}return callback(true,{error:e},self)}var options={method:"GET",endpoint:type};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("could not get entity")}else{if(data.user){self.set(data.user);self._json=JSON.stringify(data.user,null,2)}else if(data.entities){if(data.entities.length){var entity=data.entities[0];self.set(entity)}}}if(typeof callback==="function"){callback(err,data,self)}})};Usergrid.Entity.prototype.destroy=function(callback){var s
 elf=this;var type=this.get("type");if(isUUID(this.get("uuid"))){type+="/"+this.get("uuid")}else{if(typeof callback==="function"){var error="Error trying to delete object - no uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}}var options={method:"DELETE",endpoint:type};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be deleted")}else{self.set(null)}if(typeof callback==="function"){callback(err,data)}})};Usergrid.Entity.prototype.connect=function(connection,entity,callback){var self=this;var error;var connecteeType=entity.get("type");var connectee=this.getEntityId(entity);if(!connectee){if(typeof callback==="function"){error="Error trying to delete object - no uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}return}var connectorType=this.get("type");var connector=this.getEntityId(this);if(!connector){if(typeof callback==="function"){error="Error in connect - no
  uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}return}var endpoint=connectorType+"/"+connector+"/"+connection+"/"+connecteeType+"/"+connectee;var options={method:"POST",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be connected")}if(typeof callback==="function"){callback(err,data)}})};Usergrid.Entity.prototype.getEntityId=function(entity){var id=false;if(isUUID(entity.get("uuid"))){id=entity.get("uuid")}else{if(type==="users"){id=entity.get("username")}else if(entity.get("name")){id=entity.get("name")}}return id};Usergrid.Entity.prototype.getConnections=function(connection,callback){var self=this;var connectorType=this.get("type");var connector=this.getEntityId(this);if(!connector){if(typeof callback==="function"){var error="Error in getConnections - no uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}return}var endpoint=connectorType+
 "/"+connector+"/"+connection+"/";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be connected")}self[connection]={};var length=data.entities.length;for(var i=0;i<length;i++){if(data.entities[i].type==="user"){self[connection][data.entities[i].username]=data.entities[i]}else{self[connection][data.entities[i].name]=data.entities[i]}}if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getGroups=function(callback){var self=this;var endpoint="users"+"/"+this.get("uuid")+"/groups";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be connected")}self.groups=data.entities;if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getActivities=function(callback){var self=this;var endpoint=this.get("type")+"
 /"+this.get("uuid")+"/activities";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be connected")}for(var entity in data.entities){data.entities[entity].createdDate=new Date(data.entities[entity].created).toUTCString()}self.activities=data.entities;if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getFollowing=function(callback){var self=this;var endpoint="users"+"/"+this.get("uuid")+"/following";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("could not get user following")}for(var entity in data.entities){data.entities[entity].createdDate=new Date(data.entities[entity].created).toUTCString();var image=self._client.getDisplayImage(data.entities[entity].email,data.entities[entity].picture);data.entities[entity]._portal_image_icon=image}self.following
 =data.entities;if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getFollowers=function(callback){var self=this;var endpoint="users"+"/"+this.get("uuid")+"/followers";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("could not get user followers")}for(var entity in data.entities){data.entities[entity].createdDate=new Date(data.entities[entity].created).toUTCString();var image=self._client.getDisplayImage(data.entities[entity].email,data.entities[entity].picture);data.entities[entity]._portal_image_icon=image}self.followers=data.entities;if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getRoles=function(callback){var self=this;var endpoint=this.get("type")+"/"+this.get("uuid")+"/roles";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){co
 nsole.log("could not get user roles")}self.roles=data.entities;if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.getPermissions=function(callback){var self=this;var endpoint=this.get("type")+"/"+this.get("uuid")+"/permissions";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("could not get user permissions")}var permissions=[];if(data.data){var perms=data.data;var count=0;for(var i in perms){count++;var perm=perms[i];var parts=perm.split(":");var ops_part="";var path_part=parts[0];if(parts.length>1){ops_part=parts[0];path_part=parts[1]}ops_part.replace("*","get,post,put,delete");var ops=ops_part.split(",");var ops_object={};ops_object.get="no";ops_object.post="no";ops_object.put="no";ops_object.delete="no";for(var j in ops){ops_object[ops[j]]="yes"}permissions.push({operations:ops_object,path:path_part,perm:perm})}}self.permissions=permissions;if(typeof
  callback==="function"){callback(err,data,data.entities)}})};Usergrid.Entity.prototype.disconnect=function(connection,entity,callback){var self=this;var error;var connecteeType=entity.get("type");var connectee=this.getEntityId(entity);if(!connectee){if(typeof callback==="function"){error="Error trying to delete object - no uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}return}var connectorType=this.get("type");var connector=this.getEntityId(this);if(!connector){if(typeof callback==="function"){error="Error in connect - no uuid specified.";if(self._client.logging){console.log(error)}callback(true,error)}return}var endpoint=connectorType+"/"+connector+"/"+connection+"/"+connecteeType+"/"+connectee;var options={method:"DELETE",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("entity could not be disconnected")}if(typeof callback==="function"){callback(err,data)}})};Usergrid.Collection=functio
 n(options,callback){if(options){this._client=options.client;this._type=options.type;this.qs=options.qs||{};this._list=options.list||[];this._iterator=options.iterator||-1;this._previous=options.previous||[];this._next=options.next||null;this._cursor=options.cursor||null;if(options.list){var count=options.list.length;for(var i=0;i<count;i++){var entity=this._client.restoreEntity(options.list[i]);this._list[i]=entity}}}if(callback){this.fetch(callback)}};Usergrid.Collection.prototype.serialize=function(){var data={};data.type=this._type;data.qs=this.qs;data.iterator=this._iterator;data.previous=this._previous;data.next=this._next;data.cursor=this._cursor;this.resetEntityPointer();var i=0;data.list=[];while(this.hasNextEntity()){var entity=this.getNextEntity();data.list[i]=entity.serialize();i++}data=JSON.stringify(data);return data};Usergrid.Collection.prototype.addCollection=function(collectionName,options,callback){self=this;options.client=this._client;var collection=new Usergrid.Co
 llection(options,function(err,data){if(typeof callback==="function"){collection.resetEntityPointer();while(collection.hasNextEntity()){var user=collection.getNextEntity();var email=user.get("email");var image=self._client.getDisplayImage(user.get("email"),user.get("picture"));user._portal_image_icon=image}self[collectionName]=collection;callback(err,collection)}})};Usergrid.Collection.prototype.fetch=function(callback){var self=this;var qs=this.qs;if(this._cursor){qs.cursor=this._cursor}else{delete qs.cursor}var options={method:"GET",endpoint:this._type,qs:this.qs};this._client.request(options,function(err,data){if(err&&self._client.logging){console.log("error getting collection")}else{var cursor=data.cursor||null;self.saveCursor(cursor);if(data.entities){self.resetEntityPointer();var count=data.entities.length;self._list=[];for(var i=0;i<count;i++){var uuid=data.entities[i].uuid;if(uuid){var entityData=data.entities[i]||{};self._baseType=data.entities[i].type;entityData.type=self._
 type;var entityOptions={type:self._type,client:self._client,uuid:uuid,data:entityData};var ent=new Usergrid.Entity(entityOptions);ent._json=JSON.stringify(entityData,null,2);var ct=self._list.length;self._list[ct]=ent}}}}if(typeof callback==="function"){callback(err,data)}})};Usergrid.Collection.prototype.addEntity=function(options,callback){var self=this;options.type=this._type;this._client.createEntity(options,function(err,entity){if(!err){var count=self._list.length;self._list[count]=entity}if(typeof callback==="function"){callback(err,entity)}})};Usergrid.Collection.prototype.addExistingEntity=function(entity){var count=this._list.length;this._list[count]=entity};Usergrid.Collection.prototype.destroyEntity=function(entity,callback){var self=this;entity.destroy(function(err,data){if(err){if(self._client.logging){console.log("could not destroy entity")}if(typeof callback==="function"){callback(err,data)}}else{self.fetch(callback)}});this.removeEntity(entity)};Usergrid.Collection.p
 rototype.removeEntity=function(entity){var uuid=entity.get("uuid");for(var key in this._list){var listItem=this._list[key];if(listItem.get("uuid")===uuid){return this._list.splice(key,1)}}return false};Usergrid.Collection.prototype.getEntityByUUID=function(uuid,callback){for(var key in this._list){var listItem=this._list[key];if(listItem.get("uuid")===uuid){return listItem}}var options={data:{type:this._type,uuid:uuid},client:this._client};var entity=new Usergrid.Entity(options);entity.fetch(callback)};Usergrid.Collection.prototype.getFirstEntity=function(){var count=this._list.length;if(count>0){return this._list[0]}return null};Usergrid.Collection.prototype.getLastEntity=function(){var count=this._list.length;if(count>0){return this._list[count-1]}return null};Usergrid.Collection.prototype.hasNextEntity=function(){var next=this._iterator+1;var hasNextElement=next>=0&&next<this._list.length;if(hasNextElement){return true}return false};Usergrid.Collection.prototype.getNextEntity=fun
 ction(){this._iterator++;var hasNextElement=this._iterator>=0&&this._iterator<this._list.length;if(hasNextElement){return this._list[this._iterator]}return false};Usergrid.Collection.prototype.hasPrevEntity=function(){var previous=this._iterator-1;var hasPreviousElement=previous>=0&&previous<this._list.length;if(hasPreviousElement){return true}return false};Usergrid.Collection.prototype.getPrevEntity=function(){this._iterator--;var hasPreviousElement=this._iterator>=0&&this._iterator<=this._list.length;if(hasPreviousElement){return this._list[this._iterator]}return false};Usergrid.Collection.prototype.resetEntityPointer=function(){this._iterator=-1};Usergrid.Collection.prototype.saveCursor=function(cursor){if(this._next!==cursor){this._next=cursor}};Usergrid.Collection.prototype.resetPaging=function(){this._previous=[];this._next=null;this._cursor=null};Usergrid.Collection.prototype.hasNextPage=function(){return this._next};Usergrid.Collection.prototype.getNextPage=function(callback
 ){if(this.hasNextPage()){this._previous.push(this._cursor);this._cursor=this._next;this._list=[];this.fetch(callback)}else{callback(true)}};Usergrid.Collection.prototype.hasPreviousPage=function(){return this._previous.length>0};Usergrid.Collection.prototype.getPreviousPage=function(callback){if(this.hasPreviousPage()){this._next=null;this._cursor=this._previous.pop();this._list=[];this.fetch(callback)}else{callback(true)}};Usergrid.Group=function(options,callback){this._path=options.path;this._list=[];this._client=options.client;this._data=options.data||{};this._data.type="groups"};Usergrid.Group.prototype=new Usergrid.Entity;Usergrid.Group.prototype.fetch=function(callback){var self=this;var groupEndpoint="groups/"+this._path;var memberEndpoint="groups/"+this._path+"/users";var groupOptions={method:"GET",endpoint:groupEndpoint};var memberOptions={method:"GET",endpoint:memberEndpoint};this._client.request(groupOptions,function(err,data){if(err){if(self._client.logging){console.log(
 "error getting group")}if(typeof callback==="function"){callback(err,data)}}else{if(data.entities){var groupData=data.entities[0];self._data=groupData||{};self._client.request(memberOptions,function(err,data){if(err&&self._client.logging){console.log("error getting group users")}else{if(data.entities){var count=data.entities.length;self._list=[];for(var i=0;i<count;i++){var uuid=data.entities[i].uuid;if(uuid){var entityData=data.entities[i]||{};var entityOptions={type:entityData.type,client:self._client,uuid:uuid,data:entityData};var entity=new Usergrid.Entity(entityOptions);self._list.push(entity)}}}}if(typeof callback==="function"){callback(err,data,self._list)}})}}})};Usergrid.Group.prototype.members=function(callback){if(typeof callback==="function"){callback(null,this._list)}};Usergrid.Group.prototype.add=function(options,callback){var self=this;options={method:"POST",endpoint:"groups/"+this._path+"/users/"+options.user.get("username")};this._client.request(options,function(err
 or,data){if(error){if(typeof callback==="function"){callback(error,data,data.entities)}}else{self.fetch(callback)}})};Usergrid.Group.prototype.remove=function(options,callback){var self=this;options={method:"DELETE",endpoint:"groups/"+this._path+"/users/"+options.user.get("username")};this._client.request(options,function(error,data){if(error){if(typeof callback==="function"){callback(error,data)}}else{self.fetch(callback)}})};Usergrid.Group.prototype.feed=function(callback){var self=this;var endpoint="groups/"+this._path+"/feed";var options={method:"GET",endpoint:endpoint};this._client.request(options,function(err,data){if(err&&self.logging){console.log("error trying to log user in")}if(typeof callback==="function"){callback(err,data,data.entities)}})};Usergrid.Group.prototype.createGroupActivity=function(options,callback){var user=options.user;options={client:this._client,data:{actor:{displayName:user.get("username"),uuid:user.get("uuid"),username:user.get("username"),email:user.g
 et("email"),picture:user.get("picture"),image:{duration:0,height:80,url:user.get("picture"),width:80}},verb:"post",content:options.content,type:"groups/"+this._path+"/activities"}};
-var entity=new Usergrid.Entity(options);entity.save(function(err,data){if(typeof callback==="function"){callback(err,entity)}})};function isUUID(uuid){var uuidValueRegex=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;if(!uuid){return false}return uuidValueRegex.test(uuid)}function encodeParams(params){var tail=[];var item=[];var i;if(params instanceof Array){for(i in params){item=params[i];if(item instanceof Array&&item.length>1){tail.push(item[0]+"="+encodeURIComponent(item[1]))}}}else{for(var key in params){if(params.hasOwnProperty(key)){var value=params[key];if(value instanceof Array){for(i in value){item=value[i];tail.push(key+"="+encodeURIComponent(item))}}else{tail.push(key+"="+encodeURIComponent(value))}}}}return tail.join("&")}Usergrid.SDK_VERSION="0.10.07";Usergrid.NODE_MODULE_VERSION=Usergrid.SDK_VERSION;global[name]={client:Usergrid.Client,entity:Usergrid.Entity,collection:Usergrid.Collection,group:Usergrid.Group,AUTH_CLIENT_ID:AUTH_CLIENT
 _ID,AUTH_APP_USER:AUTH_APP_USER,AUTH_NONE:AUTH_NONE};global[name].noConflict=function(){if(overwrittenName){global[name]=overwrittenName}return Usergrid}})();
\ No newline at end of file
+window.console=window.console||{};window.console.log=window.console.log||function(){};window.Usergrid=window.Usergrid||{};Usergrid=Usergrid||{};Usergrid.SDK_VERSION="0.10.07";Usergrid.Client=function(a){this.URI=a.URI||"https://api.usergrid.com";if(a.orgName){this.set("orgName",a.orgName)}if(a.appName){this.set("appName",a.appName)}this.buildCurl=a.buildCurl||false;this.logging=a.logging||false;this._callTimeout=a.callTimeout||30000;this._callTimeoutCallback=a.callTimeoutCallback||null;this.logoutCallback=a.logoutCallback||null};Usergrid.Client.prototype.request=function(p,j){var o=this;var a=p.method||"GET";var n=p.endpoint;var c=p.body||{};var f=p.qs||{};var k=p.mQuery||false;var e=this.get("orgName");var d=this.get("appName");if(!k&&!e&&!d){if(typeof(this.logoutCallback)==="function"){return this.logoutCallback(true,"no_org_or_app_name_specified")}}if(k){var b=this.URI+"/"+n}else{var b=this.URI+"/"+e+"/"+d+"/"+n}if(o.getToken()){f.access_token=o.getToken()}var m=encodeParams(f);i
 f(m){b+="?"+m}c=JSON.stringify(c);var l=new XMLHttpRequest();l.open(a,b,true);if(c){l.setRequestHeader("Content-Type","application/json");l.setRequestHeader("Accept","application/json")}l.onerror=function(q){o._end=new Date().getTime();if(o.logging){console.log("success (time: "+o.calcTimeDiff()+"): "+a+" "+b)}if(o.logging){console.log("Error: API call failed at the network level.")}clearTimeout(h);var r=true;if(typeof(j)==="function"){j(r,q)}};l.onload=function(q){o._end=new Date().getTime();if(o.logging){console.log("success (time: "+o.calcTimeDiff()+"): "+a+" "+b)}clearTimeout(h);q=JSON.parse(l.responseText);if(l.status!=200){var r=q.error;var s=q.error_description;if(o.logging){console.log("Error ("+l.status+")("+r+"): "+s)}if((r=="auth_expired_session_token")||(r=="auth_missing_credentials")||(r=="auth_unverified_oath")||(r=="expired_token")||(r=="unauthorized")||(r=="auth_invalid")){if(typeof(o.logoutCallback)==="function"){return o.logoutCallback(true,q)}}if(typeof(j)==="func
 tion"){j(true,q)}}else{if(typeof(j)==="function"){j(false,q)}}};var h=setTimeout(function(){l.abort();if(o._callTimeoutCallback==="function"){o._callTimeoutCallback("API CALL TIMEOUT")}else{o.callback("API CALL TIMEOUT")}},o._callTimeout);if(this.logging){console.log("calling: "+a+" "+b)}if(this.buildCurl){var g={uri:b,body:c,method:a};this.buildCurlCall(g)}this._start=new Date().getTime();l.send(c)};Usergrid.Client.prototype.createGroup=function(a,d){var c=a.getOnExist||false;var a={path:a.path,client:this,data:a};var b=new Usergrid.Group(a);b.fetch(function(f,g){var e=(f&&"service_resource_not_found"===g.error||"no_name_specified"===g.error||"null_pointer"===g.error)||(!f&&c);if(e){b.save(function(h,j){if(typeof(d)==="function"){d(h,b)}})}else{if(typeof(d)==="function"){d(f,b)}}})};Usergrid.Client.prototype.createEntity=function(b,d){var c=b.getOnExist||false;var b={client:this,data:b};var a=new Usergrid.Entity(b);a.fetch(function(f,g){var e=(f&&"service_resource_not_found"===g.er
 ror||"no_name_specified"===g.error||"null_pointer"===g.error)||(!f&&c);if(e){a.set(b.data);a.save(function(h,j){if(typeof(d)==="function"){d(h,a,j)}})}else{if(typeof(d)==="function"){d(f,a,g)}}})};Usergrid.Client.prototype.getEntity=function(b,c){var b={client:this,data:b};var a=new Usergrid.Entity(b);a.fetch(function(d,e){if(typeof(c)==="function"){c(d,a,e)}})};Usergrid.Client.prototype.restoreEntity=function(c){var d=JSON.parse(c);var b={client:this,data:d};var a=new Usergrid.Entity(b);return a};Usergrid.Client.prototype.createCollection=function(a,c){a.client=this;var b=new Usergrid.Collection(a,function(d,e){if(typeof(c)==="function"){c(d,b,e)}})};Usergrid.Client.prototype.restoreCollection=function(a){var b=JSON.parse(a);b.client=this;var c=new Usergrid.Collection(b);return c};Usergrid.Client.prototype.getFeedForUser=function(c,b){var a={method:"GET",endpoint:"users/"+c+"/feed"};this.request(a,function(d,e){if(typeof(b)==="function"){if(d){b(d)}else{b(d,e,e.entities)}}})};Userg
 rid.Client.prototype.createUserActivity=function(b,c,d){c.type="users/"+b+"/activities";var c={client:this,data:c};var a=new Usergrid.Entity(c);a.save(function(e,f){if(typeof(d)==="function"){d(e,a)}})};Usergrid.Client.prototype.createUserActivityWithEntity=function(a,c,e){var d=a.get("username");var b={actor:{displayName:d,uuid:a.get("uuid"),username:d,email:a.get("email"),picture:a.get("picture"),image:{duration:0,height:80,url:a.get("picture"),width:80},},verb:"post",content:c};this.createUserActivity(d,b,e)};Usergrid.Client.prototype.calcTimeDiff=function(){var c=0;var b=this._end-this._start;try{c=((b/10)/60).toFixed(2)}catch(a){return 0}return c};Usergrid.Client.prototype.setToken=function(a){this.set("token",a)};Usergrid.Client.prototype.getToken=function(){return this.get("token")};Usergrid.Client.prototype.setObject=function(a,b){if(b){b=JSON.stringify(b)}this.set(a,b)};Usergrid.Client.prototype.set=function(b,c){var a="apigee_"+b;this[b]=c;if(typeof(Storage)!=="undefined")
 {if(c){localStorage.setItem(a,c)}else{localStorage.removeItem(a)}}};Usergrid.Client.prototype.getObject=function(a){return JSON.parse(this.get(a))};Usergrid.Client.prototype.get=function(b){var a="apigee_"+b;if(this[b]){return this[b]}else{if(typeof(Storage)!=="undefined"){return localStorage.getItem(a)}}return null};Usergrid.Client.prototype.signup=function(g,e,d,c,f){var a=this;var b={type:"users",username:g,password:e,email:d,name:c};this.createEntity(b,f)};Usergrid.Client.prototype.login=function(e,c,d){var a=this;var b={method:"POST",endpoint:"token",body:{username:e,password:c,grant_type:"password"}};this.request(b,function(h,j){var f={};if(h&&a.logging){console.log("error trying to log user in")}else{var g={client:a,data:j.user};f=new Usergrid.Entity(g);a.setToken(j.access_token)}if(typeof(d)==="function"){d(h,j,f)}})};Usergrid.Client.prototype.reAuthenticateLite=function(c){var a=this;var b={method:"GET",endpoint:"management/me",mQuery:true};this.request(b,function(e,d){if(e
 &&a.logging){console.log("error trying to re-authenticate user")}else{a.setToken(d.access_token)}if(typeof(c)==="function"){c(e)}})};Usergrid.Client.prototype.reAuthenticate=function(c,d){var a=this;var b={method:"GET",endpoint:"management/users/"+c,mQuery:true};this.request(b,function(k,l){var f={};var j={};var m={};if(k&&a.logging){console.log("error trying to full authenticate user")}else{var n=l.data;a.setToken(n.token);a.set("email",n.email);localStorage.setItem("accessToken",n.token);localStorage.setItem("userUUID",n.uuid);localStorage.setItem("userEmail",n.email);var g={username:n.username,email:n.email,name:n.name,uuid:n.uuid};var q={client:a,data:g};m=new Usergrid.Entity(q);f=n.organizations;var p="";try{var h=a.get("orgName");p=(f[h])?f[h]:f[Object.keys(f)[0]];a.set("orgName",p.name)}catch(o){k=true;if(a.logging){console.log("error selecting org")}}j=a.parseApplicationsArray(p);a.selectFirstApp(j);a.setObject("organizations",f);a.setObject("applications",j)}if(typeof(d)===
 "function"){d(k,n,m,f,j)}})};Usergrid.Client.prototype.loginFacebook=function(a,d){var b=this;var c={method:"GET",endpoint:"auth/facebook",qs:{fb_access_token:a}};this.request(c,function(g,h){var e={};if(g&&b.logging){console.log("error trying to log user in")}else{var f={client:b,data:h.user};e=new Usergrid.Entity(f);b.setToken(h.access_token)}if(typeof(d)==="function"){d(g,h,e)}})};Usergrid.Client.prototype.getLoggedInUser=function(c){if(!this.getToken()){c(true,null,null)}else{var a=this;var b={method:"GET",endpoint:"users/me"};this.request(b,function(f,g){if(f){if(a.logging){console.log("error trying to log user in")}if(typeof(c)==="function"){c(f,g,null)}}else{var e={client:a,data:g.entities[0]};var d=new Usergrid.Entity(e);if(typeof(c)==="function"){c(f,g,d)}}})}};Usergrid.Client.prototype.isLoggedIn=function(){if(this.getToken()){return true}return false};Usergrid.Client.prototype.logout=function(){this.setToken(null)};Usergrid.Client.prototype.buildCurlCall=function(c){var b
 ="curl";var e=(c.method||"GET").toUpperCase();var a=c.body||{};var d=c.uri;if(e==="POST"){b+=" -X POST"}else{if(e==="PUT"){b+=" -X PUT"}else{if(e==="DELETE"){b+=" -X DELETE"}else{b+=" -X GET"}}}b+=" "+d;if(a!=='"{}"'&&e!=="GET"&&e!=="DELETE"){b+=" -d '"+a+"'"}console.log(b);return b};Usergrid.Client.prototype.getDisplayImage=function(a,c,b){try{if(c){return c}var b=b||50;if(a.length){return"https://secure.gravatar.com/avatar/"+MD5(a)+"?s="+b+encodeURI("&d=https://apigee.com/usergrid/images/user_profile.png")}else{return"https://apigee.com/usergrid/images/user_profile.png"}}catch(d){return"https://apigee.com/usergrid/images/user_profile.png"}};Usergrid.Entity=function(a){if(a){this._data=a.data||{};this._client=a.client||{}}};Usergrid.Entity.prototype.serialize=function(){return JSON.stringify(this._data)};Usergrid.Entity.prototype.get=function(a){if(a){return this._data[a]}else{return this._data}};Usergrid.Entity.prototype.set=function(a,b){if(typeof a==="object"){for(var c in a){th
 is._data[c]=a[c]}}else{if(typeof a==="string"){if(b===null){delete this._data[a]}else{this._data[a]=b}}else{this._data={}}}};Usergrid.Entity.prototype.save=function(h){var c=this.get("type");var g="POST";if(isUUID(this.get("uuid"))){g="PUT";c+="/"+this.get("uuid")}var a=this;var e={};var f=this.get();for(var d in f){if(d==="metadata"||d==="created"||d==="modified"||d==="type"||d==="activated"||d==="uuid"){continue}e[d]=f[d]}var b={method:g,endpoint:c,body:e};this._client.request(b,function(n,k){if(n&&a._client.logging){console.log("could not save entity");if(typeof(h)==="function"){return h(n,k,a)}}else{if(k.entities){if(k.entities.length){var j=k.entities[0];a.set(j);var p=k.path;while(p.substring(0,1)==="/"){p=p.substring(1)}a.set("type",p)}}var o=((a.get("type")==="user"||a.get("type")==="users")&&f.oldpassword&&f.newpassword);if(o){var m={};m.oldpassword=f.oldpassword;m.newpassword=f.newpassword;var l={method:"PUT",endpoint:c+"/password",body:m};a._client.request(l,function(q,r)
 {if(q&&a._client.logging){console.log("could not update user")}a.set("oldpassword",null);a.set("newpassword",null);if(typeof(h)==="function"){h(q,r,a)}})}else{if(typeof(h)==="function"){h(n,k,a)}}}})};Usergrid.Entity.prototype.fetch=function(e){var d=this.get("type");var a=this;if(this.get("uuid")){d+="/"+this.get("uuid")}else{if(d==="users"){if(this.get("username")){d+="/"+this.get("username")}else{if(typeof(e)==="function"){var c="no_name_specified";if(a._client.logging){console.log(c)}return e(true,{error:c},a)}}}else{if(d==="a path"){if(this.get("path")){d+="/"+encodeURIComponent(this.get("name"))}else{if(typeof(e)==="function"){var c="no_name_specified";if(a._client.logging){console.log(c)}return e(true,{error:c},a)}}}else{if(this.get("name")){d+="/"+encodeURIComponent(this.get("name"))}else{if(typeof(e)==="function"){var c="no_name_specified";if(a._client.logging){console.log(c)}return e(true,{error:c},a)}}}}}var b={method:"GET",endpoint:d};this._client.request(b,function(g,h)
 {if(g&&a._client.logging){console.log("could not get entity")}else{if(h.user){a.set(h.user);a._json=JSON.stringify(h.user,null,2)}else{if(h.entities){if(h.entities.length){var f=h.entities[0];a.set(f)}}}}if(typeof(e)==="function"){e(g,h,a)}})};Usergrid.Entity.prototype.destroy=function(e){var d=this.get("type");if(isUUID(this.get("uuid"))){d+="/"+this.get("uuid")}else{if(typeof(e)==="function"){var c="Error trying to delete object - no uuid specified.";if(a._client.logging){console.log(c)}e(true,c)}}var a=this;var b={method:"DELETE",endpoint:d};this._client.request(b,function(f,g){if(f&&a._client.logging){console.log("entity could not be deleted")}else{a.set(null)}if(typeof(e)==="function"){e(f,g)}})};Usergrid.Entity.prototype.connect=function(a,d,h){var k=this;var f=d.get("type");var c=this.getEntityId(d);if(!c){if(typeof(h)==="function"){var g="Error trying to delete object - no uuid specified.";if(k._client.logging){console.log(g)}h(true,g)}return}var e=this.get("type");var b=thi
 s.getEntityId(this);if(!b){if(typeof(h)==="function"){var g="Error in connect - no uuid specified.";if(k._client.logging){console.log(g)}h(true,g)}return}var j=e+"/"+b+"/"+a+"/"+f+"/"+c;var l={method:"POST",endpoint:j};this._client.request(l,function(m,n){if(m&&k._client.logging){console.log("entity could not be connected")}if(typeof(h)==="function"){h(m,n)}})};Usergrid.Entity.prototype.getEntityId=function(a){var b=false;if(isUUID(a.get("uuid"))){b=a.get("uuid")}else{if(type==="users"){b=a.get("username")}else{if(a.get("name")){b=a.get("name")}}}return b};Usergrid.Entity.prototype.getConnections=function(d,h){var c=this;var b=this.get("type");var a=this.getEntityId(this);if(!a){if(typeof(h)==="function"){var f="Error in getConnections - no uuid specified.";if(c._client.logging){console.log(f)}h(true,f)}return}var g=b+"/"+a+"/"+d+"/";var e={method:"GET",endpoint:g};this._client.request(e,function(l,m){if(l&&c._client.logging){console.log("entity could not be connected")}c[d]={};var 
 k=m.entities.length;for(var j=0;j<k;j++){if(m.entities[j].type==="user"){c[d][m.entities[j].username]=m.entities[j]}else{c[d][m.entities[j].name]=m.entities[j]}}if(typeof(h)==="function"){h(l,m,m.entities)}})};Usergrid.Entity.prototype.getGroups=function(d){var a=this;var c="users/"+this.get("uuid")+"/groups";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a._client.logging){console.log("entity could not be connected")}a.groups=f.entities;if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Entity.prototype.getActivities=function(d){var a=this;var c=this.get("type")+"/"+this.get("uuid")+"/activities";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a._client.logging){console.log("entity could not be connected")}for(entity in f.entities){f.entities[entity].createdDate=(new Date(f.entities[entity].created)).toUTCString()}a.activities=f.entities;if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Entity.prototype.getFollow
 ing=function(d){var a=this;var c="users/"+this.get("uuid")+"/following";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a._client.logging){console.log("could not get user following")}for(entity in f.entities){f.entities[entity].createdDate=(new Date(f.entities[entity].created)).toUTCString();var g=a._client.getDisplayImage(f.entities[entity].email,f.entities[entity].picture);f.entities[entity]._portal_image_icon=g}a.following=f.entities;if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Entity.prototype.getFollowers=function(d){var a=this;var c="users/"+this.get("uuid")+"/followers";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a._client.logging){console.log("could not get user followers")}for(entity in f.entities){f.entities[entity].createdDate=(new Date(f.entities[entity].created)).toUTCString();var g=a._client.getDisplayImage(f.entities[entity].email,f.entities[entity].picture);f.entities[entity]._portal_image_icon=g}
 a.followers=f.entities;if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Entity.prototype.getRoles=function(d){var a=this;var c=this.get("type")+"/"+this.get("uuid")+"/roles";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a._client.logging){console.log("could not get user roles")}a.roles=f.entities;if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Entity.prototype.getPermissions=function(d){var a=this;var c=this.get("type")+"/"+this.get("uuid")+"/permissions";var b={method:"GET",endpoint:c};this._client.request(b,function(g,m){if(g&&a._client.logging){console.log("could not get user permissions")}var p=[];if(m.data){var r=m.data;var o=0;for(var n in r){o++;var h=r[n];var l=h.split(":");var s="";var q=l[0];if(l.length>1){s=l[0];q=l[1]}s.replace("*","get,post,put,delete");var e=s.split(",");var f={};f.get="no";f.post="no";f.put="no";f["delete"]="no";for(var k in e){f[e[k]]="yes"}p.push({operations:f,path:q,perm:h})}}a.permissions=p;if(typeof
 (d)==="function"){d(g,m,m.entities)}})};Usergrid.Entity.prototype.disconnect=function(a,d,h){var k=this;var f=d.get("type");var c=this.getEntityId(d);if(!c){if(typeof(h)==="function"){var g="Error trying to delete object - no uuid specified.";if(k._client.logging){console.log(g)}h(true,g)}return}var e=this.get("type");var b=this.getEntityId(this);if(!b){if(typeof(h)==="function"){var g="Error in connect - no uuid specified.";if(k._client.logging){console.log(g)}h(true,g)}return}var j=e+"/"+b+"/"+a+"/"+f+"/"+c;var l={method:"DELETE",endpoint:j};this._client.request(l,function(m,n){if(m&&k._client.logging){console.log("entity could not be disconnected")}if(typeof(h)==="function"){h(m,n)}})};Usergrid.Collection=function(b,e){if(b){this._client=b.client;this._type=b.type;this.qs=b.qs||{};this._list=b.list||[];this._iterator=b.iterator||-1;this._previous=b.previous||[];this._next=b.next||null;this._cursor=b.cursor||null;if(b.list){var d=b.list.length;for(var c=0;c<d;c++){var a=this._clie
 nt.restoreEntity(b.list[c]);this._list[c]=a}}}if(e){this.fetch(e)}};Usergrid.Collection.prototype.serialize=function(){var c={};c.type=this._type;c.qs=this.qs;c.iterator=this._iterator;c.previous=this._previous;c.next=this._next;c.cursor=this._cursor;this.resetEntityPointer();var b=0;c.list=[];while(this.hasNextEntity()){var a=this.getNextEntity();c.list[b]=a.serialize();b++}c=JSON.stringify(c);return c};Usergrid.Collection.prototype.addCollection=function(b,a,d){self=this;a.client=this._client;var c=new Usergrid.Collection(a,function(g,h){if(typeof(d)==="function"){c.resetEntityPointer();while(c.hasNextEntity()){var e=c.getNextEntity();var f=e.get("email");var j=self._client.getDisplayImage(e.get("email"),e.get("picture"));e._portal_image_icon=j}self[b]=c;d(g,c)}})};Usergrid.Collection.prototype.fetch=function(d){var b=this;var a=this.qs;if(this._cursor){a.cursor=this._cursor}else{delete a.cursor}var c={method:"GET",endpoint:this._type,qs:this.qs};this._client.request(c,function(g,
 h){if(g&&b._client.logging){console.log("error getting collection")}else{var o=h.cursor||null;b.saveCursor(o);if(h.entities){b.resetEntityPointer();var l=h.entities.length;b._list=[];for(var j=0;j<l;j++){var e=h.entities[j].uuid;if(e){var f=h.entities[j]||{};b._baseType=h.entities[j].type;f.type=b._type;var n={type:b._type,client:b._client,uuid:e,data:f};var m=new Usergrid.Entity(n);m._json=JSON.stringify(f,null,2);var k=b._list.length;b._list[k]=m}}}}if(typeof(d)==="function"){d(g,h)}})};Usergrid.Collection.prototype.addEntity=function(b,c){var a=this;b.type=this._type;this._client.createEntity(b,function(f,d){if(!f){var e=a._list.length;a._list[e]=d}if(typeof(c)==="function"){c(f,d)}})};Usergrid.Collection.prototype.addExistingEntity=function(a){var b=this._list.length;this._list[b]=a};Usergrid.Collection.prototype.destroyEntity=function(b,c){var a=this;b.destroy(function(d,e){if(d){if(a._client.logging){console.log("could not destroy entity")}if(typeof(c)==="function"){c(d,e)}}el
 se{a.fetch(c)}});this.removeEntity(b)};Usergrid.Collection.prototype.removeEntity=function(a){var b=a.get("uuid");for(key in this._list){var c=this._list[key];if(c.get("uuid")===b){return this._list.splice(key,1)}}return false};Usergrid.Collection.prototype.getEntityByUUID=function(c,e){for(key in this._list){var d=this._list[key];if(d.get("uuid")===c){return d}}var b={data:{type:this._type,uuid:c},client:this._client};var a=new Usergrid.Entity(b);a.fetch(e)};Usergrid.Collection.prototype.getFirstEntity=function(){var a=this._list.length;if(a>0){return this._list[0]}return null};Usergrid.Collection.prototype.getLastEntity=function(){var a=this._list.length;if(a>0){return this._list[a-1]}return null};Usergrid.Collection.prototype.hasNextEntity=function(){var a=this._iterator+1;var b=(a>=0&&a<this._list.length);if(b){return true}return false};Usergrid.Collection.prototype.getNextEntity=function(){this._iterator++;var a=(this._iterator>=0&&this._iterator<=this._list.length);if(a){retur
 n this._list[this._iterator]}return false};Usergrid.Collection.prototype.hasPrevEntity=function(){var b=this._iterator-1;var a=(b>=0&&b<this._list.length);if(a){return true}return false};Usergrid.Collection.prototype.getPrevEntity=function(){this._iterator--;var a=(this._iterator>=0&&this._iterator<=this._list.length);if(a){return this.list[this._iterator]}return false};Usergrid.Collection.prototype.resetEntityPointer=function(){this._iterator=-1};Usergrid.Collection.prototype.saveCursor=function(a){if(this._next!==a){this._next=a}};Usergrid.Collection.prototype.resetPaging=function(){this._previous=[];this._next=null;this._cursor=null};Usergrid.Collection.prototype.hasNextPage=function(){return(this._next)};Usergrid.Collection.prototype.getNextPage=function(a){if(this.hasNextPage()){this._previous.push(this._cursor);this._cursor=this._next;this._list=[];this.fetch(a)}};Usergrid.Collection.prototype.hasPreviousPage=function(){return(this._previous.length>0)};Usergrid.Collection.prot
 otype.getPreviousPage=function(a){if(this.hasPreviousPage()){this._next=null;this._cursor=this._previous.pop();this._list=[];this.fetch(a)}};Usergrid.Group=function(a,b){this._path=a.path;this._list=[];this._client=a.client;this._data=a.data||{};this._data.type="groups"};Usergrid.Group.prototype=new Usergrid.Entity();Usergrid.Group.prototype.fetch=function(f){var a=this;var e="groups/"+this._path;var d="groups/"+this._path+"/users";var b={method:"GET",endpoint:e};var c={method:"GET",endpoint:d};this._client.request(b,function(h,j){if(h){if(a._client.logging){console.log("error getting group")}if(typeof(f)==="function"){f(h,j)}}else{if(j.entities){var g=j.entities[0];a._data=g||{};a._client.request(c,function(p,q){if(p&&a._client.logging){console.log("error getting group users")}else{if(q.entities){var o=q.entities.length;a._list=[];for(var l=0;l<o;l++){var n=q.entities[l].uuid;if(n){var r=q.entities[l]||{};var m={type:r.type,client:a._client,uuid:n,data:r};var k=new Usergrid.Entity(
 m);a._list.push(k)}}}}if(typeof(f)==="function"){f(p,q,a._list)}})}}})};Usergrid.Group.prototype.members=function(a){if(typeof(a)==="function"){a(null,this._list)}};Usergrid.Group.prototype.add=function(b,c){var a=this;var b={method:"POST",endpoint:"groups/"+this._path+"/users/"+b.user.get("username")};this._client.request(b,function(d,e){if(d){if(typeof(c)==="function"){c(d,e,e.entities)}}else{a.fetch(c)}})};Usergrid.Group.prototype.remove=function(b,c){var a=this;var b={method:"DELETE",endpoint:"groups/"+this._path+"/users/"+b.user.get("username")};this._client.request(b,function(d,e){if(d){if(typeof(c)==="function"){c(d,e)}}else{a.fetch(c)}})};Usergrid.Group.prototype.feed=function(d){var a=this;var c="groups/"+this._path+"/feed";var b={method:"GET",endpoint:c};this._client.request(b,function(e,f){if(e&&a.logging){console.log("error trying to log user in")}if(typeof(d)==="function"){d(e,f,f.entities)}})};Usergrid.Group.prototype.createGroupActivity=function(c,d){var b=c.user;var 
 c={actor:{displayName:b.get("username"),uuid:b.get("uuid"),username:b.get("username"),email:b.get("email"),picture:b.get("picture"),image:{duration:0,height:80,url:b.get("picture"),width:80},},verb:"post",content:c.content};c.type="groups/"+this._path+"/activities";var c={client:this._client,data:c};var a=new Usergrid.Entity(c);a.save(function(e,f){if(typeof(d)==="function"){d(e,a)}})};function isUUID(a){var b=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;if(!a){return false}return b.test(a)}function encodeParams(d){tail=[];var b=[];if(d instanceof Array){for(i in d){b=d[i];if((b instanceof Array)&&(b.length>1)){tail.push(b[0]+"="+encodeURIComponent(b[1]))}}}else{for(var a in d){if(d.hasOwnProperty(a)){var c=d[a];if(c instanceof Array){for(i in c){b=c[i];tail.push(a+"="+encodeURIComponent(b))}}else{tail.push(a+"="+encodeURIComponent(c))}}}}return tail.join("&")};
\ No newline at end of file


Mime
View raw message