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
@@ -1,47 +1,45 @@
1
- require 'openssl'
2
- require 'base64'
1
+ require "openssl"
2
+ require "base64"
3
3
 
4
4
  module Instagram
5
5
  # Defines HTTP request methods
6
6
  module Request
7
7
  # Perform an HTTP GET request
8
- def get(path, options={}, signature=false, raw=false, unformatted=false, no_response_wrapper=no_response_wrapper(), signed=sign_requests)
8
+ def get(path, options = {}, signature = false, raw = false, unformatted = false, no_response_wrapper = no_response_wrapper, signed = sign_requests)
9
9
  request(:get, path, options, signature, raw, unformatted, no_response_wrapper, signed)
10
10
  end
11
11
 
12
12
  # Perform an HTTP POST request
13
- def post(path, options={}, signature=false, raw=false, unformatted=false, no_response_wrapper=no_response_wrapper(), signed=sign_requests)
13
+ def post(path, options = {}, signature = false, raw = false, unformatted = false, no_response_wrapper = no_response_wrapper, signed = sign_requests)
14
14
  request(:post, path, options, signature, raw, unformatted, no_response_wrapper, signed)
15
15
  end
16
16
 
17
17
  # Perform an HTTP PUT request
18
- def put(path, options={}, signature=false, raw=false, unformatted=false, no_response_wrapper=no_response_wrapper(), signed=sign_requests)
18
+ def put(path, options = {}, signature = false, raw = false, unformatted = false, no_response_wrapper = no_response_wrapper, signed = sign_requests)
19
19
  request(:put, path, options, signature, raw, unformatted, no_response_wrapper, signed)
20
20
  end
21
21
 
22
22
  # Perform an HTTP DELETE request
23
- def delete(path, options={}, signature=false, raw=false, unformatted=false, no_response_wrapper=no_response_wrapper(), signed=sign_requests)
23
+ def delete(path, options = {}, signature = false, raw = false, unformatted = false, no_response_wrapper = no_response_wrapper, signed = sign_requests)
24
24
  request(:delete, path, options, signature, raw, unformatted, no_response_wrapper, signed)
25
25
  end
26
26
 
27
27
  private
28
28
 
29
29
  # Perform an HTTP request
30
- def request(method, path, options, signature=false, raw=false, unformatted=false, no_response_wrapper=false, signed=sign_requests)
30
+ def request(method, path, options, signature = false, raw = false, unformatted = false, no_response_wrapper = false, signed = sign_requests)
31
31
  response = connection(raw).send(method) do |request|
32
32
  path = formatted_path(path) unless unformatted
33
-
33
+
34
34
  if signed == true
35
- if client_id != nil
36
- sig_options = options.merge({:client_id => client_id})
37
- end
38
- if access_token != nil
39
- sig_options = options.merge({:access_token => access_token})
35
+ sig_options = options.merge(client_id: client_id) unless client_id.nil?
36
+ unless access_token.nil?
37
+ sig_options = options.merge(access_token: access_token)
40
38
  end
41
- sig = generate_sig("/"+path, sig_options, client_secret)
39
+ sig = generate_sig("/" + path, sig_options, client_secret)
42
40
  options[:sig] = sig
43
41
  end
44
-
42
+
45
43
  case method
46
44
  when :get, :delete
47
45
  request.url(URI.encode(path), options)
@@ -49,34 +47,33 @@ module Instagram
49
47
  request.path = URI.encode(path)
50
48
  request.body = options unless options.empty?
51
49
  end
52
- if signature && client_ips != nil
50
+ if signature && !client_ips.nil?
53
51
  request.headers["X-Insta-Forwarded-For"] = get_insta_fowarded_for(client_ips, client_secret)
54
52
  end
55
53
  end
56
54
  return response if raw
57
55
  return response.body if no_response_wrapper
58
- return Response.create( response.body, {:limit => response.headers['x-ratelimit-limit'].to_i,
59
- :remaining => response.headers['x-ratelimit-remaining'].to_i} )
56
+ Response.create(response.body, limit: response.headers["x-ratelimit-limit"].to_i,
57
+ remaining: response.headers["x-ratelimit-remaining"].to_i)
60
58
  end
61
59
 
62
60
  def formatted_path(path)
63
- [path, format].compact.join('.')
61
+ [path, format].compact.join(".")
64
62
  end
65
63
 
66
64
  def get_insta_fowarded_for(ips, secret)
67
- digest = OpenSSL::Digest.new('sha256')
68
- signature = OpenSSL::HMAC.hexdigest(digest, secret, ips)
69
- return [ips, signature].join('|')
65
+ digest = OpenSSL::Digest.new("sha256")
66
+ signature = OpenSSL::HMAC.hexdigest(digest, secret, ips)
67
+ [ips, signature].join("|")
70
68
  end
71
69
 
72
70
  def generate_sig(endpoint, params, secret)
73
71
  sig = endpoint
74
72
  params.sort.map do |key, val|
75
- sig += '|%s=%s' % [key, val]
73
+ sig += "|%s=%s" % [key, val]
76
74
  end
77
- digest = OpenSSL::Digest::Digest.new('sha256')
78
- return OpenSSL::HMAC.hexdigest(digest, secret, sig)
75
+ digest = OpenSSL::Digest::Digest.new("sha256")
76
+ OpenSSL::HMAC.hexdigest(digest, secret, sig)
79
77
  end
80
-
81
78
  end
82
79
  end
@@ -1,11 +1,15 @@
1
1
  module Instagram
2
2
  module Response
3
- def self.create( response_hash, ratelimit_hash )
3
+ def self.create(response_hash, ratelimit_hash)
4
4
  response_hash = {} unless response_hash
5
- data = response_hash.data.dup rescue response_hash
6
- data.extend( self )
5
+ data = begin
6
+ response_hash.data.dup
7
+ rescue
8
+ response_hash
9
+ end
10
+ data.extend(self)
7
11
  data.instance_exec do
8
- %w{pagination meta}.each do |k|
12
+ %w(pagination meta).each do |k|
9
13
  response_hash.public_send(k).tap do |v|
10
14
  instance_variable_set("@#{k}", v) if v
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Instagram
2
- VERSION = '1.3.0'.freeze unless defined?(::Instagram::VERSION)
2
+ VERSION = '1.3.1'.freeze unless defined?(::Instagram::VERSION)
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Faraday::Response do
4
4
  before do
@@ -11,76 +11,74 @@ describe Faraday::Response do
11
11
  404 => Instagram::NotFound,
12
12
  429 => Instagram::TooManyRequests,
13
13
  500 => Instagram::InternalServerError,
14
- 503 => Instagram::ServiceUnavailable
14
+ 503 => Instagram::ServiceUnavailable,
15
15
  }.each do |status, exception|
16
16
  context "when HTTP status is #{status}" do
17
-
18
17
  before do
19
- stub_get('users/self/feed.json').
20
- to_return(:status => status)
18
+ stub_get("users/self/feed.json")
19
+ .to_return(status: status)
21
20
  end
22
21
 
23
22
  it "should raise #{exception.name} error" do
24
23
  expect do
25
- @client.user_media_feed()
24
+ @client.user_media_feed
26
25
  end.to raise_error(exception)
27
26
  end
28
-
29
27
  end
30
28
  end
31
29
 
32
30
  context "when a 400 is raised" do
33
31
  before do
34
- stub_get('users/self/feed.json').
35
- to_return(:body => '{"meta":{"error_message": "Bad words are bad."}}', :status => 400)
32
+ stub_get("users/self/feed.json")
33
+ .to_return(body: '{"meta":{"error_message": "Bad words are bad."}}', status: 400)
36
34
  end
37
35
 
38
36
  it "should return the body error message" do
39
37
  expect do
40
- @client.user_media_feed()
38
+ @client.user_media_feed
41
39
  end.to raise_error(Instagram::BadRequest, /Bad words are bad\./)
42
40
  end
43
41
  end
44
42
 
45
43
  context "when a 400 is raised with no meta but an error_message" do
46
44
  before do
47
- stub_get('users/self/feed.json').
48
- to_return(:body => '{"error_type": "OAuthException", "error_message": "No matching code found."}', :status => 400)
45
+ stub_get("users/self/feed.json")
46
+ .to_return(body: '{"error_type": "OAuthException", "error_message": "No matching code found."}', status: 400)
49
47
  end
50
48
 
51
49
  it "should return the body error type and message" do
52
50
  expect do
53
- @client.user_media_feed()
51
+ @client.user_media_feed
54
52
  end.to raise_error(Instagram::BadRequest, /OAuthException: No matching code found\./)
55
53
  end
56
54
  end
57
55
 
58
- context 'when a 502 is raised with an HTML response' do
56
+ context "when a 502 is raised with an HTML response" do
59
57
  before do
60
- stub_get('users/self/feed.json').to_return(
61
- :body => '<html><body><h1>502 Bad Gateway</h1> The server returned an invalid or incomplete response. </body></html>',
62
- :status => 502
58
+ stub_get("users/self/feed.json").to_return(
59
+ body: "<html><body><h1>502 Bad Gateway</h1> The server returned an invalid or incomplete response. </body></html>",
60
+ status: 502
63
61
  )
64
62
  end
65
63
 
66
- it 'should raise an Instagram::BadGateway' do
64
+ it "should raise an Instagram::BadGateway" do
67
65
  expect do
68
- @client.user_media_feed()
66
+ @client.user_media_feed
69
67
  end.to raise_error(Instagram::BadGateway)
70
68
  end
71
69
  end
72
70
 
73
- context 'when a 504 is raised with an HTML response' do
71
+ context "when a 504 is raised with an HTML response" do
74
72
  before do
75
- stub_get('users/self/feed.json').to_return(
76
- :body => '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html>',
77
- :status => 504
73
+ stub_get("users/self/feed.json").to_return(
74
+ body: '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx</center> </body> </html>',
75
+ status: 504
78
76
  )
79
77
  end
80
78
 
81
- it 'should raise an Instagram::GatewayTimeout' do
79
+ it "should raise an Instagram::GatewayTimeout" do
82
80
  expect do
83
- @client.user_media_feed()
81
+ @client.user_media_feed
84
82
  end.to raise_error(Instagram::GatewayTimeout)
85
83
  end
86
84
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Instagram::API do
4
4
  before do
@@ -6,7 +6,6 @@ describe Instagram::API do
6
6
  end
7
7
 
8
8
  context "with module configuration" do
9
-
10
9
  before do
11
10
  Instagram.configure do |config|
12
11
  @keys.each do |key|
@@ -27,38 +26,36 @@ describe Instagram::API do
27
26
  end
28
27
 
29
28
  context "with class configuration" do
30
-
31
29
  before do
32
30
  @configuration = {
33
- :access_token => 'AT',
34
- :adapter => :typhoeus,
35
- :client_id => 'CID',
36
- :client_secret => 'CS',
37
- :client_ips => '1.2.3.4',
38
- :connection_options => { :ssl => { :verify => true } },
39
- :redirect_uri => 'http://http://localhost:4567/oauth/callback',
40
- :endpoint => 'http://tumblr.com/',
41
- :format => :xml,
42
- :proxy => 'http://shayne:sekret@proxy.example.com:8080',
43
- :scope => 'comments relationships',
44
- :user_agent => 'Custom User Agent',
45
- :no_response_wrapper => true,
46
- :loud_logger => true,
47
- :sign_requests => false,
31
+ access_token: "AT",
32
+ adapter: :typhoeus,
33
+ client_id: "CID",
34
+ client_secret: "CS",
35
+ client_ips: "1.2.3.4",
36
+ connection_options: { ssl: { verify: true } },
37
+ redirect_uri: "http://http://localhost:4567/oauth/callback",
38
+ endpoint: "http://tumblr.com/",
39
+ format: :xml,
40
+ proxy: "http://shayne:sekret@proxy.example.com:8080",
41
+ scope: "comments relationships",
42
+ user_agent: "Custom User Agent",
43
+ no_response_wrapper: true,
44
+ loud_logger: true,
45
+ sign_requests: false,
48
46
  }
49
47
  end
50
48
 
51
49
  context "during initialization"
52
50
 
53
- it "should override module configuration" do
54
- api = Instagram::API.new(@configuration)
55
- @keys.each do |key|
56
- expect(api.send(key)).to eq(@configuration[key])
57
- end
51
+ it "should override module configuration" do
52
+ api = Instagram::API.new(@configuration)
53
+ @keys.each do |key|
54
+ expect(api.send(key)).to eq(@configuration[key])
58
55
  end
56
+ end
59
57
 
60
58
  context "after initilization" do
61
-
62
59
  let(:api) { Instagram::API.new }
63
60
 
64
61
  before do
@@ -75,7 +72,7 @@ describe Instagram::API do
75
72
 
76
73
  describe "#connection" do
77
74
  it "should use the connection_options" do
78
- expect(Faraday::Connection).to receive(:new).with(include(:ssl => { :verify => true }))
75
+ expect(Faraday::Connection).to receive(:new).with(include(ssl: { verify: true }))
79
76
  api.send(:connection)
80
77
  end
81
78
  end
@@ -83,11 +80,11 @@ describe Instagram::API do
83
80
  end
84
81
  end
85
82
 
86
- describe '#config' do
83
+ describe "#config" do
87
84
  subject { Instagram::API.new }
88
85
 
89
86
  let(:config) do
90
- c = {}; @keys.each {|key| c[key] = key }; c
87
+ c = {}; @keys.each { |key| c[key] = key }; c
91
88
  end
92
89
 
93
90
  it "returns a hash representing the configuration" do
@@ -99,18 +96,17 @@ describe Instagram::API do
99
96
  end
100
97
 
101
98
  describe ".authorize_url" do
102
-
103
99
  it "should generate an authorize URL with necessary params" do
104
- params = { :client_id => "CID", :client_secret => "CS" }
100
+ params = { client_id: "CID", client_secret: "CS" }
105
101
 
106
102
  client = Instagram::Client.new(params)
107
103
 
108
- redirect_uri = 'http://localhost:4567/oauth/callback'
109
- url = client.authorize_url(:redirect_uri => redirect_uri)
104
+ redirect_uri = "http://localhost:4567/oauth/callback"
105
+ url = client.authorize_url(redirect_uri: redirect_uri)
110
106
 
111
107
  options = {
112
- :redirect_uri => redirect_uri,
113
- :response_type => "code"
108
+ redirect_uri: redirect_uri,
109
+ response_type: "code",
114
110
  }
115
111
  params2 = client.send(:authorization_params).merge(options)
116
112
 
@@ -120,140 +116,140 @@ describe Instagram::API do
120
116
  end
121
117
 
122
118
  it "should not include client secret in URL params" do
123
- params = { :client_id => "CID", :client_secret => "CS" }
119
+ params = { client_id: "CID", client_secret: "CS" }
124
120
  client = Instagram::Client.new(params)
125
- redirect_uri = 'http://localhost:4567/oauth/callback'
126
- url = client.authorize_url(:redirect_uri => redirect_uri)
121
+ redirect_uri = "http://localhost:4567/oauth/callback"
122
+ url = client.authorize_url(redirect_uri: redirect_uri)
127
123
  expect(url).not_to include("client_secret")
128
124
  end
129
125
 
130
126
  describe "scope param" do
131
127
  it "should include the scope if there is one set" do
132
- params = { :scope => "comments likes" }
128
+ params = { scope: "comments likes" }
133
129
  client = Instagram::Client.new(params)
134
- redirect_uri = 'http://localhost:4567/oauth/callback'
135
- url = client.authorize_url(:redirect_uri => redirect_uri)
130
+ redirect_uri = "http://localhost:4567/oauth/callback"
131
+ url = client.authorize_url(redirect_uri: redirect_uri)
136
132
  expect(url).to include("scope")
137
133
  end
138
134
 
139
135
  it "should not include the scope if the scope is blank" do
140
- params = { :scope => "" }
136
+ params = { scope: "" }
141
137
  client = Instagram::Client.new(params)
142
- redirect_uri = 'http://localhost:4567/oauth/callback'
143
- url = client.authorize_url(:redirect_uri => redirect_uri)
138
+ redirect_uri = "http://localhost:4567/oauth/callback"
139
+ url = client.authorize_url(redirect_uri: redirect_uri)
144
140
  expect(url).not_to include("scope")
145
141
  end
146
142
  end
147
143
 
148
144
  describe "redirect_uri" do
149
145
  it "should fall back to configuration redirect_uri if not passed as option" do
150
- redirect_uri = 'http://localhost:4567/oauth/callback'
151
- params = { :redirect_uri => redirect_uri }
146
+ redirect_uri = "http://localhost:4567/oauth/callback"
147
+ params = { redirect_uri: redirect_uri }
152
148
  client = Instagram::Client.new(params)
153
- url = client.authorize_url()
154
- expect(url).to match(/redirect_uri=#{URI.escape(redirect_uri, Regexp.union('/',':'))}/)
149
+ url = client.authorize_url
150
+ expect(url).to match(/redirect_uri=#{URI.escape(redirect_uri, Regexp.union('/', ':'))}/)
155
151
  end
156
152
 
157
153
  it "should override configuration redirect_uri if passed as option" do
158
- redirect_uri_config = 'http://localhost:4567/oauth/callback_config'
159
- params = { :redirect_uri => redirect_uri_config }
154
+ redirect_uri_config = "http://localhost:4567/oauth/callback_config"
155
+ params = { redirect_uri: redirect_uri_config }
160
156
  client = Instagram::Client.new(params)
161
- redirect_uri_option = 'http://localhost:4567/oauth/callback_option'
162
- options = { :redirect_uri => redirect_uri_option }
157
+ redirect_uri_option = "http://localhost:4567/oauth/callback_option"
158
+ options = { redirect_uri: redirect_uri_option }
163
159
  url = client.authorize_url(options)
164
- expect(url).to match(/redirect_uri=#{URI.escape(redirect_uri_option, Regexp.union('/',':'))}/)
160
+ expect(url).to match(/redirect_uri=#{URI.escape(redirect_uri_option, Regexp.union('/', ':'))}/)
165
161
  end
166
162
  end
167
163
  end
168
164
 
169
165
  describe ".get_access_token" do
170
-
171
166
  describe "common functionality" do
172
167
  before do
173
- @client = Instagram::Client.new(:client_id => "CID", :client_secret => "CS")
168
+ @client = Instagram::Client.new(client_id: "CID", client_secret: "CS")
174
169
  @url = @client.send(:connection).build_url("/oauth/access_token/").to_s
175
- stub_request(:post, @url).
176
- with(:body => {:client_id => "CID", :client_secret => "CS", :redirect_uri => "http://localhost:4567/oauth/callback", :grant_type => "authorization_code", :code => "C"}).
177
- to_return(:status => 200, :body => fixture("access_token.json"), :headers => {})
170
+ stub_request(:post, @url)
171
+ .with(body: { client_id: "CID", client_secret: "CS", redirect_uri: "http://localhost:4567/oauth/callback", grant_type: "authorization_code", code: "C" })
172
+ .to_return(status: 200, body: fixture("access_token.json"), headers: {})
178
173
  end
179
174
 
180
175
  it "should get the correct resource" do
181
- @client.get_access_token(code="C", :redirect_uri => "http://localhost:4567/oauth/callback")
182
- expect(a_request(:post, @url).
183
- with(:body => {:client_id => "CID", :client_secret => "CS", :redirect_uri => "http://localhost:4567/oauth/callback", :grant_type => "authorization_code", :code => "C"})).
184
- to have_been_made
176
+ @client.get_access_token(code = "C", redirect_uri: "http://localhost:4567/oauth/callback")
177
+ expect(a_request(:post, @url)
178
+ .with(body: { client_id: "CID", client_secret: "CS", redirect_uri: "http://localhost:4567/oauth/callback", grant_type: "authorization_code", code: "C" }))
179
+ .to have_been_made
185
180
  end
186
181
 
187
182
  it "should return a hash with an access_token and user data" do
188
- response = @client.get_access_token(code="C", :redirect_uri => "http://localhost:4567/oauth/callback")
183
+ response = @client.get_access_token(code = "C", redirect_uri: "http://localhost:4567/oauth/callback")
189
184
  expect(response.access_token).to eq("at")
190
185
  expect(response.user.username).to eq("mikeyk")
191
186
  end
192
187
  end
193
188
 
194
189
  describe "redirect_uri param" do
195
-
196
190
  before do
197
191
  @redirect_uri_config = "http://localhost:4567/oauth/callback_config"
198
- @client = Instagram::Client.new(:client_id => "CID", :client_secret => "CS", :redirect_uri => @redirect_uri_config)
192
+ @client = Instagram::Client.new(client_id: "CID", client_secret: "CS", redirect_uri: @redirect_uri_config)
199
193
  @url = @client.send(:connection).build_url("/oauth/access_token/").to_s
200
194
  stub_request(:post, @url)
201
195
  end
202
196
 
203
197
  it "should fall back to configuration redirect_uri if not passed as option" do
204
- @client.get_access_token(code="C")
205
- expect(a_request(:post, @url).
206
- with(:body => hash_including({:redirect_uri => @redirect_uri_config}))).
207
- to have_been_made
198
+ @client.get_access_token(code = "C")
199
+ expect(a_request(:post, @url)
200
+ .with(body: hash_including(redirect_uri: @redirect_uri_config)))
201
+ .to have_been_made
208
202
  end
209
203
 
210
204
  it "should override configuration redirect_uri if passed as option" do
211
205
  redirect_uri_option = "http://localhost:4567/oauth/callback_option"
212
- @client.get_access_token(code="C", :redirect_uri => redirect_uri_option)
213
- expect(a_request(:post, @url).
214
- with(:body => hash_including({:redirect_uri => redirect_uri_option}))).
215
- to have_been_made
206
+ @client.get_access_token(code = "C", redirect_uri: redirect_uri_option)
207
+ expect(a_request(:post, @url)
208
+ .with(body: hash_including(redirect_uri: redirect_uri_option)))
209
+ .to have_been_made
216
210
  end
217
211
  end
218
212
 
219
213
  describe "loud_logger param" do
220
-
221
214
  before do
222
- @client = Instagram::Client.new(:loud_logger => true)
215
+ @client = Instagram::Client.new(loud_logger: true)
223
216
  end
224
217
 
225
218
  context "outputs to STDOUT with faraday logs when enabled" do
226
219
  before do
227
- stub_get('users/self/feed.json').
228
- to_return(:body => fixture("user_media_feed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
220
+ stub_get("users/self/feed.json")
221
+ .to_return(body: fixture("user_media_feed.json"), headers: { content_type: "application/json; charset=utf-8" })
229
222
  end
230
223
 
231
224
  it "should return the body error message" do
232
225
  output = capture_output do
233
- @client.user_media_feed()
226
+ @client.user_media_feed
234
227
  end
235
228
 
236
- expect(output).to include 'INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json'
237
- expect(output).to include 'DEBUG -- : Response Headers:'
229
+ expect(output).to include "INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json"
230
+ expect(output).to include "DEBUG -- : Response Headers:"
238
231
  expect(output).to include "User-Agent : Instagram Ruby Gem #{Instagram::VERSION}"
239
- expect(output).to include 'http://distillery.s3.amazonaws.com/media/2011/01/31/0f8e832c3dc6420bb6ddf0bd09f032f6_6.jpg'
232
+ expect(output).to include "http://distillery.s3.amazonaws.com/media/2011/01/31/0f8e832c3dc6420bb6ddf0bd09f032f6_6.jpg"
240
233
  end
241
234
  end
242
235
 
243
236
  context "shows STDOUT output when errors occur" do
244
-
245
237
  before do
246
- stub_get('users/self/feed.json').
247
- to_return(:body => '{"meta":{"error_message": "Bad words are bad."}}', :status => 400)
238
+ stub_get("users/self/feed.json")
239
+ .to_return(body: '{"meta":{"error_message": "Bad words are bad."}}', status: 400)
248
240
  end
249
241
 
250
242
  it "should return the body error message" do
251
243
  output = capture_output do
252
- @client.user_media_feed() rescue nil
244
+ begin
245
+ @client.user_media_feed
246
+ rescue
247
+ nil
248
+ end
253
249
  end
254
250
 
255
- expect(output).to include 'INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json'
256
- expect(output).to include 'DEBUG -- : Response Headers:'
251
+ expect(output).to include "INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json"
252
+ expect(output).to include "DEBUG -- : Response Headers:"
257
253
  expect(output).to include "User-Agent : Instagram Ruby Gem #{Instagram::VERSION}"
258
254
  expect(output).to include '{"meta":{"error_message": "Bad words are bad."}}'
259
255
  end
@@ -261,23 +257,23 @@ describe Instagram::API do
261
257
 
262
258
  context "will redact API keys if INSTAGRAM_GEM_REDACT=true" do
263
259
  before do
264
- stub_get('users/self/feed.json').
265
- to_return(:body => fixture("user_media_feed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
260
+ stub_get("users/self/feed.json")
261
+ .to_return(body: fixture("user_media_feed.json"), headers: { content_type: "application/json; charset=utf-8" })
266
262
  end
267
263
 
268
264
  it "should redact API keys" do
269
- allow(ENV).to receive(:[]).with('http_proxy').and_return(nil)
270
- allow(ENV).to receive(:[]).with('INSTAGRAM_GEM_REDACT').and_return('true')
265
+ allow(ENV).to receive(:[]).with("http_proxy").and_return(nil)
266
+ allow(ENV).to receive(:[]).with("INSTAGRAM_GEM_REDACT").and_return("true")
271
267
 
272
268
  output = capture_output do
273
- @client.user_media_feed()
269
+ @client.user_media_feed
274
270
  end
275
271
 
276
- expect(output).to include 'INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json'
277
- expect(output).to include 'DEBUG -- : Response Headers:'
272
+ expect(output).to include "INFO -- : Started GET request to: https://api.instagram.com/v1/users/self/feed.json"
273
+ expect(output).to include "DEBUG -- : Response Headers:"
278
274
  expect(output).to include "User-Agent : Instagram Ruby Gem #{Instagram::VERSION}"
279
- expect(output).to include 'http://distillery.s3.amazonaws.com/media/2011/01/31/0f8e832c3dc6420bb6ddf0bd09f032f6_6.jpg'
280
- expect(output).to include 'access_token=[ACCESS-TOKEN]'
275
+ expect(output).to include "http://distillery.s3.amazonaws.com/media/2011/01/31/0f8e832c3dc6420bb6ddf0bd09f032f6_6.jpg"
276
+ expect(output).to include "access_token=[ACCESS-TOKEN]"
281
277
  end
282
278
  end
283
279
  end