Permalink
Browse files

Adding user_requested_by endpoint, tests and

fixture.
  • Loading branch information...
1 parent 162ec24 commit ed5415b50d7be88b231be97cf82402b45ee05dc9 @shayne shayne committed Feb 14, 2011
Showing with 101 additions and 47 deletions.
  1. +27 −7 lib/instagram/client/users.rb
  2. +12 −0 spec/fixtures/requested_by.json
  3. +62 −40 spec/instagram/client/users_spec.rb
@@ -20,7 +20,7 @@ def user(*args)
response = get("users/#{id}")
response["data"]
end
-
+
# Returns users that match the given query
#
# @format :json
@@ -37,7 +37,7 @@ def user_search(query, options={})
response = get('users/search', options.merge(:q => query))
response["data"]
end
-
+
# Returns a list of users whom a given user follows
#
# @overload follows(id=nil, options={})
@@ -66,15 +66,15 @@ def user_follows(*args)
response["data"]
end
end
-
+
# Returns a list of users whom a given user is followed by
#
- # @overload followed_by(id=nil, options={})
+ # @overload user_followed_by(id=nil, options={})
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash]
# @example Returns a list of users the authenticated user is followed by
# Instagram.user_followed_by
- # @overload followed_by(id=nil, options={})
+ # @overload user_followed_by(id=nil, options={})
# @param user [Integer] An Instagram user ID.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (nil) Breaks the results into pages. Provide values as returned in the response objects's next_cursor attribute to page forward in the list.
@@ -94,7 +94,27 @@ def user_followed_by(*args)
response = get("users/#{id}/followed-by", options)
response["data"]
end
-
+
+ # Returns a list of users whom a given user is followed by
+ #
+ # @overload user_requested_by()
+ # @param options [Hash] A customizable set of options.
+ # @return [Hashie::Mash]
+ # @example Returns a list of users awaiting approval of a ollow request, for the authenticated user
+ # Instagram.user_requested_by
+ # @overload user_requested_by()
+ # @return [Hashie::Mash]
+ # @example Return a list of users who have requested to follow the authenticated user
+ # Instagram.user_requested_by()
+ # @see TODO:docs url
+ # @format :json
+ # @authenticated truei
+ # @rate_limited true
+ def user_requested_by()
+ response = get("users/self/requested-by")
+ response["data"]
+ end
+
# Returns the 20 most recent media items from the currently authorized user's feed.
#
# @overload user_media_feed(options={})
@@ -113,7 +133,7 @@ def user_media_feed(*args)
response = get('users/self/feed', options)
response["data"]
end
-
+
# Returns a list of recent media items for a given user
#
# @overload user_recent_media(id=nil, options={})
@@ -0,0 +1,12 @@
+{
+ "meta": {
+ "code": 200
+ },
+ "data": [
+ {
+ "username": "shayne",
+ "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_20_75sq_1295492590_debug.jpg",
+ "id": "20"
+ }]
+}
+
@@ -6,32 +6,32 @@
before do
@client = Instagram::Client.new(:format => format, :client_id => 'CID', :access_token => 'AT')
end
-
+
describe ".user" do
-
+
context "with user ID passed" do
-
+
before do
stub_get("users/4.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("mikeyk.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user(4)
a_get("users/4.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
-
+
it "should return extended information of a given user" do
user = @client.user(4)
user.first_name.should == "Mike"
user.last_name.should == "Krieger"
end
-
+
end
-
+
context "without user ID passed" do
before do
@@ -48,63 +48,63 @@
end
end
end
-
+
describe ".user_search" do
-
+
before do
stub_get("users/search.#{format}").
with(:query => {:access_token => @client.access_token}).
with(:query => {:q => "Shayne Sweeney"}).
to_return(:body => fixture("user_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_search("Shayne Sweeney")
a_get("users/search.#{format}").
with(:query => {:access_token => @client.access_token}).
with(:query => {:q => "Shayne Sweeney"}).
should have_been_made
end
-
+
it "should return an array of user search results" do
users = @client.user_search("Shayne Sweeney")
users.should be_a Array
users.first.username.should == "shayne"
end
end
-
+
describe ".user_follows" do
-
+
context "with user ID passed" do
-
+
before do
stub_get("users/4/follows.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_follows(4)
a_get("users/4/follows.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
-
+
it "should return a list of users whom a given user follows" do
follows = @client.user_follows(4)
follows.should be_a Array
follows.first.username.should == "heartsf"
end
end
-
+
context "without user ID passed" do
-
+
before do
stub_get("users/self/follows.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_follows
a_get("users/self/follows.#{format}").
@@ -113,39 +113,39 @@
end
end
end
-
+
describe ".user_followed_by" do
-
+
context "with user ID passed" do
-
+
before do
stub_get("users/4/followed-by.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_followed_by(4)
a_get("users/4/followed-by.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
-
+
it "should return a list of users whom a given user is followed by" do
followed_by = @client.user_followed_by(4)
followed_by.should be_a Array
followed_by.first.username.should == "bojieyang"
end
end
-
+
context "without user ID passed" do
-
+
before do
stub_get("users/self/followed-by.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_followed_by
a_get("users/self/followed-by.#{format}").
@@ -154,63 +154,85 @@
end
end
end
-
+
describe ".user_media_feed" do
-
+
before do
stub_get("users/self/feed.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("user_media_feed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_media_feed
a_get("users/self/feed.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
end
-
+
describe ".user_recent_media" do
-
+
context "with user ID passed" do
-
+
before do
stub_get("users/4/media/recent.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_recent_media(4)
a_get("users/4/media/recent.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
end
-
+
it "should return a list of recent media items for the given user" do
recent_media = @client.user_recent_media(4)
recent_media.should be_a Array
recent_media.first.user.username.should == "shayne"
end
end
-
+
context "without user ID passed" do
-
+
before do
stub_get("users/self/media/recent.#{format}").
with(:query => {:access_token => @client.access_token}).
to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end
-
+
it "should get the correct resource" do
@client.user_recent_media
a_get("users/self/media/recent.#{format}").
with(:query => {:access_token => @client.access_token}).
should have_been_made
- end
+ end
+ end
+ end
+
+ describe ".user_requested_by" do
+
+ before do
+ stub_get("users/self/requested-by.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.user_requested_by
+ a_get("users/self/requested-by.#{format}").
+ with(:query => {:access_token => @client.access_token}).
+ should have_been_made
+ end
+
+ it "should return a list of users awaiting approval" do
+ users = @client.user_requested_by
+ users.should be_a Array
+ users.first.username.should == "shayne"
end
end
end
end
-end
+end

0 comments on commit ed5415b

Please sign in to comment.