- var req = new enyo.Ajax({
- url: url
- });
- req.response(function(inSender, inResponse) {
- this.bubble('onItemsLoaded', {
- entries: inResponse
- });
- }.bind(this));
- req.go();
- },
- getSubscriptionStatus: function(username) {
- var req = new enyo.Ajax({
- url: baseURL + '/feedinfo/' + username,
- method: 'POST'
- });
- req.response(function(inSender, inResponse) {
- this.bubble('onSubscriptionStatus', {
- username: username,
- subscribed: inResponse.subscribed
- });
- }.bind(this));
- req.go({
- username: blerg.API.username
- });
- },
- subscribe: function(username) {
- var req = new enyo.Ajax({
- url: baseURL + '/subscribe/' + username,
- method: 'POST'
- });
- req.response(function(inSender, inResponse) {
- this.bubble('onSubscriptionStatus', {
- username: username,
- subscribed: inResponse.status == "success"
- });
- }.bind(this));
- req.go({
- username: blerg.API.username
- });
- },
- unsubscribe: function(username) {
- var req = new enyo.Ajax({
- url: baseURL + '/unsubscribe/' + username,
- method: 'POST'
- });
- req.response(function(inSender, inResponse) {
- this.bubble('onSubscriptionStatus', {
- username: username,
- subscribed: inResponse.status != "success"
- });
- }.bind(this));
- req.go({
- username: blerg.API.username
- });
- },
+ var req = new enyo.Ajax({
+ url: url
+ });
+ req.response(function(inSender, inResponse) {
+ this.bubble('onItemsLoaded', {
+ type: 'user',
+ username: username,
+ from: from,
+ to: to,
+ 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) {
+ var url;
+ switch(type) {
+ case 'tag':
+ // Apache eats the hash, even encoded. Probably a security
+ // feature.
+ url = baseURL + '/tag/H' + tag;
+ break;
+ case 'ref':
+ url = baseURL + '/tag/%40' + tag;
+ break;
+ default:
+ throw new Error("Invalid tag type: " + type);
+ return;
+ }
+ var req = new enyo.Ajax({
+ url: url
+ });
+ req.response(function(inSender, inResponse) {
+ this.bubble('onItemsLoaded', {
+ type: 'tag',
+ tagType: type,
+ tag: tag,
+ entries: inResponse
+ });
+ }.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,
+ method: 'POST'
+ });
+ req.response(function(inSender, inResponse) {
+ this.bubble('onSubscriptionStatus', {
+ username: username,
+ subscribed: inResponse.subscribed
+ });
+ }.bind(this));
+ req.go({
+ username: blerg.API.username
+ });
+ },
+ subscribe: function(username) {
+ var req = new enyo.Ajax({
+ url: baseURL + '/subscribe/' + username,
+ method: 'POST'
+ });
+ req.response(function(inSender, inResponse) {
+ this.bubble('onSubscriptionStatus', {
+ username: username,
+ subscribed: inResponse.status == "success"
+ });
+ }.bind(this));
+ req.go({
+ username: blerg.API.username
+ });
+ },
+ unsubscribe: function(username) {
+ var req = new enyo.Ajax({
+ url: baseURL + '/unsubscribe/' + username,
+ method: 'POST'
+ });
+ req.response(function(inSender, inResponse) {
+ this.bubble('onSubscriptionStatus', {
+ username: username,
+ subscribed: inResponse.status != "success"
+ });
+ }.bind(this));
+ req.go({
+ 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
+ });
+ }