instagram-fixed 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +3 -0
  3. data/.yardopts +9 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.md +20 -0
  6. data/README.md +145 -0
  7. data/Rakefile +27 -0
  8. data/instagram.gemspec +37 -0
  9. data/lib/faraday/oauth2.rb +36 -0
  10. data/lib/faraday/raise_http_4xx.rb +37 -0
  11. data/lib/faraday/raise_http_5xx.rb +29 -0
  12. data/lib/instagram.rb +26 -0
  13. data/lib/instagram/api.rb +23 -0
  14. data/lib/instagram/client.rb +20 -0
  15. data/lib/instagram/client/comments.rb +62 -0
  16. data/lib/instagram/client/geographies.rb +29 -0
  17. data/lib/instagram/client/likes.rb +58 -0
  18. data/lib/instagram/client/locations.rb +59 -0
  19. data/lib/instagram/client/media.rb +63 -0
  20. data/lib/instagram/client/subscriptions.rb +157 -0
  21. data/lib/instagram/client/tags.rb +59 -0
  22. data/lib/instagram/client/users.rb +309 -0
  23. data/lib/instagram/client/utils.rb +15 -0
  24. data/lib/instagram/configuration.rb +90 -0
  25. data/lib/instagram/connection.rb +31 -0
  26. data/lib/instagram/error.rb +19 -0
  27. data/lib/instagram/oauth.rb +27 -0
  28. data/lib/instagram/request.rb +45 -0
  29. data/lib/instagram/version.rb +3 -0
  30. data/spec/faraday/response_spec.rb +28 -0
  31. data/spec/fixtures/access_token.json +9 -0
  32. data/spec/fixtures/approve_user.json +8 -0
  33. data/spec/fixtures/block_user.json +8 -0
  34. data/spec/fixtures/deny_user.json +8 -0
  35. data/spec/fixtures/follow_user.json +8 -0
  36. data/spec/fixtures/followed_by.json +1 -0
  37. data/spec/fixtures/follows.json +1 -0
  38. data/spec/fixtures/geography_recent_media.json +1 -0
  39. data/spec/fixtures/liked_media.json +1 -0
  40. data/spec/fixtures/location.json +1 -0
  41. data/spec/fixtures/location_recent_media.json +1 -0
  42. data/spec/fixtures/location_search.json +1 -0
  43. data/spec/fixtures/media.json +1 -0
  44. data/spec/fixtures/media_comment.json +1 -0
  45. data/spec/fixtures/media_comment_deleted.json +1 -0
  46. data/spec/fixtures/media_comments.json +1 -0
  47. data/spec/fixtures/media_liked.json +1 -0
  48. data/spec/fixtures/media_likes.json +1 -0
  49. data/spec/fixtures/media_popular.json +1 -0
  50. data/spec/fixtures/media_search.json +1 -0
  51. data/spec/fixtures/media_unliked.json +1 -0
  52. data/spec/fixtures/mikeyk.json +1 -0
  53. data/spec/fixtures/recent_media.json +1 -0
  54. data/spec/fixtures/relationship.json +9 -0
  55. data/spec/fixtures/requested_by.json +12 -0
  56. data/spec/fixtures/shayne.json +1 -0
  57. data/spec/fixtures/subscription.json +12 -0
  58. data/spec/fixtures/subscription_deleted.json +1 -0
  59. data/spec/fixtures/subscription_payload.json +14 -0
  60. data/spec/fixtures/subscriptions.json +22 -0
  61. data/spec/fixtures/tag.json +1 -0
  62. data/spec/fixtures/tag_recent_media.json +1 -0
  63. data/spec/fixtures/tag_search.json +1 -0
  64. data/spec/fixtures/unblock_user.json +8 -0
  65. data/spec/fixtures/unfollow_user.json +8 -0
  66. data/spec/fixtures/user_media_feed.json +1 -0
  67. data/spec/fixtures/user_search.json +1 -0
  68. data/spec/instagram/api_spec.rb +110 -0
  69. data/spec/instagram/client/comments_spec.rb +71 -0
  70. data/spec/instagram/client/geography_spec.rb +37 -0
  71. data/spec/instagram/client/likes_spec.rb +66 -0
  72. data/spec/instagram/client/locations_spec.rb +78 -0
  73. data/spec/instagram/client/media_spec.rb +78 -0
  74. data/spec/instagram/client/subscriptions_spec.rb +148 -0
  75. data/spec/instagram/client/tags_spec.rb +78 -0
  76. data/spec/instagram/client/users_spec.rb +400 -0
  77. data/spec/instagram/client_spec.rb +23 -0
  78. data/spec/instagram_spec.rb +97 -0
  79. data/spec/spec_helper.rb +59 -0
  80. metadata +253 -0
@@ -0,0 +1,400 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe Instagram::Client do
4
+ Instagram::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Instagram::Client.new(:format => format, :client_id => 'CID', :client_secret => 'CS', :access_token => 'AT')
8
+ end
9
+
10
+ describe ".user" do
11
+
12
+ context "with user ID passed" do
13
+
14
+ before do
15
+ stub_get("users/4.#{format}").
16
+ with(:query => {:access_token => @client.access_token}).
17
+ to_return(:body => fixture("mikeyk.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
18
+ end
19
+
20
+ it "should get the correct resource" do
21
+ @client.user(4)
22
+ a_get("users/4.#{format}").
23
+ with(:query => {:access_token => @client.access_token}).
24
+ should have_been_made
25
+ end
26
+
27
+ it "should return extended information of a given user" do
28
+ user = @client.user(4)
29
+ user.full_name.should == "Mike Krieger"
30
+ end
31
+
32
+ end
33
+
34
+ context "without user ID passed" do
35
+
36
+ before do
37
+ stub_get("users/self.#{format}").
38
+ with(:query => {:access_token => @client.access_token}).
39
+ to_return(:body => fixture("shayne.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ @client.user()
44
+ a_get("users/self.#{format}").
45
+ with(:query => {:access_token => @client.access_token}).
46
+ should have_been_made
47
+ end
48
+ end
49
+ end
50
+
51
+ describe ".user_search" do
52
+
53
+ before do
54
+ stub_get("users/search.#{format}").
55
+ with(:query => {:access_token => @client.access_token}).
56
+ with(:query => {:q => "Shayne Sweeney"}).
57
+ to_return(:body => fixture("user_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
58
+ end
59
+
60
+ it "should get the correct resource" do
61
+ @client.user_search("Shayne Sweeney")
62
+ a_get("users/search.#{format}").
63
+ with(:query => {:access_token => @client.access_token}).
64
+ with(:query => {:q => "Shayne Sweeney"}).
65
+ should have_been_made
66
+ end
67
+
68
+ it "should return an array of user search results" do
69
+ users = @client.user_search("Shayne Sweeney")
70
+ users.should be_a Array
71
+ users.first.username.should == "shayne"
72
+ end
73
+ end
74
+
75
+ describe ".user_follows" do
76
+
77
+ context "with user ID passed" do
78
+
79
+ before do
80
+ stub_get("users/4/follows.#{format}").
81
+ with(:query => {:access_token => @client.access_token}).
82
+ to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
83
+ end
84
+
85
+ it "should get the correct resource" do
86
+ @client.user_follows(4)
87
+ a_get("users/4/follows.#{format}").
88
+ with(:query => {:access_token => @client.access_token}).
89
+ should have_been_made
90
+ end
91
+
92
+ it "should return a list of users whom a given user follows" do
93
+ follows = @client.user_follows(4)
94
+ follows.should be_a Array
95
+ follows.first.username.should == "heartsf"
96
+ end
97
+ end
98
+
99
+ context "without user ID passed" do
100
+
101
+ before do
102
+ stub_get("users/self/follows.#{format}").
103
+ with(:query => {:access_token => @client.access_token}).
104
+ to_return(:body => fixture("follows.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
105
+ end
106
+
107
+ it "should get the correct resource" do
108
+ @client.user_follows
109
+ a_get("users/self/follows.#{format}").
110
+ with(:query => {:access_token => @client.access_token}).
111
+ should have_been_made
112
+ end
113
+ end
114
+ end
115
+
116
+ describe ".user_followed_by" do
117
+
118
+ context "with user ID passed" do
119
+
120
+ before do
121
+ stub_get("users/4/followed-by.#{format}").
122
+ with(:query => {:access_token => @client.access_token}).
123
+ to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
124
+ end
125
+
126
+ it "should get the correct resource" do
127
+ @client.user_followed_by(4)
128
+ a_get("users/4/followed-by.#{format}").
129
+ with(:query => {:access_token => @client.access_token}).
130
+ should have_been_made
131
+ end
132
+
133
+ it "should return a list of users whom a given user is followed by" do
134
+ followed_by = @client.user_followed_by(4)
135
+ followed_by.should be_a Array
136
+ followed_by.first.username.should == "bojieyang"
137
+ end
138
+ end
139
+
140
+ context "without user ID passed" do
141
+
142
+ before do
143
+ stub_get("users/self/followed-by.#{format}").
144
+ with(:query => {:access_token => @client.access_token}).
145
+ to_return(:body => fixture("followed_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
146
+ end
147
+
148
+ it "should get the correct resource" do
149
+ @client.user_followed_by
150
+ a_get("users/self/followed-by.#{format}").
151
+ with(:query => {:access_token => @client.access_token}).
152
+ should have_been_made
153
+ end
154
+ end
155
+ end
156
+
157
+ describe ".user_media_feed" do
158
+
159
+ before do
160
+ stub_get("users/self/feed.#{format}").
161
+ with(:query => {:access_token => @client.access_token}).
162
+ to_return(:body => fixture("user_media_feed.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
163
+ end
164
+
165
+ it "should get the correct resource" do
166
+ @client.user_media_feed
167
+ a_get("users/self/feed.#{format}").
168
+ with(:query => {:access_token => @client.access_token}).
169
+ should have_been_made
170
+ end
171
+ end
172
+
173
+ describe ".user_liked_media" do
174
+
175
+ before do
176
+ stub_get("users/self/media/liked.#{format}").
177
+ with(:query => {:access_token => @client.access_token}).
178
+ to_return(:body => fixture("liked_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
179
+ end
180
+
181
+ it "should get the correct resource" do
182
+ @client.user_liked_media
183
+ a_get("users/self/media/liked.#{format}").
184
+ with(:query => {:access_token => @client.access_token}).
185
+ should have_been_made
186
+ end
187
+ end
188
+
189
+ describe ".user_recent_media" do
190
+
191
+ context "with user ID passed" do
192
+
193
+ before do
194
+ stub_get("users/4/media/recent.#{format}").
195
+ with(:query => {:access_token => @client.access_token}).
196
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
197
+ end
198
+
199
+ it "should get the correct resource" do
200
+ @client.user_recent_media(4)
201
+ a_get("users/4/media/recent.#{format}").
202
+ with(:query => {:access_token => @client.access_token}).
203
+ should have_been_made
204
+ end
205
+
206
+ it "should return a list of recent media items for the given user" do
207
+ recent_media = @client.user_recent_media(4)
208
+ recent_media.should be_a Array
209
+ recent_media.first.user.username.should == "shayne"
210
+ end
211
+ end
212
+
213
+ context "without user ID passed" do
214
+
215
+ before do
216
+ stub_get("users/self/media/recent.#{format}").
217
+ with(:query => {:access_token => @client.access_token}).
218
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
219
+ end
220
+
221
+ it "should get the correct resource" do
222
+ @client.user_recent_media
223
+ a_get("users/self/media/recent.#{format}").
224
+ with(:query => {:access_token => @client.access_token}).
225
+ should have_been_made
226
+ end
227
+ end
228
+ end
229
+
230
+ describe ".user_requested_by" do
231
+
232
+ before do
233
+ stub_get("users/self/requested-by.#{format}").
234
+ with(:query => {:access_token => @client.access_token}).
235
+ to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
236
+ end
237
+
238
+ it "should get the correct resource" do
239
+ @client.user_requested_by
240
+ a_get("users/self/requested-by.#{format}").
241
+ with(:query => {:access_token => @client.access_token}).
242
+ should have_been_made
243
+ end
244
+
245
+ it "should return a list of users awaiting approval" do
246
+ users = @client.user_requested_by
247
+ users.should be_a Array
248
+ users.first.username.should == "shayne"
249
+ end
250
+ end
251
+
252
+ describe ".user_relationship" do
253
+
254
+ before do
255
+ stub_get("users/4/relationship.#{format}").
256
+ with(:query => {:access_token => @client.access_token}).
257
+ to_return(:body => fixture("relationship.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
258
+ end
259
+
260
+ it "should get the correct resource" do
261
+ @client.user_relationship(4)
262
+ a_get("users/4/relationship.#{format}").
263
+ with(:query => {:access_token => @client.access_token}).
264
+ should have_been_made
265
+ end
266
+
267
+ it "should return a relationship status response" do
268
+ status = @client.user_relationship(4)
269
+ status.incoming_status.should == "requested_by"
270
+ end
271
+ end
272
+
273
+ describe ".follow_user" do
274
+
275
+ before do
276
+ stub_post("users/4/relationship.#{format}").
277
+ with(:body => {:action => "follow", :access_token => @client.access_token}).
278
+ to_return(:body => fixture("follow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
279
+ end
280
+
281
+ it "should get the correct resource" do
282
+ @client.follow_user(4)
283
+ a_post("users/4/relationship.#{format}").
284
+ with(:body => {:action => "follow", :access_token => @client.access_token}).
285
+ should have_been_made
286
+ end
287
+
288
+ it "should return a relationship status response" do
289
+ status = @client.follow_user(4)
290
+ status.outgoing_status.should == "requested"
291
+ end
292
+ end
293
+
294
+ describe ".unfollow_user" do
295
+
296
+ before do
297
+ stub_post("users/4/relationship.#{format}").
298
+ with(:body => {:action => "unfollow", :access_token => @client.access_token}).
299
+ to_return(:body => fixture("unfollow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
300
+ end
301
+
302
+ it "should get the correct resource" do
303
+ @client.unfollow_user(4)
304
+ a_post("users/4/relationship.#{format}").
305
+ with(:body => {:action => "unfollow", :access_token => @client.access_token}).
306
+ should have_been_made
307
+ end
308
+
309
+ it "should return a relationship status response" do
310
+ status = @client.unfollow_user(4)
311
+ status.outgoing_status.should == "none"
312
+ end
313
+ end
314
+
315
+ describe ".block_user" do
316
+
317
+ before do
318
+ stub_post("users/4/relationship.#{format}").
319
+ with(:body => {:action => "block", :access_token => @client.access_token}).
320
+ to_return(:body => fixture("block_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
321
+ end
322
+
323
+ it "should get the correct resource" do
324
+ @client.block_user(4)
325
+ a_post("users/4/relationship.#{format}").
326
+ with(:body => {:action => "block", :access_token => @client.access_token}).
327
+ should have_been_made
328
+ end
329
+
330
+ it "should return a relationship status response" do
331
+ status = @client.block_user(4)
332
+ status.outgoing_status.should == "none"
333
+ end
334
+ end
335
+
336
+ describe ".unblock_user" do
337
+
338
+ before do
339
+ stub_post("users/4/relationship.#{format}").
340
+ with(:body => {:action => "unblock", :access_token => @client.access_token}).
341
+ to_return(:body => fixture("unblock_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
342
+ end
343
+
344
+ it "should get the correct resource" do
345
+ @client.unblock_user(4)
346
+ a_post("users/4/relationship.#{format}").
347
+ with(:body => {:action => "unblock", :access_token => @client.access_token}).
348
+ should have_been_made
349
+ end
350
+
351
+ it "should return a relationship status response" do
352
+ status = @client.unblock_user(4)
353
+ status.outgoing_status.should == "none"
354
+ end
355
+ end
356
+
357
+ describe ".approve_user" do
358
+
359
+ before do
360
+ stub_post("users/4/relationship.#{format}").
361
+ with(:body => {:action => "approve", :access_token => @client.access_token}).
362
+ to_return(:body => fixture("approve_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
363
+ end
364
+
365
+ it "should get the correct resource" do
366
+ @client.approve_user(4)
367
+ a_post("users/4/relationship.#{format}").
368
+ with(:body => {:action => "approve", :access_token => @client.access_token}).
369
+ should have_been_made
370
+ end
371
+
372
+ it "should return a relationship status response" do
373
+ status = @client.approve_user(4)
374
+ status.outgoing_status.should == "follows"
375
+ end
376
+ end
377
+
378
+ describe ".deny_user" do
379
+
380
+ before do
381
+ stub_post("users/4/relationship.#{format}").
382
+ with(:body => {:action => "deny", :access_token => @client.access_token}).
383
+ to_return(:body => fixture("deny_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
384
+ end
385
+
386
+ it "should get the correct resource" do
387
+ @client.deny_user(4)
388
+ a_post("users/4/relationship.#{format}").
389
+ with(:body => {:action => "deny", :access_token => @client.access_token}).
390
+ should have_been_made
391
+ end
392
+
393
+ it "should return a relationship status response" do
394
+ status = @client.deny_user(4)
395
+ status.outgoing_status.should == "none"
396
+ end
397
+ end
398
+ end
399
+ end
400
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Instagram::Client do
4
+ it "should connect using the endpoint configuration" do
5
+ client = Instagram::Client.new
6
+ endpoint = URI.parse(client.endpoint)
7
+ connection = client.send(:connection).build_url(nil).to_s
8
+ connection.should == endpoint.to_s
9
+ end
10
+
11
+ it "should not cache the user account across clients" do
12
+ stub_get("users/self.json").
13
+ with(:query => {:access_token => "at1"}).
14
+ to_return(:body => fixture("shayne.json"), :headers => {:content_type => "application/json; charset=utf-8"})
15
+ client1 = Instagram::Client.new(:access_token => "at1")
16
+ client1.send(:get_username).should == "shayne"
17
+ stub_get("users/self.json").
18
+ with(:query => {:access_token => "at2"}).
19
+ to_return(:body => fixture("mikeyk.json"), :headers => {:content_type => "application/json; charset=utf-8"})
20
+ client2 = Instagram::Client.new(:access_token => "at2")
21
+ client2.send(:get_username).should == "mikeyk"
22
+ end
23
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Instagram do
4
+ after do
5
+ Instagram.reset
6
+ end
7
+
8
+ context "when delegating to a client" do
9
+
10
+ before do
11
+ stub_get("users/self/feed.json").
12
+ to_return(:body => fixture("user_media_feed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
+ end
14
+
15
+ it "should get the correct resource" do
16
+ Instagram.user_media_feed()
17
+ a_get("users/self/feed.json").
18
+ should have_been_made
19
+ end
20
+
21
+ it "should return the same results as a client" do
22
+ Instagram.user_media_feed().should == Instagram::Client.new.user_media_feed()
23
+ end
24
+
25
+ end
26
+
27
+ describe ".client" do
28
+ it "should be a Instagram::Client" do
29
+ Instagram.client.should be_a Instagram::Client
30
+ end
31
+ end
32
+
33
+ describe ".adapter" do
34
+ it "should return the default adapter" do
35
+ Instagram.adapter.should == Instagram::Configuration::DEFAULT_ADAPTER
36
+ end
37
+ end
38
+
39
+ describe ".adapter=" do
40
+ it "should set the adapter" do
41
+ Instagram.adapter = :typhoeus
42
+ Instagram.adapter.should == :typhoeus
43
+ end
44
+ end
45
+
46
+ describe ".endpoint" do
47
+ it "should return the default endpoint" do
48
+ Instagram.endpoint.should == Instagram::Configuration::DEFAULT_ENDPOINT
49
+ end
50
+ end
51
+
52
+ describe ".endpoint=" do
53
+ it "should set the endpoint" do
54
+ Instagram.endpoint = 'http://tumblr.com'
55
+ Instagram.endpoint.should == 'http://tumblr.com'
56
+ end
57
+ end
58
+
59
+ describe ".format" do
60
+ it "should return the default format" do
61
+ Instagram.format.should == Instagram::Configuration::DEFAULT_FORMAT
62
+ end
63
+ end
64
+
65
+ describe ".format=" do
66
+ it "should set the format" do
67
+ Instagram.format = 'xml'
68
+ Instagram.format.should == 'xml'
69
+ end
70
+ end
71
+
72
+ describe ".user_agent" do
73
+ it "should return the default user agent" do
74
+ Instagram.user_agent.should == Instagram::Configuration::DEFAULT_USER_AGENT
75
+ end
76
+ end
77
+
78
+ describe ".user_agent=" do
79
+ it "should set the user_agent" do
80
+ Instagram.user_agent = 'Custom User Agent'
81
+ Instagram.user_agent.should == 'Custom User Agent'
82
+ end
83
+ end
84
+
85
+ describe ".configure" do
86
+
87
+ Instagram::Configuration::VALID_OPTIONS_KEYS.each do |key|
88
+
89
+ it "should set the #{key}" do
90
+ Instagram.configure do |config|
91
+ config.send("#{key}=", key)
92
+ Instagram.send(key).should == key
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end