faraday 0.9.0.rc2 → 0.9.0.rc3

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.
data/lib/faraday.rb CHANGED
@@ -14,7 +14,7 @@ require 'forwardable'
14
14
  # conn.get '/'
15
15
  #
16
16
  module Faraday
17
- VERSION = "0.9.0.rc2"
17
+ VERSION = "0.9.0.rc3"
18
18
 
19
19
  class << self
20
20
  # Public: Gets or sets the root path that Faraday is being loaded from.
@@ -144,10 +144,11 @@ module Faraday
144
144
  def call(env)
145
145
  super
146
146
  normalized_path = Faraday::Utils.normalize_path(env[:url])
147
+ params_encoder = env.request.params_encoder || Faraday::Utils.default_params_encoder
147
148
 
148
149
  if stub = stubs.match(env[:method], normalized_path, env.request_headers, env[:body])
149
150
  env[:params] = (query = env[:url].query) ?
150
- Faraday::Utils.parse_nested_query(query) :
151
+ params_encoder.decode(query) :
151
152
  {}
152
153
  status, headers, body = stub.block.call(env)
153
154
  save_response(env, status, body, headers)
@@ -186,8 +186,7 @@ module Faraday
186
186
  #
187
187
  # Returns nothing.
188
188
  def basic_auth(login, pass)
189
- headers[Faraday::Request::Authorization::KEY] =
190
- Faraday::Request::BasicAuthentication.header(login, pass)
189
+ set_authorization_header(:basic_auth, login, pass)
191
190
  end
192
191
 
193
192
  # Public: Sets up the Authorization header with the given token.
@@ -204,8 +203,7 @@ module Faraday
204
203
  #
205
204
  # Returns nothing.
206
205
  def token_auth(token, options = nil)
207
- headers[Faraday::Request::Authorization::KEY] =
208
- Faraday::Request::TokenAuthentication.header(token, options)
206
+ set_authorization_header(:token_auth, token, options)
209
207
  end
210
208
 
211
209
  # Public: Sets up a custom Authorization header.
@@ -227,8 +225,7 @@ module Faraday
227
225
  #
228
226
  # Returns nothing.
229
227
  def authorization(type, token)
230
- headers[Faraday::Request::Authorization::KEY] =
231
- Faraday::Request::Authorization.header(type, token)
228
+ set_authorization_header(:authorization, type, token)
232
229
  end
233
230
 
234
231
  # Internal: Traverse the middleware stack in search of a
@@ -395,6 +392,12 @@ module Faraday
395
392
  yield Utils.unescape(uri.user), Utils.unescape(uri.password)
396
393
  end
397
394
  end
395
+
396
+ def set_authorization_header(header_type, *args)
397
+ header = Faraday::Request.lookup_middleware(header_type).
398
+ header(*args)
399
+ headers[Faraday::Request::Authorization::KEY] = header
400
+ end
398
401
  end
399
402
  end
400
403
 
@@ -69,6 +69,35 @@ module Adapters
69
69
  assert_equal 'a', @conn.get('http://foo.com/hello?a=1').body
70
70
  end
71
71
 
72
+ def test_parses_params_with_default_encoder
73
+ @stubs.get '/hello' do |env|
74
+ assert_equal '1', env[:params]['a']['b']
75
+ [200, {}, 'a']
76
+ end
77
+
78
+ assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
79
+ end
80
+
81
+ def test_parses_params_with_nested_encoder
82
+ @stubs.get '/hello' do |env|
83
+ assert_equal '1', env[:params]['a']['b']
84
+ [200, {}, 'a']
85
+ end
86
+
87
+ @conn.options.params_encoder = Faraday::NestedParamsEncoder
88
+ assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
89
+ end
90
+
91
+ def test_parses_params_with_flat_encoder
92
+ @stubs.get '/hello' do |env|
93
+ assert_equal '1', env[:params]['a[b]']
94
+ [200, {}, 'a']
95
+ end
96
+
97
+ @conn.options.params_encoder = Faraday::FlatParamsEncoder
98
+ assert_equal 'a', @conn.get('http://foo.com/hello?a[b]=1').body
99
+ end
100
+
72
101
  def test_raises_an_error_if_no_stub_is_found_for_request
73
102
  assert_raises Stubs::NotFound do
74
103
  @conn.get('/invalid'){ [200, {}, []] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.rc2
4
+ version: 0.9.0.rc3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: