Skip to content
Browse files

Deprecate Trends#trends_current and remove the XML response format

  • Loading branch information...
1 parent e153480 commit f9f0c1f1ddc5057cdb655f645970f771e1ebc702 @sferik committed Sep 13, 2011
View
9 lib/twitter/client/local_trends.rb
@@ -9,16 +9,14 @@ module LocalTrends
# @rate_limited Yes
# @requires_authentication No
# @response_format `json`
- # @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [Float] :lat If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive.
# @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
# @return [Array]
# @example Return the locations that Twitter has trending topic information for
# Twitter.trend_locations
def trend_locations(options={})
- response = get('1/trends/available', options)
- format.to_s.downcase == 'xml' ? response['locations'] : response
+ get('1/trends/available', options, :format => :json)
end
# Returns the top 10 trending topics for a specific WOEID
@@ -27,15 +25,14 @@ def trend_locations(options={})
# @rate_limited Yes
# @requires_authentication No
# @response_format `json`
- # @response_format `xml`
# @param woeid [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::Client::LocalTrends#trend_locations}. Global information is available by using 1 as the WOEID.
# @param options [Hash] A customizable set of options.
# @return [Array]
# @example Return the top 10 trending topics for San Francisco
# Twitter.local_trends(2487956)
def local_trends(woeid=1, options={})
- response = get("1/trends/#{woeid}", options)
- format.to_s.downcase == 'xml' ? response['matching_trends'].first.trend : response.first.trends.map{|trend| trend.name}
+ response = get("1/trends/#{woeid}", options, :format => :json)
+ response.first.trends.map{|trend| trend.name}
end
end
end
View
9 lib/twitter/client/trends.rb
@@ -5,7 +5,7 @@ class Client
module Trends
# Returns the top ten topics that are currently trending on Twitter
#
- # @see https://dev.twitter.com/docs/api/1/get/trends
+ # @see https://dev.twitter.com/docs/api/1/get/trends/:woeid
# @rate_limited Yes
# @requires_authentication No
# @response_format `json`
@@ -14,22 +14,23 @@ module Trends
# @example Return the top ten topics that are currently trending on Twitter
# Twitter.trends
def trends(options={})
- get('1/trends', options, :format => :json)['trends']
+ local_trends(1, options)
end
# Returns the current top 10 trending topics on Twitter
#
# @see https://dev.twitter.com/docs/api/1/get/trends/current
+ # @deprecated {Twitter::Client::Trends#trends_current} is deprecated and will be removed in the next major version. Please use {Twitter::Client::Trends#trends} instead.
# @rate_limited Yes
# @requires_authentication No
# @response_format `json`
# @param options [Hash] A customizable set of options.
- # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
# @return [Array]
# @example Return the current top 10 trending topics on Twitter
# Twitter.trends_current
def trends_current(options={})
- get('1/trends/current', options, :format => :json)['trends']
+ warn "#{caller.first}: [DEPRECATION] #trends_current is deprecated and will be removed in the next major version. Please use #trends instead."
+ local_trends(1, options)
end
# Returns the top 20 trending topics for each hour in a given day
View
104 spec/twitter/client/local_trends_spec.rb
@@ -1,75 +1,71 @@
require 'helper'
describe Twitter::Client do
- %w(json xml).each do |format|
- context ".new(:format => '#{format}')" do
- before do
- @client = Twitter::Client.new(:format => format)
- end
+ before do
+ @client = Twitter::Client.new
+ end
- describe ".trend_locations" do
+ describe ".trend_locations" do
- before do
- stub_get("1/trends/available.#{format}").
- to_return(:body => fixture("locations.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
+ before do
+ stub_get("1/trends/available.json").
+ to_return(:body => fixture("locations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
- it "should get the correct resource" do
- @client.trend_locations
- a_get("1/trends/available.#{format}").
- should have_been_made
- end
+ it "should get the correct resource" do
+ @client.trend_locations
+ a_get("1/trends/available.json").
+ should have_been_made
+ end
- it "should return the locations that Twitter has trending topic information for" do
- locations = @client.trend_locations
- locations.should be_an Array
- locations.first.name.should == "Ireland"
- end
+ it "should return the locations that Twitter has trending topic information for" do
+ locations = @client.trend_locations
+ locations.should be_an Array
+ locations.first.name.should == "Ireland"
+ end
- end
+ end
- describe ".local_trends" do
+ describe ".local_trends" do
- context "with woeid passed" do
+ context "with woeid passed" do
- before do
- stub_get("1/trends/2487956.#{format}").
- to_return(:body => fixture("matching_trends.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
+ before do
+ stub_get("1/trends/2487956.json").
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
- it "should get the correct resource" do
- @client.local_trends(2487956)
- a_get("1/trends/2487956.#{format}").
- should have_been_made
- end
+ it "should get the correct resource" do
+ @client.local_trends(2487956)
+ a_get("1/trends/2487956.json").
+ should have_been_made
+ end
- it "should return the top 10 trending topics for a specific WOEID" do
- matching_trends = @client.local_trends(2487956)
- matching_trends.should be_an Array
- matching_trends.first.should == "#sevenwordsaftersex"
- end
+ it "should return the top 10 trending topics for a specific WOEID" do
+ matching_trends = @client.local_trends(2487956)
+ matching_trends.should be_an Array
+ matching_trends.first.should == "#sevenwordsaftersex"
+ end
- end
+ end
- context "without arguments passed" do
+ context "without arguments passed" do
- before do
- stub_get("1/trends/1.#{format}").
- to_return(:body => fixture("matching_trends.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
- end
+ before do
+ stub_get("1/trends/1.json").
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
- it "should get the correct resource" do
- @client.local_trends
- a_get("1/trends/1.#{format}").
- should have_been_made
- end
+ it "should get the correct resource" do
+ @client.local_trends
+ a_get("1/trends/1.json").
+ should have_been_made
+ end
- it "should return the top 10 trending topics worldwide" do
- matching_trends = @client.local_trends
- matching_trends.should be_an Array
- matching_trends.first.should == "#sevenwordsaftersex"
- end
- end
+ it "should return the top 10 trending topics worldwide" do
+ matching_trends = @client.local_trends
+ matching_trends.should be_an Array
+ matching_trends.first.should == "#sevenwordsaftersex"
end
end
end
View
174 spec/twitter/client/trends_spec.rb
@@ -1,94 +1,92 @@
require 'helper'
describe Twitter::Client do
- %w(json xml).each do |format|
- context ".new(:format => '#{format}')" do
- before do
- @client = Twitter::Client.new(:format => format)
- end
-
- describe ".trends" do
-
- before do
- stub_get("1/trends.json").
- to_return(:body => fixture("trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- end
-
- it "should get the correct resource" do
- @client.trends
- a_get("1/trends.json").
- should have_been_made
- end
-
- it "should return the top ten topics that are currently trending on Twitter" do
- trends = @client.trends
- trends.first.name.should == "Isaacs"
- end
-
- end
-
- describe ".trends_current" do
-
- before do
- stub_get("1/trends/current.json").
- to_return(:body => fixture("trends_current.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- end
-
- it "should get the correct resource" do
- @client.trends_current
- a_get("1/trends/current.json").
- should have_been_made
- end
-
- it "should return the current top 10 trending topics on Twitter" do
- trends = @client.trends_current
- trends["2010-10-25 16:00:00"].first.name.should == "Isaacs"
- end
-
- end
-
- describe ".trends_daily" do
-
- before do
- stub_get("1/trends/daily.json").
- with(:query => {:date => "2010-10-24"}).
- to_return(:body => fixture("trends_daily.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- end
-
- it "should get the correct resource" do
- @client.trends_daily(Date.parse("2010-10-24"))
- a_get("1/trends/daily.json").
- with(:query => {:date => "2010-10-24"}).
- should have_been_made
- end
-
- it "should return the top 20 trending topics for each hour in a given day" do
- trends = @client.trends_daily(Date.parse("2010-10-24"))
- trends["2010-10-24 17:00"].first.name.should == "#bigbangcomeback"
- end
-
- end
-
- describe ".trends_weekly" do
-
- before do
- stub_get("1/trends/weekly.json").
- with(:query => {:date => "2010-10-24"}).
- to_return(:body => fixture("trends_weekly.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- end
-
- it "should get the correct resource" do
- @client.trends_weekly(Date.parse("2010-10-24"))
- a_get("1/trends/weekly.json").
- with(:query => {:date => "2010-10-24"}).
- should have_been_made
- end
-
- it "should return the top 30 trending topics for each day in a given week" do
- trends = @client.trends_weekly(Date.parse("2010-10-24"))
- trends["2010-10-23"].first.name.should == "#unfollowmeif"
- end
- end
+ before do
+ @client = Twitter::Client.new
+ end
+
+ describe ".trends" do
+
+ before do
+ stub_get("1/trends/1.json").
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.trends
+ a_get("1/trends/1.json").
+ should have_been_made
+ end
+
+ it "should return the top ten topics that are currently trending on Twitter" do
+ trends = @client.trends
+ trends.should be_an Array
+ trends.first.should == "#sevenwordsaftersex"
+ end
+
+ end
+
+ describe ".trends_current" do
+
+ before do
+ stub_get("1/trends/1.json").
+ to_return(:body => fixture("matching_trends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.trends_current
+ a_get("1/trends/1.json").
+ should have_been_made
+ end
+
+ it "should return the current top 10 trending topics on Twitter" do
+ trends_current = @client.trends_current
+ trends_current.should be_an Array
+ trends_current.first.should == "#sevenwordsaftersex"
+ end
+
+ end
+
+ describe ".trends_daily" do
+
+ before do
+ stub_get("1/trends/daily.json").
+ with(:query => {:date => "2010-10-24"}).
+ to_return(:body => fixture("trends_daily.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.trends_daily(Date.parse("2010-10-24"))
+ a_get("1/trends/daily.json").
+ with(:query => {:date => "2010-10-24"}).
+ should have_been_made
+ end
+
+ it "should return the top 20 trending topics for each hour in a given day" do
+ trends = @client.trends_daily(Date.parse("2010-10-24"))
+ trends["2010-10-24 17:00"].first.name.should == "#bigbangcomeback"
+ end
+
+ end
+
+ describe ".trends_weekly" do
+
+ before do
+ stub_get("1/trends/weekly.json").
+ with(:query => {:date => "2010-10-24"}).
+ to_return(:body => fixture("trends_weekly.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.trends_weekly(Date.parse("2010-10-24"))
+ a_get("1/trends/weekly.json").
+ with(:query => {:date => "2010-10-24"}).
+ should have_been_made
+ end
+
+ it "should return the top 30 trending topics for each day in a given week" do
+ trends = @client.trends_weekly(Date.parse("2010-10-24"))
+ trends["2010-10-23"].first.name.should == "#unfollowmeif"
end
end
end

0 comments on commit f9f0c1f

Please sign in to comment.
Something went wrong with that request. Please try again.