instagram-continued 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -0
  3. data/.travis.yml +1 -0
  4. data/README.md +1 -1
  5. data/Rakefile +12 -11
  6. data/instagram-continued.gemspec +6 -5
  7. data/lib/faraday/loud_logger.rb +47 -48
  8. data/lib/faraday/oauth2.rb +16 -18
  9. data/lib/faraday/raise_http_exception.rb +9 -9
  10. data/lib/instagram.rb +8 -8
  11. data/lib/instagram/api.rb +4 -4
  12. data/lib/instagram/client.rb +1 -1
  13. data/lib/instagram/client/comments.rb +5 -5
  14. data/lib/instagram/client/embedding.rb +9 -9
  15. data/lib/instagram/client/likes.rb +5 -5
  16. data/lib/instagram/client/locations.rb +4 -4
  17. data/lib/instagram/client/media.rb +3 -3
  18. data/lib/instagram/client/subscriptions.rb +27 -27
  19. data/lib/instagram/client/tags.rb +3 -3
  20. data/lib/instagram/client/users.rb +19 -19
  21. data/lib/instagram/client/utils.rb +5 -5
  22. data/lib/instagram/configuration.rb +7 -6
  23. data/lib/instagram/connection.rb +7 -7
  24. data/lib/instagram/oauth.rb +8 -8
  25. data/lib/instagram/request.rb +23 -26
  26. data/lib/instagram/response.rb +8 -4
  27. data/lib/instagram/version.rb +1 -1
  28. data/spec/faraday/response_spec.rb +23 -25
  29. data/spec/instagram/api_spec.rb +90 -94
  30. data/spec/instagram/client/comments_spec.rb +21 -25
  31. data/spec/instagram/client/embedding_spec.rb +8 -8
  32. data/spec/instagram/client/geography_spec.rb +10 -13
  33. data/spec/instagram/client/likes_spec.rb +21 -25
  34. data/spec/instagram/client/locations_spec.rb +42 -48
  35. data/spec/instagram/client/media_spec.rb +33 -37
  36. data/spec/instagram/client/subscriptions_spec.rb +34 -46
  37. data/spec/instagram/client/tags_spec.rb +29 -33
  38. data/spec/instagram/client/users_spec.rb +155 -180
  39. data/spec/instagram/client/utils_spec.rb +8 -9
  40. data/spec/instagram/client_spec.rb +9 -9
  41. data/spec/instagram/request_spec.rb +27 -27
  42. data/spec/instagram_spec.rb +20 -24
  43. data/spec/spec_helper.rb +10 -10
  44. metadata +24 -9
@@ -15,7 +15,7 @@ module Instagram
15
15
  # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
16
16
  # @rate_limited true
17
17
  # @see http://instagram.com/developer/endpoints/likes/#get_media_likes
18
- def media_likes(id, *args)
18
+ def media_likes(id, *_args)
19
19
  response = get("media/#{id}/likes")
20
20
  response
21
21
  end
@@ -33,8 +33,8 @@ module Instagram
33
33
  # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
34
34
  # @rate_limited true
35
35
  # @see http://instagram.com/developer/endpoints/likes/#post_likes
36
- def like_media(id, options={})
37
- response = post("media/#{id}/likes", options, signature=true)
36
+ def like_media(id, options = {})
37
+ response = post("media/#{id}/likes", options, signature = true)
38
38
  response
39
39
  end
40
40
 
@@ -49,8 +49,8 @@ module Instagram
49
49
  # @authenticated true
50
50
  # @rate_limited true
51
51
  # @see http://instagram.com/developer/endpoints/likes/#delete_likes
52
- def unlike_media(id, options={})
53
- response = delete("media/#{id}/likes", options, signature=true)
52
+ def unlike_media(id, options = {})
53
+ response = delete("media/#{id}/likes", options, signature = true)
54
54
  response
55
55
  end
56
56
  end
@@ -13,7 +13,7 @@ module Instagram
13
13
  # @authenticated false
14
14
  # @rate_limited true
15
15
  # @see http://instagram.com/developer/endpoints/locations/#get_locations
16
- def location(id, *args)
16
+ def location(id, *_args)
17
17
  response = get("locations/#{id}")
18
18
  response
19
19
  end
@@ -60,13 +60,13 @@ module Instagram
60
60
  case args.size
61
61
  when 1
62
62
  facebook_places_id = args.first
63
- response = get('locations/search', options.merge(:facebook_places_id => facebook_places_id))
63
+ response = get("locations/search", options.merge(facebook_places_id: facebook_places_id))
64
64
  when 2
65
65
  lat, lng = args
66
- response = get('locations/search', options.merge(:lat => lat, :lng => lng))
66
+ response = get("locations/search", options.merge(lat: lat, lng: lng))
67
67
  when 3
68
68
  lat, lng, distance = args
69
- response = get('locations/search', options.merge(:lat => lat, :lng => lng, :distance => distance))
69
+ response = get("locations/search", options.merge(lat: lat, lng: lng, distance: distance))
70
70
  end
71
71
  response
72
72
  end
@@ -16,7 +16,7 @@ module Instagram
16
16
  # @rate_limited true
17
17
  # @see http://instagram.com/developer/endpoints/media/#get_media
18
18
  def media_item(*args)
19
- id = args.first || 'self'
19
+ id = args.first || "self"
20
20
  response = get("media/#{id}")
21
21
  response
22
22
  end
@@ -73,8 +73,8 @@ module Instagram
73
73
  # @format :json
74
74
  # @authenticated false
75
75
  # @rate_limited true
76
- def media_search(lat, lng, options={})
77
- response = get('media/search', options.merge(:lat => lat, :lng => lng))
76
+ def media_search(lat, lng, options = {})
77
+ response = get("media/search", options.merge(lat: lat, lng: lng))
78
78
  response
79
79
  end
80
80
  end
@@ -1,5 +1,5 @@
1
- require 'openssl'
2
- require 'multi_json'
1
+ require "openssl"
2
+ require "multi_json"
3
3
 
4
4
  module Instagram
5
5
  class Client
@@ -17,8 +17,8 @@ module Instagram
17
17
  # Requires client_secret to be set on the client or passed in options
18
18
  # @rate_limited true
19
19
  # @see https://api.instagram.com/developer/realtime/
20
- def subscriptions(options={})
21
- response = get("subscriptions", options.merge(:client_secret => client_secret))
20
+ def subscriptions(options = {})
21
+ response = get("subscriptions", options.merge(client_secret: client_secret))
22
22
  response
23
23
  end
24
24
 
@@ -58,12 +58,12 @@ module Instagram
58
58
  object = args.shift
59
59
  callback_url = args.shift
60
60
  aspect = args.shift
61
- options.tap {|o|
61
+ options.tap do |o|
62
62
  o[:object] = object unless object.nil?
63
63
  o[:callback_url] = callback_url unless callback_url.nil?
64
64
  o[:aspect] = aspect || o[:aspect] || "media"
65
- }
66
- response = post("subscriptions", options.merge(:client_secret => client_secret), signature=true)
65
+ end
66
+ response = post("subscriptions", options.merge(client_secret: client_secret), signature = true)
67
67
  response
68
68
  end
69
69
 
@@ -91,8 +91,8 @@ module Instagram
91
91
  def delete_subscription(*args)
92
92
  options = args.last.is_a?(Hash) ? args.pop : {}
93
93
  subscription_id = args.first
94
- options.merge!(:id => subscription_id) if subscription_id
95
- response = delete("subscriptions", options.merge(:client_secret => client_secret), signature=true)
94
+ options[:id] = subscription_id if subscription_id
95
+ response = delete("subscriptions", options.merge(client_secret: client_secret), signature = true)
96
96
  response
97
97
  end
98
98
 
@@ -111,14 +111,14 @@ module Instagram
111
111
  # @return the challenge string to be sent back to Instagram, or false if the request is invalid.
112
112
  def meet_challenge(params, verify_token = nil, &verification_block)
113
113
  if params["hub.mode"] == "subscribe" &&
114
- # you can make sure this is legitimate through two ways
115
- # if your store the token across the calls, you can pass in the token value
116
- # and we'll make sure it matches
117
- ((verify_token && params["hub.verify_token"] == verify_token) ||
118
- # alternately, if you sent a specially-constructed value (such as a hash of various secret values)
119
- # you can pass in a block, which we'll call with the verify_token sent by Instagram
120
- # if it's legit, return anything that evaluates to true; otherwise, return nil or false
121
- (verification_block && yield(params["hub.verify_token"])))
114
+ # you can make sure this is legitimate through two ways
115
+ # if your store the token across the calls, you can pass in the token value
116
+ # and we'll make sure it matches
117
+ ((verify_token && params["hub.verify_token"] == verify_token) ||
118
+ # alternately, if you sent a specially-constructed value (such as a hash of various secret values)
119
+ # you can pass in a block, which we'll call with the verify_token sent by Instagram
120
+ # if it's legit, return anything that evaluates to true; otherwise, return nil or false
121
+ (verification_block && yield(params["hub.verify_token"])))
122
122
  params["hub.challenge"]
123
123
  else
124
124
  false
@@ -143,8 +143,8 @@ module Instagram
143
143
  raise ArgumentError, "client_secret must be set during configure"
144
144
  end
145
145
 
146
- if request_signature = headers['X-Hub-Signature'] || headers['HTTP_X_HUB_SIGNATURE']
147
- calculated_signature = OpenSSL::HMAC.hexdigest('sha1', client_secret, body)
146
+ if request_signature = headers["X-Hub-Signature"] || headers["HTTP_X_HUB_SIGNATURE"]
147
+ calculated_signature = OpenSSL::HMAC.hexdigest("sha1", client_secret, body)
148
148
  calculated_signature == request_signature
149
149
  end
150
150
  end
@@ -174,14 +174,14 @@ module Instagram
174
174
  # Requires client_secret to be set on the client or passed in options
175
175
  # @rate_limited true
176
176
  # @see https://api.instagram.com/developer/realtime/
177
- def process_subscription(json, options={}, &block)
177
+ def process_subscription(json, options = {})
178
178
  raise ArgumentError, "callbacks block expected" unless block_given?
179
179
 
180
- if options.has_key?(:signature)
181
- if !client_secret
180
+ if options.key?(:signature)
181
+ unless client_secret
182
182
  raise ArgumentError, "client_secret must be set during configure"
183
183
  end
184
- digest = OpenSSL::Digest.new('sha1')
184
+ digest = OpenSSL::Digest.new("sha1")
185
185
  verify_signature = OpenSSL::HMAC.hexdigest(digest, client_secret, json)
186
186
 
187
187
  if options[:signature] != verify_signature
@@ -190,15 +190,15 @@ module Instagram
190
190
  end
191
191
 
192
192
  payload = MultiJson.decode(json)
193
- @changes = Hash.new { |h,k| h[k] = [] }
193
+ @changes = Hash.new { |h, k| h[k] = [] }
194
194
  for change in payload
195
- @changes[change['object']] << change
195
+ @changes[change["object"]] << change
196
196
  end
197
- block.call(self)
197
+ yield(self)
198
198
  end
199
199
 
200
200
  [:user, :tag, :location, :geography].each do |object|
201
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ +1
201
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
202
202
  def on_#{object}_changed(&block)
203
203
  for change in @changes['#{object}']
204
204
  yield change.delete('object_id'), change
@@ -13,7 +13,7 @@ module Instagram
13
13
  # @authenticated false
14
14
  # @rate_limited true
15
15
  # @see http://instagram.com/developer/endpoints/tags/#get_tags
16
- def tag(tag, *args)
16
+ def tag(tag, *_args)
17
17
  response = get("tags/#{tag}")
18
18
  response
19
19
  end
@@ -50,8 +50,8 @@ module Instagram
50
50
  # @see http://instagram.com/developer/endpoints/tags/#get_tags_search
51
51
  # @example Return tags that start with "cat"
52
52
  # Instagram.tag_search("cat")
53
- def tag_search(query, options={})
54
- response = get('tags/search', options.merge(:q => query))
53
+ def tag_search(query, options = {})
54
+ response = get("tags/search", options.merge(q: query))
55
55
  response
56
56
  end
57
57
  end
@@ -17,7 +17,7 @@ module Instagram
17
17
  # @see http://instagram.com/developer/endpoints/users/#get_users
18
18
  def user(*args)
19
19
  options = args.last.is_a?(Hash) ? args.pop : {}
20
- id = args.first || 'self'
20
+ id = args.first || "self"
21
21
  response = get("users/#{id}", options)
22
22
  response
23
23
  end
@@ -34,8 +34,8 @@ module Instagram
34
34
  # @see http://instagram.com/developer/endpoints/users/#get_users_search
35
35
  # @example Return users that match "Shayne Sweeney"
36
36
  # Instagram.user_search("Shayne Sweeney")
37
- def user_search(query, options={})
38
- response = get('users/search', options.merge(:q => query))
37
+ def user_search(query, options = {})
38
+ response = get("users/search", options.merge(q: query))
39
39
  response
40
40
  end
41
41
 
@@ -111,7 +111,7 @@ module Instagram
111
111
  # @format :json
112
112
  # @authenticated true
113
113
  # @rate_limited true
114
- def user_requested_by()
114
+ def user_requested_by
115
115
  response = get("users/self/requested-by")
116
116
  response
117
117
  end
@@ -132,7 +132,7 @@ module Instagram
132
132
  # @see http://instagram.com/developer/endpoints/users/#get_users_feed
133
133
  def user_media_feed(*args)
134
134
  options = args.first.is_a?(Hash) ? args.pop : {}
135
- response = get('users/self/feed', options)
135
+ response = get("users/self/feed", options)
136
136
  response
137
137
  end
138
138
 
@@ -177,7 +177,7 @@ module Instagram
177
177
  # @format :json
178
178
  # @authenticated true
179
179
  # @rate_limited true
180
- def user_liked_media(options={})
180
+ def user_liked_media(options = {})
181
181
  response = get("users/self/media/liked", options)
182
182
  response
183
183
  end
@@ -194,7 +194,7 @@ module Instagram
194
194
  # @format :json
195
195
  # @authenticated true
196
196
  # @rate_limited true
197
- def user_relationship(id, options={})
197
+ def user_relationship(id, options = {})
198
198
  response = get("users/#{id}/relationship", options)
199
199
  response
200
200
  end
@@ -211,9 +211,9 @@ module Instagram
211
211
  # @format :json
212
212
  # @authenticated true
213
213
  # @rate_limited true
214
- def follow_user(id, options={})
214
+ def follow_user(id, options = {})
215
215
  options["action"] = "follow"
216
- response = post("users/#{id}/relationship", options, signature=true)
216
+ response = post("users/#{id}/relationship", options, signature = true)
217
217
  response
218
218
  end
219
219
 
@@ -229,9 +229,9 @@ module Instagram
229
229
  # @format :json
230
230
  # @authenticated true
231
231
  # @rate_limited true
232
- def unfollow_user(id, options={})
232
+ def unfollow_user(id, options = {})
233
233
  options["action"] = "unfollow"
234
- response = post("users/#{id}/relationship", options, signature=true)
234
+ response = post("users/#{id}/relationship", options, signature = true)
235
235
  response
236
236
  end
237
237
 
@@ -247,9 +247,9 @@ module Instagram
247
247
  # @format :json
248
248
  # @authenticated true
249
249
  # @rate_limited true
250
- def block_user(id, options={})
250
+ def block_user(id, options = {})
251
251
  options["action"] = "block"
252
- response = post("users/#{id}/relationship", options, signature=true)
252
+ response = post("users/#{id}/relationship", options, signature = true)
253
253
  response
254
254
  end
255
255
 
@@ -265,9 +265,9 @@ module Instagram
265
265
  # @format :json
266
266
  # @authenticated true
267
267
  # @rate_limited true
268
- def unblock_user(id, options={})
268
+ def unblock_user(id, options = {})
269
269
  options["action"] = "unblock"
270
- response = post("users/#{id}/relationship", options, signature=true)
270
+ response = post("users/#{id}/relationship", options, signature = true)
271
271
  response
272
272
  end
273
273
 
@@ -283,9 +283,9 @@ module Instagram
283
283
  # @format :json
284
284
  # @authenticated true
285
285
  # @rate_limited true
286
- def approve_user(id, options={})
286
+ def approve_user(id, options = {})
287
287
  options["action"] = "approve"
288
- response = post("users/#{id}/relationship", options, signature=true)
288
+ response = post("users/#{id}/relationship", options, signature = true)
289
289
  response
290
290
  end
291
291
 
@@ -301,9 +301,9 @@ module Instagram
301
301
  # @format :json
302
302
  # @authenticated true
303
303
  # @rate_limited true
304
- def deny_user(id, options={})
304
+ def deny_user(id, options = {})
305
305
  options["action"] = "deny"
306
- response = post("users/#{id}/relationship", options, signature=true)
306
+ response = post("users/#{id}/relationship", options, signature = true)
307
307
  response
308
308
  end
309
309
  end
@@ -2,26 +2,26 @@ module Instagram
2
2
  class Client
3
3
  # @private
4
4
  module Utils
5
- # Returns the raw full response including all headers. Can be used to access the values for 'X-Ratelimit-Limit' and 'X-Ratelimit-Remaining'
5
+ # Returns the raw full response including all headers. Can be used to access the values for 'X-Ratelimit-Limit' and 'X-Ratelimit-Remaining'
6
6
  # ==== Examples
7
- #
7
+ #
8
8
  # client = Instagram.client(:access_token => session[:access_token])
9
9
  # response = client.utils_raw_response
10
10
  # remaining = response.headers[:x_ratelimit_remaining]
11
11
  # limit = response.headers[:x_ratelimit_limit]
12
12
  #
13
13
  def utils_raw_response
14
- response = get('users/self/feed',nil, false, true)
14
+ response = get("users/self/feed", nil, false, true)
15
15
  response
16
16
  end
17
-
17
+
18
18
  private
19
19
 
20
20
  # Returns the configured user name or the user name of the authenticated user
21
21
  #
22
22
  # @return [String]
23
23
  def get_username
24
- @user_name ||= self.user.username
24
+ @user_name ||= user.username
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
- require 'faraday'
2
- require File.expand_path('../version', __FILE__)
1
+ require "faraday"
2
+ require File.expand_path("../version", __FILE__)
3
3
 
4
4
  module Instagram
5
5
  # Defines constants and methods related to configuration
@@ -41,12 +41,12 @@ module Instagram
41
41
  DEFAULT_CLIENT_IPS = nil
42
42
 
43
43
  # By default, don't set any connection options
44
- DEFAULT_CONNECTION_OPTIONS = {}
44
+ DEFAULT_CONNECTION_OPTIONS = {}.freeze
45
45
 
46
46
  # The endpoint that will be used to connect if none is set
47
47
  #
48
48
  # @note There is no reason to use any other endpoint at this time
49
- DEFAULT_ENDPOINT = 'https://api.instagram.com/v1/'.freeze
49
+ DEFAULT_ENDPOINT = "https://api.instagram.com/v1/".freeze
50
50
 
51
51
  # The response format appended to the path and sent in the 'Accept' header if none is set
52
52
  #
@@ -72,7 +72,8 @@ module Instagram
72
72
  #
73
73
  # @note Not all methods support the XML format.
74
74
  VALID_FORMATS = [
75
- :json].freeze
75
+ :json,
76
+ ].freeze
76
77
 
77
78
  # By default, don't turn on loud logging
78
79
  DEFAULT_LOUD_LOGGER = nil
@@ -114,7 +115,7 @@ module Instagram
114
115
  self.format = DEFAULT_FORMAT
115
116
  self.proxy = DEFAULT_PROXY
116
117
  self.user_agent = DEFAULT_USER_AGENT
117
- self.no_response_wrapper= DEFAULT_NO_RESPONSE_WRAPPER
118
+ self.no_response_wrapper = DEFAULT_NO_RESPONSE_WRAPPER
118
119
  self.loud_logger = DEFAULT_LOUD_LOGGER
119
120
  self.sign_requests = DEFAULT_SIGN_REQUESTS
120
121
  end
@@ -1,16 +1,16 @@
1
- require 'faraday_middleware'
2
- Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
1
+ require "faraday_middleware"
2
+ Dir[File.expand_path("../../faraday/*.rb", __FILE__)].each { |f| require f }
3
3
 
4
4
  module Instagram
5
5
  # @private
6
6
  module Connection
7
7
  private
8
8
 
9
- def connection(raw=false)
9
+ def connection(raw = false)
10
10
  options = {
11
- :headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
12
- :proxy => proxy,
13
- :url => endpoint,
11
+ headers: { "Accept" => "application/#{format}; charset=utf-8", "User-Agent" => user_agent },
12
+ proxy: proxy,
13
+ url: endpoint,
14
14
  }.merge(connection_options)
15
15
 
16
16
  Faraday::Connection.new(options) do |connection|
@@ -19,7 +19,7 @@ module Instagram
19
19
  connection.use FaradayMiddleware::Mashify unless raw
20
20
  unless raw
21
21
  case format.to_s.downcase
22
- when 'json' then connection.use Faraday::Response::ParseJson
22
+ when "json" then connection.use Faraday::Response::ParseJson
23
23
  end
24
24
  end
25
25
  connection.use FaradayMiddleware::RaiseHttpException
@@ -2,34 +2,34 @@ module Instagram
2
2
  # Defines HTTP request methods
3
3
  module OAuth
4
4
  # Return URL for OAuth authorization
5
- def authorize_url(options={})
5
+ def authorize_url(options = {})
6
6
  options[:response_type] ||= "code"
7
7
  options[:scope] ||= scope if !scope.nil? && !scope.empty?
8
- options[:redirect_uri] ||= self.redirect_uri
8
+ options[:redirect_uri] ||= redirect_uri
9
9
  params = authorization_params.merge(options)
10
10
  connection.build_url("/oauth/authorize/", params).to_s
11
11
  end
12
12
 
13
13
  # Return an access token from authorization
14
- def get_access_token(code, options={})
14
+ def get_access_token(code, options = {})
15
15
  options[:grant_type] ||= "authorization_code"
16
- options[:redirect_uri] ||= self.redirect_uri
16
+ options[:redirect_uri] ||= redirect_uri
17
17
  params = access_token_params.merge(options)
18
- post("/oauth/access_token/", params.merge(:code => code), signature=false, raw=false, unformatted=true, no_response_wrapper=true)
18
+ post("/oauth/access_token/", params.merge(code: code), signature = false, raw = false, unformatted = true, no_response_wrapper = true)
19
19
  end
20
20
 
21
21
  private
22
22
 
23
23
  def authorization_params
24
24
  {
25
- :client_id => client_id
25
+ client_id: client_id,
26
26
  }
27
27
  end
28
28
 
29
29
  def access_token_params
30
30
  {
31
- :client_id => client_id,
32
- :client_secret => client_secret
31
+ client_id: client_id,
32
+ client_secret: client_secret,
33
33
  }
34
34
  end
35
35
  end