instagram-community-maintained 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +9 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.md +30 -0
  8. data/PATENTS.md +23 -0
  9. data/README.md +261 -0
  10. data/Rakefile +27 -0
  11. data/instagram.gemspec +53 -0
  12. data/lib/faraday/loud_logger.rb +75 -0
  13. data/lib/faraday/oauth2.rb +42 -0
  14. data/lib/faraday/raise_http_exception.rb +59 -0
  15. data/lib/instagram.rb +27 -0
  16. data/lib/instagram/api.rb +31 -0
  17. data/lib/instagram/client.rb +21 -0
  18. data/lib/instagram/client/comments.rb +62 -0
  19. data/lib/instagram/client/embedding.rb +28 -0
  20. data/lib/instagram/client/geographies.rb +29 -0
  21. data/lib/instagram/client/likes.rb +58 -0
  22. data/lib/instagram/client/locations.rb +75 -0
  23. data/lib/instagram/client/media.rb +82 -0
  24. data/lib/instagram/client/subscriptions.rb +211 -0
  25. data/lib/instagram/client/tags.rb +59 -0
  26. data/lib/instagram/client/users.rb +310 -0
  27. data/lib/instagram/client/utils.rb +28 -0
  28. data/lib/instagram/configuration.rb +122 -0
  29. data/lib/instagram/connection.rb +31 -0
  30. data/lib/instagram/error.rb +31 -0
  31. data/lib/instagram/oauth.rb +36 -0
  32. data/lib/instagram/request.rb +82 -0
  33. data/lib/instagram/response.rb +21 -0
  34. data/lib/instagram/version.rb +3 -0
  35. data/spec/faraday/response_spec.rb +86 -0
  36. data/spec/fixtures/access_token.json +9 -0
  37. data/spec/fixtures/approve_user.json +8 -0
  38. data/spec/fixtures/block_user.json +8 -0
  39. data/spec/fixtures/deny_user.json +8 -0
  40. data/spec/fixtures/follow_user.json +8 -0
  41. data/spec/fixtures/followed_by.json +1 -0
  42. data/spec/fixtures/follows.json +1 -0
  43. data/spec/fixtures/geography_recent_media.json +1 -0
  44. data/spec/fixtures/liked_media.json +1 -0
  45. data/spec/fixtures/location.json +1 -0
  46. data/spec/fixtures/location_recent_media.json +1 -0
  47. data/spec/fixtures/location_search.json +1 -0
  48. data/spec/fixtures/location_search_fsq.json +1 -0
  49. data/spec/fixtures/media.json +1 -0
  50. data/spec/fixtures/media_comment.json +1 -0
  51. data/spec/fixtures/media_comment_deleted.json +1 -0
  52. data/spec/fixtures/media_comments.json +1 -0
  53. data/spec/fixtures/media_liked.json +1 -0
  54. data/spec/fixtures/media_likes.json +1 -0
  55. data/spec/fixtures/media_popular.json +1 -0
  56. data/spec/fixtures/media_search.json +1 -0
  57. data/spec/fixtures/media_shortcode.json +1 -0
  58. data/spec/fixtures/media_unliked.json +1 -0
  59. data/spec/fixtures/mikeyk.json +1 -0
  60. data/spec/fixtures/oembed.json +14 -0
  61. data/spec/fixtures/recent_media.json +1 -0
  62. data/spec/fixtures/relationship.json +9 -0
  63. data/spec/fixtures/requested_by.json +12 -0
  64. data/spec/fixtures/shayne.json +1 -0
  65. data/spec/fixtures/subscription.json +12 -0
  66. data/spec/fixtures/subscription_deleted.json +1 -0
  67. data/spec/fixtures/subscription_payload.json +14 -0
  68. data/spec/fixtures/subscriptions.json +22 -0
  69. data/spec/fixtures/tag.json +1 -0
  70. data/spec/fixtures/tag_recent_media.json +1 -0
  71. data/spec/fixtures/tag_search.json +1 -0
  72. data/spec/fixtures/unblock_user.json +8 -0
  73. data/spec/fixtures/unfollow_user.json +8 -0
  74. data/spec/fixtures/user_media_feed.json +1 -0
  75. data/spec/fixtures/user_search.json +1 -0
  76. data/spec/instagram/api_spec.rb +285 -0
  77. data/spec/instagram/client/comments_spec.rb +71 -0
  78. data/spec/instagram/client/embedding_spec.rb +36 -0
  79. data/spec/instagram/client/geography_spec.rb +37 -0
  80. data/spec/instagram/client/likes_spec.rb +66 -0
  81. data/spec/instagram/client/locations_spec.rb +127 -0
  82. data/spec/instagram/client/media_spec.rb +99 -0
  83. data/spec/instagram/client/subscriptions_spec.rb +174 -0
  84. data/spec/instagram/client/tags_spec.rb +79 -0
  85. data/spec/instagram/client/users_spec.rb +424 -0
  86. data/spec/instagram/client/utils_spec.rb +32 -0
  87. data/spec/instagram/client_spec.rb +23 -0
  88. data/spec/instagram/request_spec.rb +56 -0
  89. data/spec/instagram_spec.rb +109 -0
  90. data/spec/spec_helper.rb +71 -0
  91. metadata +328 -0
@@ -0,0 +1,79 @@
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 ".tag" do
11
+
12
+ before do
13
+ stub_get("tags/cat.#{format}").
14
+ with(:query => {:access_token => @client.access_token}).
15
+ to_return(:body => fixture("tag.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
16
+ end
17
+
18
+ it "should get the correct resource" do
19
+ @client.tag('cat')
20
+ a_get("tags/cat.#{format}").
21
+ with(:query => {:access_token => @client.access_token}).
22
+ should have_been_made
23
+ end
24
+
25
+ it "should return extended information of a given media item" do
26
+ tag = @client.tag('cat')
27
+ tag.name.should == 'cat'
28
+ end
29
+ end
30
+
31
+ describe ".tag_recent_media" do
32
+
33
+ before do
34
+ stub_get("tags/cat/media/recent.#{format}").
35
+ with(:query => {:access_token => @client.access_token}).
36
+ to_return(:body => fixture("tag_recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
37
+ end
38
+
39
+ it "should get the correct resource" do
40
+ @client.tag_recent_media('cat')
41
+ a_get("tags/cat/media/recent.#{format}").
42
+ with(:query => {:access_token => @client.access_token}).
43
+ should have_been_made
44
+ end
45
+
46
+ it "should return a list of media taken at a given location" do
47
+ media = @client.tag_recent_media('cat')
48
+ media.should be_a Array
49
+ media.first.user.username.should == "amandavan"
50
+ end
51
+
52
+ end
53
+
54
+ describe ".tag_search" do
55
+
56
+ before do
57
+ stub_get("tags/search.#{format}").
58
+ with(:query => {:access_token => @client.access_token}).
59
+ with(:query => {:q => 'cat'}).
60
+ to_return(:body => fixture("tag_search.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
61
+ end
62
+
63
+ it "should get the correct resource" do
64
+ @client.tag_search('cat')
65
+ a_get("tags/search.#{format}").
66
+ with(:query => {:access_token => @client.access_token}).
67
+ with(:query => {:q => 'cat'}).
68
+ should have_been_made
69
+ end
70
+
71
+ it "should return an array of user search results" do
72
+ tags = @client.tag_search('cat')
73
+ tags.should be_a Array
74
+ tags.first.name.should == "cats"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,424 @@
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
+
172
+ context Instagram::Response do
173
+ let(:user_media_feed_response){ @client.user_media_feed }
174
+ subject{ user_media_feed_response }
175
+
176
+ it{ should be_an_instance_of(Array) }
177
+ it{ should be_a_kind_of(Instagram::Response) }
178
+ it{ should respond_to(:pagination) }
179
+ it{ should respond_to(:meta) }
180
+
181
+ context '.pagination' do
182
+ subject{ user_media_feed_response.pagination }
183
+
184
+ it{ should be_an_instance_of(Hashie::Mash) }
185
+ its(:next_max_id){ should == '22063131' }
186
+ end
187
+
188
+ context '.meta' do
189
+ subject{ user_media_feed_response.meta }
190
+
191
+ it{ should be_an_instance_of(Hashie::Mash) }
192
+ its(:code){ should == 200 }
193
+ end
194
+ end
195
+ end
196
+
197
+ describe ".user_liked_media" do
198
+
199
+ before do
200
+ stub_get("users/self/media/liked.#{format}").
201
+ with(:query => {:access_token => @client.access_token}).
202
+ to_return(:body => fixture("liked_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
203
+ end
204
+
205
+ it "should get the correct resource" do
206
+ @client.user_liked_media
207
+ a_get("users/self/media/liked.#{format}").
208
+ with(:query => {:access_token => @client.access_token}).
209
+ should have_been_made
210
+ end
211
+ end
212
+
213
+ describe ".user_recent_media" do
214
+
215
+ context "with user ID passed" do
216
+
217
+ before do
218
+ stub_get("users/4/media/recent.#{format}").
219
+ with(:query => {:access_token => @client.access_token}).
220
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
221
+ end
222
+
223
+ it "should get the correct resource" do
224
+ @client.user_recent_media(4)
225
+ a_get("users/4/media/recent.#{format}").
226
+ with(:query => {:access_token => @client.access_token}).
227
+ should have_been_made
228
+ end
229
+
230
+ it "should return a list of recent media items for the given user" do
231
+ recent_media = @client.user_recent_media(4)
232
+ recent_media.should be_a Array
233
+ recent_media.first.user.username.should == "shayne"
234
+ end
235
+ end
236
+
237
+ context "without user ID passed" do
238
+
239
+ before do
240
+ stub_get("users/self/media/recent.#{format}").
241
+ with(:query => {:access_token => @client.access_token}).
242
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
243
+ end
244
+
245
+ it "should get the correct resource" do
246
+ @client.user_recent_media
247
+ a_get("users/self/media/recent.#{format}").
248
+ with(:query => {:access_token => @client.access_token}).
249
+ should have_been_made
250
+ end
251
+ end
252
+ end
253
+
254
+ describe ".user_requested_by" do
255
+
256
+ before do
257
+ stub_get("users/self/requested-by.#{format}").
258
+ with(:query => {:access_token => @client.access_token}).
259
+ to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
260
+ end
261
+
262
+ it "should get the correct resource" do
263
+ @client.user_requested_by
264
+ a_get("users/self/requested-by.#{format}").
265
+ with(:query => {:access_token => @client.access_token}).
266
+ should have_been_made
267
+ end
268
+
269
+ it "should return a list of users awaiting approval" do
270
+ users = @client.user_requested_by
271
+ users.should be_a Array
272
+ users.first.username.should == "shayne"
273
+ end
274
+ end
275
+
276
+ describe ".user_relationship" do
277
+
278
+ before do
279
+ stub_get("users/4/relationship.#{format}").
280
+ with(:query => {:access_token => @client.access_token}).
281
+ to_return(:body => fixture("relationship.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
282
+ end
283
+
284
+ it "should get the correct resource" do
285
+ @client.user_relationship(4)
286
+ a_get("users/4/relationship.#{format}").
287
+ with(:query => {:access_token => @client.access_token}).
288
+ should have_been_made
289
+ end
290
+
291
+ it "should return a relationship status response" do
292
+ status = @client.user_relationship(4)
293
+ status.incoming_status.should == "requested_by"
294
+ end
295
+ end
296
+
297
+ describe ".follow_user" do
298
+
299
+ before do
300
+ stub_post("users/4/relationship.#{format}").
301
+ with(:body => {:action => "follow", :access_token => @client.access_token}).
302
+ to_return(:body => fixture("follow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
303
+ end
304
+
305
+ it "should get the correct resource" do
306
+ @client.follow_user(4)
307
+ a_post("users/4/relationship.#{format}").
308
+ with(:body => {:action => "follow", :access_token => @client.access_token}).
309
+ should have_been_made
310
+ end
311
+
312
+ it "should return a relationship status response" do
313
+ status = @client.follow_user(4)
314
+ status.outgoing_status.should == "requested"
315
+ end
316
+ end
317
+
318
+ describe ".unfollow_user" do
319
+
320
+ before do
321
+ stub_post("users/4/relationship.#{format}").
322
+ with(:body => {:action => "unfollow", :access_token => @client.access_token}).
323
+ to_return(:body => fixture("unfollow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
324
+ end
325
+
326
+ it "should get the correct resource" do
327
+ @client.unfollow_user(4)
328
+ a_post("users/4/relationship.#{format}").
329
+ with(:body => {:action => "unfollow", :access_token => @client.access_token}).
330
+ should have_been_made
331
+ end
332
+
333
+ it "should return a relationship status response" do
334
+ status = @client.unfollow_user(4)
335
+ status.outgoing_status.should == "none"
336
+ end
337
+ end
338
+
339
+ describe ".block_user" do
340
+
341
+ before do
342
+ stub_post("users/4/relationship.#{format}").
343
+ with(:body => {:action => "block", :access_token => @client.access_token}).
344
+ to_return(:body => fixture("block_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
345
+ end
346
+
347
+ it "should get the correct resource" do
348
+ @client.block_user(4)
349
+ a_post("users/4/relationship.#{format}").
350
+ with(:body => {:action => "block", :access_token => @client.access_token}).
351
+ should have_been_made
352
+ end
353
+
354
+ it "should return a relationship status response" do
355
+ status = @client.block_user(4)
356
+ status.outgoing_status.should == "none"
357
+ end
358
+ end
359
+
360
+ describe ".unblock_user" do
361
+
362
+ before do
363
+ stub_post("users/4/relationship.#{format}").
364
+ with(:body => {:action => "unblock", :access_token => @client.access_token}).
365
+ to_return(:body => fixture("unblock_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
366
+ end
367
+
368
+ it "should get the correct resource" do
369
+ @client.unblock_user(4)
370
+ a_post("users/4/relationship.#{format}").
371
+ with(:body => {:action => "unblock", :access_token => @client.access_token}).
372
+ should have_been_made
373
+ end
374
+
375
+ it "should return a relationship status response" do
376
+ status = @client.unblock_user(4)
377
+ status.outgoing_status.should == "none"
378
+ end
379
+ end
380
+
381
+ describe ".approve_user" do
382
+
383
+ before do
384
+ stub_post("users/4/relationship.#{format}").
385
+ with(:body => {:action => "approve", :access_token => @client.access_token}).
386
+ to_return(:body => fixture("approve_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
387
+ end
388
+
389
+ it "should get the correct resource" do
390
+ @client.approve_user(4)
391
+ a_post("users/4/relationship.#{format}").
392
+ with(:body => {:action => "approve", :access_token => @client.access_token}).
393
+ should have_been_made
394
+ end
395
+
396
+ it "should return a relationship status response" do
397
+ status = @client.approve_user(4)
398
+ status.outgoing_status.should == "follows"
399
+ end
400
+ end
401
+
402
+ describe ".deny_user" do
403
+
404
+ before do
405
+ stub_post("users/4/relationship.#{format}").
406
+ with(:body => {:action => "deny", :access_token => @client.access_token}).
407
+ to_return(:body => fixture("deny_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
408
+ end
409
+
410
+ it "should get the correct resource" do
411
+ @client.deny_user(4)
412
+ a_post("users/4/relationship.#{format}").
413
+ with(:body => {:action => "deny", :access_token => @client.access_token}).
414
+ should have_been_made
415
+ end
416
+
417
+ it "should return a relationship status response" do
418
+ status = @client.deny_user(4)
419
+ status.outgoing_status.should == "none"
420
+ end
421
+ end
422
+ end
423
+ end
424
+ end