Permalink
Browse files

fix twitter trends endpoint

  • Loading branch information...
1 parent 184b397 commit 6a6a905a34a1c000467fbb0ace021ed41592c5a4 @Ferrari Ferrari committed Sep 1, 2012
Showing with 55 additions and 3 deletions.
  1. +8 −3 lib/twitter.js
  2. +4 −0 package.json
  3. +43 −0 test/trend.js
View
@@ -652,13 +652,18 @@ Twitter.prototype.userProfileImage = function(id, params, callback) {
// Trends resources
Twitter.prototype.getTrends = function(callback) {
- var url = '/trends.json';
- this.get(url, null, callback);
+ this.getTrendsWithId('1', null, callback);
return this;
}
Twitter.prototype.getCurrentTrends = function(params, callback) {
- var url = '/trends/current.json';
+ this.getTrendsWithId('1', params, callback);
+ return this;
+}
+
+Twitter.prototype.getTrendsWithId = function(woeid, params, callback) {
+ if (!woeid) woeid = '1';
+ var url = '/trends/' + woeid + '.json';
this.get(url, params, callback);
return this;
}
View
@@ -18,6 +18,10 @@
"cookies": "0.1.x",
"keygrip": "0.2.x"
},
+ "devDependencies": {
+ "should": "*",
+ "mocha": "*"
+ },
"engines": {"node":">=0.4.0"},
"main": "./lib/twitter"
}
View
@@ -0,0 +1,43 @@
+var ntwitter = require('../index.js'),
+ mocha = require('mocha'),
+ should = require('should'),
+ fs = require('fs'),
+ config = JSON.parse(fs.readFileSync('./config.json'));
+
+var twitter = new ntwitter({
+ consumer_key: config.key,
+ consumer_secret: config.secret,
+ access_token_key: config.token_key,
+ access_token_secret: config.token_secret
+});
+
+describe('Twitter Trend API', function() {
+ it('Origin getTrends still work', function(done) {
+ twitter.getTrends(function(err, data) {
+ data[0].trends.should.not.be.empty;
+ done();
+ });
+ });
+
+ it('Origin getCurrentTrends still work', function(done) {
+ twitter.getCurrentTrends(function(err, data) {
+ data[0].trends.should.not.be.empty;
+ done();
+ });
+ });
+
+ it('GET trends/:woeid data without earth id', function(done) {
+ twitter.getTrendsWithId(null, function(err, data) {
+ data[0].trends.should.not.be.empty;
+ done();
+ });
+ });
+
+ it('GET trends/:woeid data wih earth id', function(done) {
+ twitter.getTrendsWithId('23424977', function(err, data) {
+ data[0].trends.should.not.be.empty;
+ data[0].locations[0].name.should.equal('United States');
+ done();
+ });
+ });
+});

0 comments on commit 6a6a905

Please sign in to comment.