Skip to content

Commit

Permalink
Got initial set of tests to work. Adding more tests now
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbon committed Nov 29, 2012
1 parent ce0c97d commit 03e1512
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/twitter/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,66 @@ def friendship(source, target, options={})
def friendship?(source, target, options={})
friendship(source, target, options).source.following?
end


# Returns a cursored collection of user objects for users following the specified user.
#
# @see https://dev.twitter.com/docs/api/1.1/get/followers/list
# @rate_limited Yes
# @authentication_required Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::Cursor]
# @overload friend_ids(options={})
# Returns an array of numeric IDs for every user the authenticated user is following
#
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
# @example Return the authenticated user's friends' IDs
# Twitter.friend_ids
# @overload friend_ids(user, options={})
# Returns an array of numeric IDs for every user the specified user is following
#
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @example Return the cursored collection of users following @sferik
# Twitter.followers('sferik')
# Twitter.followers(7505382) # Same as above
def followers(*args)
merge_default_cursor!(options)
cursor_from_response(:get, "/1.1/followers/list.json", args)
end


# Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
#
# @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
# @rate_limited Yes
# @authentication_required Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::Cursor]
# @overload friend_ids(options={})
# Returns an array of numeric IDs for every user the authenticated user is following
#
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
# @example Return the authenticated user's friends' IDs
# Twitter.friend_ids
# @overload friend_ids(user, options={})
# Returns an array of numeric IDs for every user the specified user is following
#
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @example Return the cursored collection of users @sferik is following
# Twitter.friends('sferik')
# Twitter.friends(7505382) # Same as above
def friends(*args)
options = extract_options!(args)
merge_user!(options, args.pop || screen_name)
merge_default_cursor!(options)
cursor_from_response(:users, Twitter::User, :get, "/1.1/friends/list.json", options)
end
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/friends_list.json

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions spec/twitter/api/friends_and_followers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,77 @@
end
end
end




describe "#friend_ids" do
context "with a screen_name passed" do
before do
stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.friend_ids("sferik")
expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
end
it "returns an array of numeric IDs for every user the specified user is following" do
friend_ids = @client.friend_ids("sferik")
expect(friend_ids).to be_a Twitter::Cursor
expect(friend_ids.ids).to be_an Array
expect(friend_ids.ids.first).to eq 14100886
end
end
context "without arguments passed" do
before do
stub_get("/1.1/friends/ids.json").with(:query => {: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.friend_ids
expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
end
it "returns an array of numeric IDs for every user the specified user is following" do
friend_ids = @client.friend_ids
expect(friend_ids).to be_a Twitter::Cursor
expect(friend_ids.ids).to be_an Array
expect(friend_ids.ids.first).to eq 14100886
end
end
end



describe "#followers" do
end

describe "#friends" do
context "with a screen_name passed" do
before do
stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.friends("sferik")
expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
end
# it "returns an array of followers with details for every user the specified user is following" do
# friends = @client.friends
#
# end
# end
# context "without arguments passed" do
# before do
# stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
# end
# it "requests the correct resource" do
# @client.friends
# expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1"})).to have_been_made
# end
# it "returns an array of followers with details for every user the specified user is following" do
# friends = @client.friends
# expect(friends.first).to be_a Twitter::User
# expect(friends).to be_an Array
# end
end
end


end

0 comments on commit 03e1512

Please sign in to comment.