diff --git a/lib/twitter/api/undocumented.rb b/lib/twitter/api/undocumented.rb index a08c52e46..92274dc65 100644 --- a/lib/twitter/api/undocumented.rb +++ b/lib/twitter/api/undocumented.rb @@ -77,6 +77,21 @@ def statuses_activity(*args) end end + # Returns Tweets count for a URL + # + # @note Undocumented + # @rate_limited No + # @authentication Not required + # @return [Integer] + # @param url [Integer] A URL. + # @param options [Hash] A customizable set of options. + # @example Return Tweet count for http://twitter.com + # Twitter.tweet_count("http://twitter.com/") + def tweet_count(url, options={}) + connection = Faraday.new("https://cdn.api.twitter.com", @connection_options.merge(:builder => @middleware)) + connection.get("/1/urls/count.json", options.merge(:url => url)).body[:count] + end + end end end diff --git a/spec/fixtures/count.json b/spec/fixtures/count.json new file mode 100644 index 000000000..0b839f7c0 --- /dev/null +++ b/spec/fixtures/count.json @@ -0,0 +1 @@ +{"count":13845465,"url":"http:\/\/twitter.com\/"} \ No newline at end of file diff --git a/spec/twitter/api/undocumented_spec.rb b/spec/twitter/api/undocumented_spec.rb index 8a5eb67c1..53204c967 100644 --- a/spec/twitter/api/undocumented_spec.rb +++ b/spec/twitter/api/undocumented_spec.rb @@ -111,4 +111,19 @@ end end + describe "#statuses_activity" do + before do + stub_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"}).to_return(:body => fixture("count.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.tweet_count("http://twitter.com") + expect(a_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"})).to have_been_made + end + it "returns a Tweet count" do + tweet_count = @client.tweet_count("http://twitter.com") + expect(tweet_count).to be_an Integer + expect(tweet_count).to eq 13845465 + end + end + end