Browse files

Add Twitter::API::Undocumented#tweet_count

  • Loading branch information...
1 parent 39965bd commit 795458a25ec7b143a995e7f2f2043e523c11961c @sferik committed Jun 12, 2013
Showing with 31 additions and 0 deletions.
  1. +15 −0 lib/twitter/api/undocumented.rb
  2. +1 −0 spec/fixtures/count.json
  3. +15 −0 spec/twitter/api/undocumented_spec.rb
View
15 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
View
1 spec/fixtures/count.json
@@ -0,0 +1 @@
+{"count":13845465,"url":"http:\/\/twitter.com\/"}
View
15 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

0 comments on commit 795458a

Please sign in to comment.