Skip to content

Commit

Permalink
Add Twitter::API::Tweets#retweeters_ids method
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 30, 2013
1 parent ec22170 commit 8cf5b2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/twitter/api/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ def oembeds(*args)
end
end

# Returns a collection of user IDs belonging to users who have retweeted the specified Tweet.
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
# @rate_limited Yes
# @authentication Required
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Array<Integer>]
# @param options [Hash] A customizable set of options.
# @example Return a collection of user IDs belonging to users who have retweeted the specified Tweet
# Twitter.retweeters_ids(25938088801)
def retweeters_ids(*args)
arguments = Twitter::API::Arguments.new(args)
arguments.options[:id] ||= arguments.first
cursor_from_response(:ids, nil, :get, "/1.1/statuses/retweeters/ids.json", arguments.options, :retweeters_ids)
end

private

# @param request_method [Symbol]
Expand Down
26 changes: 26 additions & 0 deletions spec/twitter/api/tweets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,30 @@
end
end

describe "#retweeters_ids" do
before do
stub_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.retweeters_ids(25938088801)
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"})).to have_been_made
end
it "returns a collection of user IDs belonging to users who have retweeted the specified Tweet" do
retweeters_ids = @client.retweeters_ids(25938088801)
expect(retweeters_ids).to be_a Twitter::Cursor
expect(retweeters_ids.ids).to be_an Array
expect(retweeters_ids.ids.first).to eq 14100886
end
context "with all" do
before do
stub_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.retweeters_ids(25938088801).all
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"})).to have_been_made
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "1305102810874389703"})).to have_been_made
end
end
end

end

0 comments on commit 8cf5b2d

Please sign in to comment.