X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FAPI.js;h=30dc7b51534388267ab60ebb14775c1fd83e9f1b;hb=fc5b9f1f68322c876b331c049749f113eb0271f7;hp=203706a674da60477844ccca4312302ecb89885d;hpb=04a4fdf9d85e0d0b193300abe0c0e433449cd285;p=blerg.git diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 203706a..30dc7b5 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -32,6 +32,26 @@ enyo.kind({ blerg.API.apiInitialized = true; }, + signup: function(username, password) { + var req = new enyo.Ajax({ + url: baseURL + '/create', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse.status == 'success') { + this.bubble('onSignupSuccess', {username: username}); + } else { + this.bubble('onSignupFailure', {username: username}); + } + }.bind(this)); + req.error(function() { + this.bubble('onSignupFailure', {username: username}); + }.bind(this)); + req.go({ + username: username, + password: password, + }); + }, login: function(username, password) { var req = new enyo.Ajax({ url: baseURL + '/login', @@ -88,6 +108,12 @@ enyo.kind({ entries: inResponse }); }.bind(this)); + req.error(function(inSender, inResponse) { + if (inResponse == 404) + this.bubble('onUserNotFound'); + else + this.bubble('onAPIError', {response: inResponse}); + }.bind(this)); req.go(); }, loadTagRecords: function(type, tag) { @@ -196,4 +222,27 @@ enyo.kind({ username: blerg.API.username }); }, + post: function(data) { + var req = new enyo.Ajax({ + url: baseURL + '/put', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse && inResponse.status == 'success') { + this.bubble('onPostSuccessful', { + username: blerg.API.username, + data: data + }); + } else { + this.bubble('onPostFailed', { + username: blerg.API.username, + data: data + }); + } + }.bind(this)); + req.go({ + username: blerg.API.username, + data: data + }); + } });