Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Twitter API versioning support for trends methods

  • Loading branch information...
commit 6f23c5eb3ffdac6eac65fa2b6d36f08aa7b6e1fb 1 parent 9ed3709
@sferik authored
Showing with 18 additions and 18 deletions.
  1. +7 −7 lib/twitter/trends.rb
  2. +11 −11 test/twitter/trends_test.rb
View
14 lib/twitter/trends.rb
@@ -1,37 +1,37 @@
module Twitter
class Trends
include HTTParty
- base_uri 'search.twitter.com/trends'
+ base_uri "api.twitter.com/1/trends"
format :json
# :exclude => 'hashtags' to exclude hashtags
def self.current(options={})
- mashup(get('/current.json', :query => options))
+ mashup(get("/current.json", :query => options))
end
# :exclude => 'hashtags' to exclude hashtags
# :date => yyyy-mm-dd for specific date
def self.daily(options={})
- mashup(get('/daily.json', :query => options))
+ mashup(get("/daily.json", :query => options))
end
# :exclude => 'hashtags' to exclude hashtags
# :date => yyyy-mm-dd for specific date
def self.weekly(options={})
- mashup(get('/weekly.json', :query => options))
+ mashup(get("/weekly.json", :query => options))
end
def self.available(query={})
- locations = get('http://api.twitter.com/1/trends/available.json', :query => query).map{|location| Hashie::Mash.new(location)}
+ locations = get("http://api.twitter.com/#{API_VERSION}/trends/available.json", :query => query).map{|location| Hashie::Mash.new(location)}
end
def self.for_location(woeid)
- get("http://api.twitter.com/1/trends/#{woeid}.json").map{|location| Hashie::Mash.new(location)}
+ get("http://api.twitter.com/#{API_VERSION}/trends/#{woeid}.json").map{|location| Hashie::Mash.new(location)}
end
private
def self.mashup(response)
- response['trends'].values.flatten.map { |t| Hashie::Mash.new(t) }
+ response["trends"].values.flatten.map { |t| Hashie::Mash.new(t) }
end
end
end
View
22 test/twitter/trends_test.rb
@@ -5,7 +5,7 @@ class TrendsTest < Test::Unit::TestCase
context "Getting current trends" do
should "work" do
- stub_get 'http://search.twitter.com:80/trends/current.json', 'trends_current.json'
+ stub_get 'http://api.twitter.com:80/1/trends/current.json', 'trends_current.json'
trends = Trends.current
trends.size.should == 10
trends[0].name.should == '#musicmonday'
@@ -15,7 +15,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to exclude hashtags" do
- stub_get 'http://search.twitter.com:80/trends/current.json?exclude=hashtags', 'trends_current_exclude.json'
+ stub_get 'http://api.twitter.com:80/1/trends/current.json?exclude=hashtags', 'trends_current_exclude.json'
trends = Trends.current(:exclude => 'hashtags')
trends.size.should == 10
trends[0].name.should == 'New Divide'
@@ -27,7 +27,7 @@ class TrendsTest < Test::Unit::TestCase
context "Getting daily trends" do
should "work" do
- stub_get 'http://search.twitter.com:80/trends/daily.json?', 'trends_daily.json'
+ stub_get 'http://api.twitter.com:80/1/trends/daily.json?', 'trends_daily.json'
trends = Trends.daily
trends.size.should == 480
trends[0].name.should == '#3turnoffwords'
@@ -35,7 +35,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to exclude hastags" do
- stub_get 'http://search.twitter.com:80/trends/daily.json?exclude=hashtags', 'trends_daily_exclude.json'
+ stub_get 'http://api.twitter.com:80/1/trends/daily.json?exclude=hashtags', 'trends_daily_exclude.json'
trends = Trends.daily(:exclude => 'hashtags')
trends.size.should == 480
trends[0].name.should == 'Kobe'
@@ -43,7 +43,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to get for specific date (with date string)" do
- stub_get 'http://search.twitter.com:80/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
+ stub_get 'http://api.twitter.com:80/1/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
trends = Trends.daily(:date => '2009-05-01')
trends.size.should == 440
trends[0].name.should == 'Swine Flu'
@@ -51,7 +51,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to get for specific date (with date object)" do
- stub_get 'http://search.twitter.com:80/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
+ stub_get 'http://api.twitter.com:80/1/trends/daily.json?date=2009-05-01', 'trends_daily_date.json'
trends = Trends.daily(:date => Date.new(2009, 5, 1))
trends.size.should == 440
trends[0].name.should == 'Swine Flu'
@@ -61,7 +61,7 @@ class TrendsTest < Test::Unit::TestCase
context "Getting weekly trends" do
should "work" do
- stub_get 'http://search.twitter.com:80/trends/weekly.json?', 'trends_weekly.json'
+ stub_get 'http://api.twitter.com:80/1/trends/weekly.json?', 'trends_weekly.json'
trends = Trends.weekly
trends.size.should == 210
trends[0].name.should == 'Happy Mothers Day'
@@ -69,7 +69,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to exclude hastags" do
- stub_get 'http://search.twitter.com:80/trends/weekly.json?exclude=hashtags', 'trends_weekly_exclude.json'
+ stub_get 'http://api.twitter.com:80/1/trends/weekly.json?exclude=hashtags', 'trends_weekly_exclude.json'
trends = Trends.weekly(:exclude => 'hashtags')
trends.size.should == 210
trends[0].name.should == 'Happy Mothers Day'
@@ -77,7 +77,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to get for specific date (with date string)" do
- stub_get 'http://search.twitter.com:80/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
+ stub_get 'http://api.twitter.com:80/1/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
trends = Trends.weekly(:date => '2009-05-01')
trends.size.should == 210
trends[0].name.should == 'TGIF'
@@ -85,7 +85,7 @@ class TrendsTest < Test::Unit::TestCase
end
should "be able to get for specific date (with date object)" do
- stub_get 'http://search.twitter.com:80/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
+ stub_get 'http://api.twitter.com:80/1/trends/weekly.json?date=2009-05-01', 'trends_weekly_date.json'
trends = Trends.weekly(:date => Date.new(2009, 5, 1))
trends.size.should == 210
trends[0].name.should == 'TGIF'
@@ -109,4 +109,4 @@ class TrendsTest < Test::Unit::TestCase
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.