Skip to content

Commit

Permalink
Add Twitter::API::Undocumented#tweet_count
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 12, 2013
1 parent 39965bd commit 795458a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/twitter/api/undocumented.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/fixtures/count.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"count":13845465,"url":"http:\/\/twitter.com\/"}
15 changes: 15 additions & 0 deletions spec/twitter/api/undocumented_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.