Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'christopherwright/master'

  • Loading branch information...
commit 3617fea8e5e2e9eae5bbcf3418f9592fc7d67b4a 2 parents 2d4dad4 + 01c2569
@oesmith oesmith authored
Showing with 184 additions and 35 deletions.
  1. +183 −34 lib/twitter.js
  2. +1 −1  package.json
View
217 lib/twitter.js
@@ -1,4 +1,4 @@
-var VERSION = '0.1.16',
+var VERSION = '0.1.17',
http = require('http'),
querystring = require('querystring'),
oauth = require('oauth'),
@@ -41,10 +41,10 @@ function Twitter(options) {
callback_url: null,
rest_base: 'https://api.twitter.com/1',
- search_base: 'http://search.twitter.com',
- stream_base: 'http://stream.twitter.com/1',
+ search_base: 'https://search.twitter.com',
+ stream_base: 'https://stream.twitter.com/1',
user_stream_base: 'https://userstream.twitter.com/2',
- site_stream_base: 'http://sitestream.twitter.com/2b',
+ site_stream_base: 'https://sitestream.twitter.com/2b',
secure: false, // force use of https for login/gatekeeper
cookie: 'twauth',
@@ -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,34 @@ 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.newSavedSearch =
+ Twitter.prototype.createSavedSearch;
+
+Twitter.prototype.destroySavedSearch = function(id, callback) {
+ var url = '/saved_searches/destroy/' + escape(id) + '.json?_method=DELETE';
+ this.post(url, null, null, callback);
+ return this;
+}
+Twitter.prototype.deleteSavedSearch =
+ Twitter.prototype.destroySavedSearch;
+
// OAuth resources
// Geo resources
@@ -957,6 +1105,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 = [];
View
2  package.json
@@ -1,5 +1,5 @@
{ "name": "twitter"
-, "version": "v0.1.16"
+, "version": "v0.1.17"
, "description": "Asynchronous Twitter REST/stream/search client API for node.js."
, "keywords": ["twitter","streaming","oauth"]
, "homepage": "https://github.com/jdub/node-twitter"
Please sign in to comment.
Something went wrong with that request. Please try again.