Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding user_requested_by endpoint, tests and

fixture.
  • Loading branch information...
commit ed5415b50d7be88b231be97cf82402b45ee05dc9 1 parent 162ec24
Shayne Sweeney shayne authored
34 lib/instagram/client/users.rb
@@ -20,7 +20,7 @@ def user(*args)
20 20 response = get("users/#{id}")
21 21 response["data"]
22 22 end
23   -
  23 +
24 24 # Returns users that match the given query
25 25 #
26 26 # @format :json
@@ -37,7 +37,7 @@ def user_search(query, options={})
37 37 response = get('users/search', options.merge(:q => query))
38 38 response["data"]
39 39 end
40   -
  40 +
41 41 # Returns a list of users whom a given user follows
42 42 #
43 43 # @overload follows(id=nil, options={})
@@ -66,15 +66,15 @@ def user_follows(*args)
66 66 response["data"]
67 67 end
68 68 end
69   -
  69 +
70 70 # Returns a list of users whom a given user is followed by
71 71 #
72   - # @overload followed_by(id=nil, options={})
  72 + # @overload user_followed_by(id=nil, options={})
73 73 # @param options [Hash] A customizable set of options.
74 74 # @return [Hashie::Mash]
75 75 # @example Returns a list of users the authenticated user is followed by
76 76 # Instagram.user_followed_by
77   - # @overload followed_by(id=nil, options={})
  77 + # @overload user_followed_by(id=nil, options={})
78 78 # @param user [Integer] An Instagram user ID.
79 79 # @param options [Hash] A customizable set of options.
80 80 # @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)
94 94 response = get("users/#{id}/followed-by", options)
95 95 response["data"]
96 96 end
97   -
  97 +
  98 + # Returns a list of users whom a given user is followed by
  99 + #
  100 + # @overload user_requested_by()
  101 + # @param options [Hash] A customizable set of options.
  102 + # @return [Hashie::Mash]
  103 + # @example Returns a list of users awaiting approval of a ollow request, for the authenticated user
  104 + # Instagram.user_requested_by
  105 + # @overload user_requested_by()
  106 + # @return [Hashie::Mash]
  107 + # @example Return a list of users who have requested to follow the authenticated user
  108 + # Instagram.user_requested_by()
  109 + # @see TODO:docs url
  110 + # @format :json
  111 + # @authenticated truei
  112 + # @rate_limited true
  113 + def user_requested_by()
  114 + response = get("users/self/requested-by")
  115 + response["data"]
  116 + end
  117 +
98 118 # Returns the 20 most recent media items from the currently authorized user's feed.
99 119 #
100 120 # @overload user_media_feed(options={})
@@ -113,7 +133,7 @@ def user_media_feed(*args)
113 133 response = get('users/self/feed', options)
114 134 response["data"]
115 135 end
116   -
  136 +
117 137 # Returns a list of recent media items for a given user
118 138 #
119 139 # @overload user_recent_media(id=nil, options={})
12 spec/fixtures/requested_by.json
... ... @@ -0,0 +1,12 @@
  1 +{
  2 + "meta": {
  3 + "code": 200
  4 + },
  5 + "data": [
  6 + {
  7 + "username": "shayne",
  8 + "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_20_75sq_1295492590_debug.jpg",
  9 + "id": "20"
  10 + }]
  11 +}
  12 +
102 spec/instagram/client/users_spec.rb
@@ -6,32 +6,32 @@
6 6 before do
7 7 @client = Instagram::Client.new(:format => format, :client_id => 'CID', :access_token => 'AT')
8 8 end
9   -
  9 +
10 10 describe ".user" do
11   -
  11 +
12 12 context "with user ID passed" do
13   -
  13 +
14 14 before do
15 15 stub_get("users/4.#{format}").
16 16 with(:query => {:access_token => @client.access_token}).
17 17 to_return(:body => fixture("mikeyk.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
18 18 end
19   -
  19 +
20 20 it "should get the correct resource" do
21 21 @client.user(4)
22 22 a_get("users/4.#{format}").
23 23 with(:query => {:access_token => @client.access_token}).
24 24 should have_been_made
25 25 end
26   -
  26 +
27 27 it "should return extended information of a given user" do
28 28 user = @client.user(4)
29 29 user.first_name.should == "Mike"
30 30 user.last_name.should == "Krieger"
31 31 end
32   -
  32 +
33 33 end
34   -
  34 +
35 35 context "without user ID passed" do
36 36
37 37 before do
@@ -48,16 +48,16 @@
48 48 end
49 49 end
50 50 end
51   -
  51 +
52 52 describe ".user_search" do
53   -
  53 +
54 54 before do
55 55 stub_get("users/search.#{format}").
56 56 with(:query => {:access_token => @client.access_token}).
57 57 with(:query => {:q => "Shayne Sweeney"}).
58 58 to_return(:body => fixture("user_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
59 59 end
60   -
  60 +
61 61 it "should get the correct resource" do
62 62 @client.user_search("Shayne Sweeney")
63 63 a_get("users/search.#{format}").
@@ -65,46 +65,46 @@
65 65 with(:query => {:q => "Shayne Sweeney"}).
66 66 should have_been_made
67 67 end
68   -
  68 +
69 69 it "should return an array of user search results" do
70 70 users = @client.user_search("Shayne Sweeney")
71 71 users.should be_a Array
72 72 users.first.username.should == "shayne"
73 73 end
74 74 end
75   -
  75 +
76 76 describe ".user_follows" do
77   -
  77 +
78 78 context "with user ID passed" do
79   -
  79 +
80 80 before do
81 81 stub_get("users/4/follows.#{format}").
82 82 with(:query => {:access_token => @client.access_token}).
83 83 to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
84 84 end
85   -
  85 +
86 86 it "should get the correct resource" do
87 87 @client.user_follows(4)
88 88 a_get("users/4/follows.#{format}").
89 89 with(:query => {:access_token => @client.access_token}).
90 90 should have_been_made
91 91 end
92   -
  92 +
93 93 it "should return a list of users whom a given user follows" do
94 94 follows = @client.user_follows(4)
95 95 follows.should be_a Array
96 96 follows.first.username.should == "heartsf"
97 97 end
98 98 end
99   -
  99 +
100 100 context "without user ID passed" do
101   -
  101 +
102 102 before do
103 103 stub_get("users/self/follows.#{format}").
104 104 with(:query => {:access_token => @client.access_token}).
105 105 to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
106 106 end
107   -
  107 +
108 108 it "should get the correct resource" do
109 109 @client.user_follows
110 110 a_get("users/self/follows.#{format}").
@@ -113,39 +113,39 @@
113 113 end
114 114 end
115 115 end
116   -
  116 +
117 117 describe ".user_followed_by" do
118   -
  118 +
119 119 context "with user ID passed" do
120   -
  120 +
121 121 before do
122 122 stub_get("users/4/followed-by.#{format}").
123 123 with(:query => {:access_token => @client.access_token}).
124 124 to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
125 125 end
126   -
  126 +
127 127 it "should get the correct resource" do
128 128 @client.user_followed_by(4)
129 129 a_get("users/4/followed-by.#{format}").
130 130 with(:query => {:access_token => @client.access_token}).
131 131 should have_been_made
132 132 end
133   -
  133 +
134 134 it "should return a list of users whom a given user is followed by" do
135 135 followed_by = @client.user_followed_by(4)
136 136 followed_by.should be_a Array
137 137 followed_by.first.username.should == "bojieyang"
138 138 end
139 139 end
140   -
  140 +
141 141 context "without user ID passed" do
142   -
  142 +
143 143 before do
144 144 stub_get("users/self/followed-by.#{format}").
145 145 with(:query => {:access_token => @client.access_token}).
146 146 to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
147 147 end
148   -
  148 +
149 149 it "should get the correct resource" do
150 150 @client.user_followed_by
151 151 a_get("users/self/followed-by.#{format}").
@@ -154,15 +154,15 @@
154 154 end
155 155 end
156 156 end
157   -
  157 +
158 158 describe ".user_media_feed" do
159   -
  159 +
160 160 before do
161 161 stub_get("users/self/feed.#{format}").
162 162 with(:query => {:access_token => @client.access_token}).
163 163 to_return(:body => fixture("user_media_feed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
164 164 end
165   -
  165 +
166 166 it "should get the correct resource" do
167 167 @client.user_media_feed
168 168 a_get("users/self/feed.#{format}").
@@ -170,47 +170,69 @@
170 170 should have_been_made
171 171 end
172 172 end
173   -
  173 +
174 174 describe ".user_recent_media" do
175   -
  175 +
176 176 context "with user ID passed" do
177   -
  177 +
178 178 before do
179 179 stub_get("users/4/media/recent.#{format}").
180 180 with(:query => {:access_token => @client.access_token}).
181 181 to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
182 182 end
183   -
  183 +
184 184 it "should get the correct resource" do
185 185 @client.user_recent_media(4)
186 186 a_get("users/4/media/recent.#{format}").
187 187 with(:query => {:access_token => @client.access_token}).
188 188 should have_been_made
189 189 end
190   -
  190 +
191 191 it "should return a list of recent media items for the given user" do
192 192 recent_media = @client.user_recent_media(4)
193 193 recent_media.should be_a Array
194 194 recent_media.first.user.username.should == "shayne"
195 195 end
196 196 end
197   -
  197 +
198 198 context "without user ID passed" do
199   -
  199 +
200 200 before do
201 201 stub_get("users/self/media/recent.#{format}").
202 202 with(:query => {:access_token => @client.access_token}).
203 203 to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
204 204 end
205   -
  205 +
206 206 it "should get the correct resource" do
207 207 @client.user_recent_media
208 208 a_get("users/self/media/recent.#{format}").
209 209 with(:query => {:access_token => @client.access_token}).
210 210 should have_been_made
211   - end
  211 + end
  212 + end
  213 + end
  214 +
  215 + describe ".user_requested_by" do
  216 +
  217 + before do
  218 + stub_get("users/self/requested-by.#{format}").
  219 + with(:query => {:access_token => @client.access_token}).
  220 + to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
  221 + end
  222 +
  223 + it "should get the correct resource" do
  224 + @client.user_requested_by
  225 + a_get("users/self/requested-by.#{format}").
  226 + with(:query => {:access_token => @client.access_token}).
  227 + should have_been_made
  228 + end
  229 +
  230 + it "should return a list of users awaiting approval" do
  231 + users = @client.user_requested_by
  232 + users.should be_a Array
  233 + users.first.username.should == "shayne"
212 234 end
213 235 end
214 236 end
215 237 end
216   -end
  238 +end

0 comments on commit ed5415b

Please sign in to comment.
Something went wrong with that request. Please try again.