Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing search method by updating the endpoint and removing search_base #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module.exports = {
authenticate_url: 'https://api.twitter.com/oauth/authenticate',
authorize_url: 'https://api.twitter.com/oauth/authorize',
rest_base: 'https://api.twitter.com/1.1',
search_base: 'http://search.twitter.com',
stream_base: 'https://stream.twitter.com/1.1',
stream_base: 'https://stream.twitter.com/1.1',
user_stream_base: 'https://userstream.twitter.com/1.1',
site_stream_base: 'https://sitestream.twitter.com/1.1'
}
Expand Down
39 changes: 19 additions & 20 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ Twitter.prototype.get = function(url, params, callback) {
err.statusCode = error.statusCode;
err.data = error.data;
callback(err);
}
}
else if (error) {
callback(error);
}
else {
try {
var json = JSON.parse(data);
}
}
catch(err) {
return callback(err);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ Twitter.prototype.post = function(url, content, content_type, callback) {
content[e] = content[e].toString();
});
}

this.oauth.post(url,
this.options.access_token_key,
this.options.access_token_secret,
Expand All @@ -131,14 +131,14 @@ Twitter.prototype.post = function(url, content, content_type, callback) {
err.data = error.data;
err.statusCode = error.statusCode;
callback(err);
}
}
else if (error) {
callback(error);
}
else {
try {
var json = JSON.parse(data);
}
}
catch(err) {
return callback(err);
}
Expand All @@ -163,9 +163,8 @@ Twitter.prototype.search = function(q, params, callback) {
return this;
}

var url = this.options.search_base + '/search.json';
params = utils.merge(params, {q:q});
this.get(url, params, callback);
this.get('/search/tweets.json', params, callback);
return this;
}

Expand Down Expand Up @@ -194,10 +193,10 @@ Twitter.prototype.stream = function(method, params, callback) {
// Stream type customisations
if (method === 'user') {
stream_base = this.options.user_stream_base;
}
}
else if (method === 'site') {
stream_base = this.options.site_stream_base;
}
}


var url = stream_base + '/' + escape(method) + '.json';
Expand Down Expand Up @@ -225,7 +224,7 @@ Twitter.prototype.stream = function(method, params, callback) {
stream.emit('destroy','socket has been destroyed');
};


stream.on('_data', processTweet);

function processTweet(tweet) {
Expand Down Expand Up @@ -263,11 +262,11 @@ Twitter.prototype.stream = function(method, params, callback) {
response.on('end', function() {
stream.emit('end', response);
});
/*

/*
* This is a net.Socket event.
* When twitter closes the connectionm no 'end/error' event is fired.
* In this way we can able to catch this event and force to destroy the
* In this way we can able to catch this event and force to destroy the
* socket. So, 'stream' object will fire the 'destroy' event as we can see above.
*/
response.on('close', function() {
Expand Down Expand Up @@ -636,7 +635,7 @@ Twitter.prototype.userProfileImage = function(id, params, callback) {
this.options.access_token_secret);
request.on('response', function(response) {
// return the location or an HTTP error
if (!response.headers.location) {
if (!response.headers.location) {
callback(new Error('HTTP Error '
+ response.statusCode + ': '
+ http.STATUS_CODES[response.statusCode])) }
Expand Down Expand Up @@ -947,25 +946,25 @@ Twitter.prototype.outgoingFriendships
Twitter.prototype.lookupFriendship = function(id, callback) {
var url = '/friendships/lookup.json',
params = {}, ids = [], names = [];

if (typeof id === 'string') {
id = id.replace(/^\s+|\s+$/g, '');
id = id.split(',');
}

id = [].concat(id);

id.forEach(function(item) {
if (parseInt(item, 10)) {
ids.push(item);
} else {
names.push(item);
}
});

params.user_id = ids.toString();
params.screen_name = names.toString();

this.get(url, params, callback);
return this;
};
Expand Down Expand Up @@ -1042,7 +1041,7 @@ Twitter.prototype.updateProfileImg = function (params, callback) {
var url = '/account/update_profile_image.json';
this.post(url, params, null, callback);
return this;

}

// FIXME: Account resources section not complete
Expand Down