Permalink
Browse files

* List resources:

  - Convert getLists/Memberships/Subscriptions to new Twitter API
  - All the other list resources use the deprecated API for now
* Friendship resources: COMPLETE!
* Saved searches resources: COMPLETE!
* Account resources: Add rateLimitStatus and updateProfile
  • Loading branch information...
1 parent 641ebf3 commit 83d25fb104ab3a034790b3ca047a1feccae632eb @jdub committed May 8, 2011
Showing with 175 additions and 30 deletions.
  1. +175 −30 lib/twitter.js
View
@@ -591,50 +591,68 @@ Twitter.prototype.getWeeklyTrends = function(params, callback) {
// List resources
-Twitter.prototype.getLists = function(screen_name, params, callback) {
+Twitter.prototype.getLists = function(id, params, callback) {
if (typeof params === 'function') {
callback = params;
params = null;
}
- var url = '/' + escape(screen_name) + '/lists.json';
- params = merge(params, {key:'lists'});
+ var defaults = {key:'lists'};
+ if (typeof id === 'string')
+ defaults.screen_name = id;
+ else
+ defaults.user_id = id;
+ params = merge(defaults, params);
+
+ var url = '/lists.json';
this._getUsingCursor(url, params, callback);
return this;
}
-Twitter.prototype.createList = function(screen_name, list_name, params, callback) {
+Twitter.prototype.getListMemberships = function(id, params, callback) {
if (typeof params === 'function') {
callback = params;
params = null;
}
- var url = '/' + escape(screen_name) + '/lists.json';
- params = merge(params, {name:list_name});
- this.post(url, params, null, callback);
+ var defaults = {key:'lists'};
+ if (typeof id === 'string')
+ defaults.screen_name = id;
+ else
+ defaults.user_id = id;
+ params = merge(defaults, params);
+
+ var url = '/lists/memberships.json';
+ this._getUsingCursor(url, params, callback);
return this;
}
-Twitter.prototype.updateList = function(screen_name, list_id, params, callback) {
- var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
- this.post(url, params, null, callback);
+Twitter.prototype.getListSubscriptions = function(id, params, callback) {
+ if (typeof params === 'function') {
+ callback = params;
+ params = null;
+ }
+
+ var defaults = {key:'lists'};
+ if (typeof id === 'string')
+ defaults.screen_name = id;
+ else
+ defaults.user_id = id;
+ params = merge(defaults, params);
+
+ var url = '/lists/subscriptions.json';
+ this._getUsingCursor(url, params, callback);
return this;
}
+// FIXME: Uses deprecated Twitter lists API
Twitter.prototype.showList = function(screen_name, list_id, callback) {
var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
this.get(url, null, callback);
return this;
}
-Twitter.prototype.deleteList = function(screen_name, list_id, callback) {
- var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json?_method=DELETE';
- this.post(url, null, callback);
- return this;
-}
-Twitter.prototype.destroyList
- = Twitter.prototype.deleteList;
-
+// FIXME: Uses deprecated Twitter lists API
Twitter.prototype.getListTimeline = function(screen_name, list_id, params, callback) {
var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '/statuses.json';
this.get(url, params, callback);
@@ -643,32 +661,38 @@ Twitter.prototype.getListTimeline = function(screen_name, list_id, params, callb
Twitter.prototype.showListStatuses
= Twitter.prototype.getListTimeline;
-Twitter.prototype.getListMemberships = function(screen_name, params, callback) {
+// FIXME: Uses deprecated Twitter lists API
+Twitter.prototype.createList = function(screen_name, list_name, params, callback) {
if (typeof params === 'function') {
callback = params;
params = null;
}
- var url = '/' + escape(screen_name) + '/lists/memberships.json';
- params = merge(params, {key:'lists'});
- this._getUsingCursor(url, params, callback);
+ var url = '/' + escape(screen_name) + '/lists.json';
+ params = merge(params, {name:list_name});
+ this.post(url, params, null, callback);
return this;
}
-Twitter.prototype.getListSubscriptions = function(screen_name, params, callback) {
- if (typeof params === 'function') {
- callback = params;
- params = null;
- }
+// FIXME: Uses deprecated Twitter lists API
+Twitter.prototype.updateList = function(screen_name, list_id, params, callback) {
+ var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json';
+ this.post(url, params, null, callback);
+ return this;
+}
- var url = '/' + escape(screen_name) + '/lists/subscriptions.json';
- params = merge(params, {key:'lists'});
- this._getUsingCursor(url, params, callback);
+// FIXME: Uses deprecated Twitter lists API
+Twitter.prototype.deleteList = function(screen_name, list_id, callback) {
+ var url = '/' + escape(screen_name) + '/lists/' + escape(list_id) + '.json?_method=DELETE';
+ this.post(url, null, callback);
return this;
}
+Twitter.prototype.destroyList
+ = Twitter.prototype.deleteList;
// List Members resources
+// FIXME: Uses deprecated Twitter lists API
Twitter.prototype.getListMembers = function(screen_name, list_id, params, callback) {
if (typeof params === 'function') {
callback = params;
@@ -685,6 +709,7 @@ Twitter.prototype.getListMembers = function(screen_name, list_id, params, callba
// List Subscribers resources
+// FIXME: Uses deprecated Twitter lists API
Twitter.prototype.getListSubscribers = function(screen_name, list_id, params, callback) {
if (typeof params === 'function') {
callback = params;
@@ -749,6 +774,83 @@ Twitter.prototype.deleteDirectMessage
// Friendship resources
+Twitter.prototype.createFriendship = function(id, params, callback) {
+ if (typeof params === 'function') {
+ callback = params;
+ params = null;
+ }
+
+ var defaults = {
+ include_entities: 1
+ };
+ if (typeof id === 'string')
+ defaults.screen_name = id;
+ else
+ defaults.user_id = id;
+ params = merge(defaults, params);
+
+ var url = '/friendships/create.json';
+ this.post(url, params, null, callback);
+ return this;
+}
+
+Twitter.prototype.destroyFriendship = function(id, callback) {
+ if (typeof id === 'function') {
+ callback = id;
+ id = null;
+ }
+
+ var params = {
+ include_entities: 1
+ };
+ if (typeof id === 'string')
+ params.screen_name = id;
+ else
+ params.user_id = id;
+
+ var url = '/friendships/destroy.json?_method=DELETE';
+ this.post(url, params, null, callback);
+ return this;
+}
+Twitter.prototype.deleteFriendship
+ = Twitter.prototype.destroyFriendship;
+
+// Only exposing friendships/show instead of friendships/exist
+
+Twitter.prototype.showFriendship = function(source, target, callback) {
+ var params = {};
+
+ if (typeof source === 'string')
+ params.source_screen_name = source;
+ else
+ params.source_id = source;
+
+ if (typeof target === 'string')
+ params.target_screen_name = target;
+ else
+ params.target_id = target;
+
+ var url = '/friendships/show.json';
+ this.get(url, params, callback);
+ return this;
+}
+
+Twitter.prototype.incomingFriendship = function(callback) {
+ var url = '/friendships/incoming.json';
+ this._getUsingCursor(url, {key:'ids'}, callback);
+ return this;
+}
+Twitter.prototype.incomingFriendships
+ = Twitter.prototype.incomingFriendship;
+
+Twitter.prototype.outgoingFriendship = function(callback) {
+ var url = '/friendships/outgoing.json';
+ this._getUsingCursor(url, {key:'ids'}, callback);
+ return this;
+}
+Twitter.prototype.outgoingFriendships
+ = Twitter.prototype.outgoingFriendship;
+
// Friends and Followers resources
Twitter.prototype.getFriendsIds = function(id, callback) {
@@ -793,6 +895,24 @@ Twitter.prototype.verifyCredentials = function(callback) {
return this;
}
+Twitter.prototype.rateLimitStatus = function(callback) {
+ var url = '/account/rate_limit_status.json';
+ this.get(url, null, callback);
+ return this;
+}
+
+Twitter.prototype.updateProfile = function(params, callback) {
+ // params: name, url, location, description
+ var defaults = {
+ include_entities: 1
+ };
+ params = merge(defaults, params);
+
+ var url = '/account/update_profile.json';
+ this.post(url, params, null, callback);
+ return this;
+}
+
// FIXME: Account resources section not complete
// Favorites resources
@@ -887,6 +1007,30 @@ Twitter.prototype.reportSpam = function(id, callback) {
// Saved Searches resources
+Twitter.prototype.savedSearches = function(callback) {
+ var url = '/saved_searches.json';
+ this.get(url, null, callback);
+ return this;
+}
+
+Twitter.prototype.showSavedSearch = function(id, callback) {
+ var url = '/saved_searches/' + escape(id) + '.json';
+ this.get(url, null, callback);
+ return this;
+}
+
+Twitter.prototype.createSavedSearch = function(query, callback) {
+ var url = '/saved_searches/create.json';
+ this.post(url, {query: query}, null, callback);
+ return this;
+}
+
+Twitter.prototype.destroySavedSearch = function(id, callback) {
+ var url = '/saved_searches/destroy/' + escape(id) + '.json?_method=DELETE';
+ this.post(url, null, null, callback);
+ return this;
+}
+
// OAuth resources
// Geo resources
@@ -957,6 +1101,7 @@ Twitter.prototype.geoGetPlace = function(place_id, callback) {
Twitter.prototype._getUsingCursor = function(url, params, callback) {
var self = this,
+ params = params || {},
key = params.key || null,
result = [];

0 comments on commit 83d25fb

Please sign in to comment.