extendi-instagram 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -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 +260 -0
  10. data/Rakefile +27 -0
  11. data/instagram.gemspec +50 -0
  12. data/lib/faraday/loud_logger.rb +78 -0
  13. data/lib/faraday/oauth2.rb +45 -0
  14. data/lib/faraday/raise_http_exception.rb +73 -0
  15. data/lib/instagram/api.rb +31 -0
  16. data/lib/instagram/client/comments.rb +62 -0
  17. data/lib/instagram/client/embedding.rb +28 -0
  18. data/lib/instagram/client/geographies.rb +29 -0
  19. data/lib/instagram/client/likes.rb +58 -0
  20. data/lib/instagram/client/locations.rb +75 -0
  21. data/lib/instagram/client/media.rb +82 -0
  22. data/lib/instagram/client/subscriptions.rb +211 -0
  23. data/lib/instagram/client/tags.rb +59 -0
  24. data/lib/instagram/client/users.rb +310 -0
  25. data/lib/instagram/client/utils.rb +28 -0
  26. data/lib/instagram/client.rb +21 -0
  27. data/lib/instagram/configuration.rb +125 -0
  28. data/lib/instagram/connection.rb +31 -0
  29. data/lib/instagram/error.rb +34 -0
  30. data/lib/instagram/oauth.rb +36 -0
  31. data/lib/instagram/request.rb +83 -0
  32. data/lib/instagram/response.rb +22 -0
  33. data/lib/instagram/version.rb +3 -0
  34. data/lib/instagram.rb +27 -0
  35. data/spec/faraday/response_spec.rb +101 -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_facebook.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 +432 -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 +322 -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
+ expect(a_get("tags/cat.#{format}").
21
+ with(:query => {:access_token => @client.access_token})).
22
+ to have_been_made
23
+ end
24
+
25
+ it "should return extended information of a given media item" do
26
+ tag = @client.tag('cat')
27
+ expect(tag.name).to eq('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
+ expect(a_get("tags/cat/media/recent.#{format}").
42
+ with(:query => {:access_token => @client.access_token})).
43
+ to 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
+ expect(media).to be_a Array
49
+ expect(media.first.user.username).to eq("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
+ expect(a_get("tags/search.#{format}").
66
+ with(:query => {:access_token => @client.access_token}).
67
+ with(:query => {:q => 'cat'})).
68
+ to have_been_made
69
+ end
70
+
71
+ it "should return an array of user search results" do
72
+ tags = @client.tag_search('cat')
73
+ expect(tags).to be_a Array
74
+ expect(tags.first.name).to eq("cats")
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,432 @@
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
+ expect(a_get("users/4.#{format}").
23
+ with(:query => {:access_token => @client.access_token})).
24
+ to have_been_made
25
+ end
26
+
27
+ it "should return extended information of a given user" do
28
+ user = @client.user(4)
29
+ expect(user.full_name).to eq("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
+ expect(a_get("users/self.#{format}").
45
+ with(:query => {:access_token => @client.access_token})).
46
+ to 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
+ expect(a_get("users/search.#{format}").
63
+ with(:query => {:access_token => @client.access_token}).
64
+ with(:query => {:q => "Shayne Sweeney"})).
65
+ to 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
+ expect(users).to be_a Array
71
+ expect(users.first.username).to eq("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
+ expect(a_get("users/4/follows.#{format}").
88
+ with(:query => {:access_token => @client.access_token})).
89
+ to 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
+ expect(follows).to be_a Array
95
+ expect(follows.first.username).to eq("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
+ expect(a_get("users/self/follows.#{format}").
110
+ with(:query => {:access_token => @client.access_token})).
111
+ to 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
+ expect(a_get("users/4/followed-by.#{format}").
129
+ with(:query => {:access_token => @client.access_token})).
130
+ to 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
+ expect(followed_by).to be_a Array
136
+ expect(followed_by.first.username).to eq("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
+ expect(a_get("users/self/followed-by.#{format}").
151
+ with(:query => {:access_token => @client.access_token})).
152
+ to 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
+ expect(a_get("users/self/feed.#{format}").
168
+ with(:query => {:access_token => @client.access_token})).
169
+ to 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{ is_expected.to be_an_instance_of(Hashie::Array) }
177
+ it{ is_expected.to be_a_kind_of(Instagram::Response) }
178
+ it{ is_expected.to respond_to(:pagination) }
179
+ it{ is_expected.to respond_to(:meta) }
180
+
181
+ context '.pagination' do
182
+ subject{ user_media_feed_response.pagination }
183
+
184
+ it{ is_expected.to be_an_instance_of(Hashie::Mash) }
185
+
186
+ describe '#next_max_id' do
187
+ subject { super().next_max_id }
188
+ it { is_expected.to eq('22063131') }
189
+ end
190
+ end
191
+
192
+ context '.meta' do
193
+ subject{ user_media_feed_response.meta }
194
+
195
+ it{ is_expected.to be_an_instance_of(Hashie::Mash) }
196
+
197
+ describe '#code' do
198
+ subject { super().code }
199
+ it { is_expected.to eq(200) }
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ describe ".user_liked_media" do
206
+
207
+ before do
208
+ stub_get("users/self/media/liked.#{format}").
209
+ with(:query => {:access_token => @client.access_token}).
210
+ to_return(:body => fixture("liked_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
211
+ end
212
+
213
+ it "should get the correct resource" do
214
+ @client.user_liked_media
215
+ expect(a_get("users/self/media/liked.#{format}").
216
+ with(:query => {:access_token => @client.access_token})).
217
+ to have_been_made
218
+ end
219
+ end
220
+
221
+ describe ".user_recent_media" do
222
+
223
+ context "with user ID passed" do
224
+
225
+ before do
226
+ stub_get("users/4/media/recent.#{format}").
227
+ with(:query => {:access_token => @client.access_token}).
228
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
229
+ end
230
+
231
+ it "should get the correct resource" do
232
+ @client.user_recent_media(4)
233
+ expect(a_get("users/4/media/recent.#{format}").
234
+ with(:query => {:access_token => @client.access_token})).
235
+ to have_been_made
236
+ end
237
+
238
+ it "should return a list of recent media items for the given user" do
239
+ recent_media = @client.user_recent_media(4)
240
+ expect(recent_media).to be_a Array
241
+ expect(recent_media.first.user.username).to eq("shayne")
242
+ end
243
+ end
244
+
245
+ context "without user ID passed" do
246
+
247
+ before do
248
+ stub_get("users/self/media/recent.#{format}").
249
+ with(:query => {:access_token => @client.access_token}).
250
+ to_return(:body => fixture("recent_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
251
+ end
252
+
253
+ it "should get the correct resource" do
254
+ @client.user_recent_media
255
+ expect(a_get("users/self/media/recent.#{format}").
256
+ with(:query => {:access_token => @client.access_token})).
257
+ to have_been_made
258
+ end
259
+ end
260
+ end
261
+
262
+ describe ".user_requested_by" do
263
+
264
+ before do
265
+ stub_get("users/self/requested-by.#{format}").
266
+ with(:query => {:access_token => @client.access_token}).
267
+ to_return(:body => fixture("requested_by.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
268
+ end
269
+
270
+ it "should get the correct resource" do
271
+ @client.user_requested_by
272
+ expect(a_get("users/self/requested-by.#{format}").
273
+ with(:query => {:access_token => @client.access_token})).
274
+ to have_been_made
275
+ end
276
+
277
+ it "should return a list of users awaiting approval" do
278
+ users = @client.user_requested_by
279
+ expect(users).to be_a Array
280
+ expect(users.first.username).to eq("shayne")
281
+ end
282
+ end
283
+
284
+ describe ".user_relationship" do
285
+
286
+ before do
287
+ stub_get("users/4/relationship.#{format}").
288
+ with(:query => {:access_token => @client.access_token}).
289
+ to_return(:body => fixture("relationship.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
290
+ end
291
+
292
+ it "should get the correct resource" do
293
+ @client.user_relationship(4)
294
+ expect(a_get("users/4/relationship.#{format}").
295
+ with(:query => {:access_token => @client.access_token})).
296
+ to have_been_made
297
+ end
298
+
299
+ it "should return a relationship status response" do
300
+ status = @client.user_relationship(4)
301
+ expect(status.incoming_status).to eq("requested_by")
302
+ end
303
+ end
304
+
305
+ describe ".follow_user" do
306
+
307
+ before do
308
+ stub_post("users/4/relationship.#{format}").
309
+ with(:body => {:action => "follow", :access_token => @client.access_token}).
310
+ to_return(:body => fixture("follow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
311
+ end
312
+
313
+ it "should get the correct resource" do
314
+ @client.follow_user(4)
315
+ expect(a_post("users/4/relationship.#{format}").
316
+ with(:body => {:action => "follow", :access_token => @client.access_token})).
317
+ to have_been_made
318
+ end
319
+
320
+ it "should return a relationship status response" do
321
+ status = @client.follow_user(4)
322
+ expect(status.outgoing_status).to eq("requested")
323
+ end
324
+ end
325
+
326
+ describe ".unfollow_user" do
327
+
328
+ before do
329
+ stub_post("users/4/relationship.#{format}").
330
+ with(:body => {:action => "unfollow", :access_token => @client.access_token}).
331
+ to_return(:body => fixture("unfollow_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
332
+ end
333
+
334
+ it "should get the correct resource" do
335
+ @client.unfollow_user(4)
336
+ expect(a_post("users/4/relationship.#{format}").
337
+ with(:body => {:action => "unfollow", :access_token => @client.access_token})).
338
+ to have_been_made
339
+ end
340
+
341
+ it "should return a relationship status response" do
342
+ status = @client.unfollow_user(4)
343
+ expect(status.outgoing_status).to eq("none")
344
+ end
345
+ end
346
+
347
+ describe ".block_user" do
348
+
349
+ before do
350
+ stub_post("users/4/relationship.#{format}").
351
+ with(:body => {:action => "block", :access_token => @client.access_token}).
352
+ to_return(:body => fixture("block_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
353
+ end
354
+
355
+ it "should get the correct resource" do
356
+ @client.block_user(4)
357
+ expect(a_post("users/4/relationship.#{format}").
358
+ with(:body => {:action => "block", :access_token => @client.access_token})).
359
+ to have_been_made
360
+ end
361
+
362
+ it "should return a relationship status response" do
363
+ status = @client.block_user(4)
364
+ expect(status.outgoing_status).to eq("none")
365
+ end
366
+ end
367
+
368
+ describe ".unblock_user" do
369
+
370
+ before do
371
+ stub_post("users/4/relationship.#{format}").
372
+ with(:body => {:action => "unblock", :access_token => @client.access_token}).
373
+ to_return(:body => fixture("unblock_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
374
+ end
375
+
376
+ it "should get the correct resource" do
377
+ @client.unblock_user(4)
378
+ expect(a_post("users/4/relationship.#{format}").
379
+ with(:body => {:action => "unblock", :access_token => @client.access_token})).
380
+ to have_been_made
381
+ end
382
+
383
+ it "should return a relationship status response" do
384
+ status = @client.unblock_user(4)
385
+ expect(status.outgoing_status).to eq("none")
386
+ end
387
+ end
388
+
389
+ describe ".approve_user" do
390
+
391
+ before do
392
+ stub_post("users/4/relationship.#{format}").
393
+ with(:body => {:action => "approve", :access_token => @client.access_token}).
394
+ to_return(:body => fixture("approve_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
395
+ end
396
+
397
+ it "should get the correct resource" do
398
+ @client.approve_user(4)
399
+ expect(a_post("users/4/relationship.#{format}").
400
+ with(:body => {:action => "approve", :access_token => @client.access_token})).
401
+ to have_been_made
402
+ end
403
+
404
+ it "should return a relationship status response" do
405
+ status = @client.approve_user(4)
406
+ expect(status.outgoing_status).to eq("follows")
407
+ end
408
+ end
409
+
410
+ describe ".deny_user" do
411
+
412
+ before do
413
+ stub_post("users/4/relationship.#{format}").
414
+ with(:body => {:action => "deny", :access_token => @client.access_token}).
415
+ to_return(:body => fixture("deny_user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
416
+ end
417
+
418
+ it "should get the correct resource" do
419
+ @client.deny_user(4)
420
+ expect(a_post("users/4/relationship.#{format}").
421
+ with(:body => {:action => "deny", :access_token => @client.access_token})).
422
+ to have_been_made
423
+ end
424
+
425
+ it "should return a relationship status response" do
426
+ status = @client.deny_user(4)
427
+ expect(status.outgoing_status).to eq("none")
428
+ end
429
+ end
430
+ end
431
+ end
432
+ end