+ var req = new enyo.Ajax({
+ url: url
+ });
+ req.response(this, function(inSender, inResponse) {
+ this.bubble('onItemsLoaded', {
+ type: 'user',
+ username: username,
+ from: from,
+ to: to,
+ entries: inResponse
+ });
+ });
+ req.error(this, function(inSender, inResponse) {
+ if (inResponse == 404)
+ this.bubble('onUserNotFound');
+ else
+ this.bubble('onAPIError', {response: inResponse});
+ });
+ 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(this, function(inSender, inResponse) {
+ this.bubble('onItemsLoaded', {
+ type: 'tag',
+ tagType: type,
+ tag: tag,
+ entries: inResponse
+ });
+ });
+ req.error(this, function() {
+ this.bubble('onItemsLoaded', {
+ type: 'tag',
+ tagType: type,
+ tag: tag,
+ entries: []
+ });
+ });
+ req.go();
+ },
+ getStatus: function() {
+ if (!blerg.API.loggedIn)
+ throw new Error('Cannot request feed status when not logged in');
+
+ var req = new enyo.Ajax({
+ url: baseURL + '/status'
+ });
+ req.response(this, function(inSender, inResponse) {
+ this.bubble('onStatus', inResponse);
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ },
+ clearStatus: function(type) {
+ if (!blerg.API.loggedIn)
+ throw new Error('Cannot request feed status when not logged in');
+
+ if (!(type == 'feed' || type == 'mentioned'))
+ throw new Error('Invalid status clear type: ' + type);
+
+ var req = new enyo.Ajax({
+ url: baseURL + '/status',
+ method: 'POST',
+ postBody: {
+ clear: type
+ }
+ });
+ req.response(this, function(inSender, inResponse) {
+ inResponse.type = type;
+ this.bubble('onClearStatus', inResponse);
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ },
+ 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'
+ });
+ req.response(this, function(inSender, inResponse) {
+ this.bubble('onItemsLoaded', {
+ type: "feed",
+ entries: inResponse
+ });
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ },
+ getSubscriptionStatus: function(username) {
+ var req = new enyo.Ajax({
+ url: baseURL + '/status/' + username
+ });
+ req.response(this, function(inSender, inResponse) {
+ this.bubble('onSubscriptionStatus', {
+ username: username,
+ subscribed: inResponse.subscribed
+ });
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ },
+ subscription: function(username, v) {
+ var subv = v ? true : false;
+ var req = new enyo.Ajax({
+ url: baseURL + '/subscribe/' + username,
+ method: 'POST',
+ postBody: {
+ subscribed: subv
+ }
+ });
+ req.response(this, function(inSender, inResponse) {
+ this.bubble('onSubscriptionStatus', {
+ username: username,
+ subscribed: inResponse.status == "success" && subv
+ });
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ },
+ subscribe: function(username) {
+ this.subscription(username, true);
+ },
+ unsubscribe: function(username) {
+ this.subscription(username, false);
+ },
+ post: function(data) {
+ var req = new enyo.Ajax({
+ url: baseURL + '/put',
+ method: 'POST',
+ postBody: {
+ data: data
+ }
+ });
+ req.response(this, 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
+ });
+ }
+ });
+ req.error(this, function() {
+ if (req.xhrResponse.status == 403) {
+ this.authenticationFailed();
+ }
+ });
+ req.go();
+ }