X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FAPI.js;h=4a0602bff9654265c2f7e03b61ec212f4338b8fe;hb=2d498144a3a655c1fd4e54b9e9d61d1c3eb82206;hp=13702340187a451afe08a43ae881a6f409e9c0ea;hpb=80ad774f55998cc11e08694245dfd6cb1b49a86f;p=blerg.git diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 1370234..4a0602b 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', @@ -68,10 +88,23 @@ enyo.kind({ }); enyo.setCookie('username', '', {"Max-Age": 0}); }, - requestFeedStatus: function() { - if (!blerg.API.loggedIn) - throw new Error('Cannot request feed status when not logged in'); - // TODO + changePassword: function(oldpassword, newpassword) { + var req = new enyo.Ajax({ + url: baseURL + '/passwd', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + if (inResponse.status == 'success') { + this.bubble('onPasswordChangeSuccessful'); + } else { + this.bubble('onPasswordChangeFailed'); + } + }.bind(this)); + req.go({ + username: blerg.API.username, + password: oldpassword, + new_password: newpassword + }); }, loadUserRecords: function(username, from ,to) { var url; @@ -93,6 +126,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) { @@ -123,6 +162,39 @@ enyo.kind({ }.bind(this)); req.go(); }, + getFeedInfo: function() { + if (!blerg.API.loggedIn) + throw new Error('Cannot request feed status when not logged in'); + + var req = new enyo.Ajax({ + url: baseURL + '/feedinfo', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + this.bubble('onFeedInfo', inResponse); + }.bind(this)); + req.go({ + username: blerg.API.username + }); + }, + loadFeed: function() { + if (!blerg.API.loggedIn) + throw new Error('Cannot request feed status when not logged in'); + + var req = new enyo.Ajax({ + url: baseURL + '/feed', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + this.bubble('onItemsLoaded', { + type: "feed", + entries: inResponse + }); + }.bind(this)); + req.go({ + username: blerg.API.username + }); + }, getSubscriptionStatus: function(username) { var req = new enyo.Ajax({ url: baseURL + '/feedinfo/' + username, @@ -168,4 +240,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 + }); + } });