faraday 2.2.0 → 2.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +11 -4
- data/lib/faraday/request/url_encoded.rb +3 -1
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +1 -1
- data/spec/faraday/params_encoders/nested_spec.rb +8 -0
- data/spec/faraday/request/url_encoded_spec.rb +12 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51764b6108e230dfff244e6e6e9f275f92f5fc1bcd1bf8e43d36058d35442e14
|
4
|
+
data.tar.gz: 2cdf2edfd3e3c0386f501c0c2609db4f5c879a2a1807869a7b7e690e4a22a77a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ce1d0df0639d8e7a8472085331796a787236989e07943a47e463f6d5c68d83bf180b55636e87d37ac654400fe11660ee10898c9b43122c29a211310682b621
|
7
|
+
data.tar.gz: 14af6c0c348cf3ca8ae7f7f8a95b3eb8b73b8a444d90a75c7eeb46d9edd4c840fa44dd2eda4e76653fd4924e6b20d13f32236e21bd303f90b589df1abc88da3d
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
This file is not being updated anymore. Instead, please check the [Releases](https://github.com/lostisland/faraday/releases) page.
|
6
6
|
|
7
|
+
## [2.2.0](https://github.com/lostisland/faraday/compare/v2.1.0...v2.2.0) (2022-02-03)
|
8
|
+
|
9
|
+
* Reintroduce the possibility to register middleware with symbols, strings or procs in [#1391](https://github.com/lostisland/faraday/pull/1391)
|
10
|
+
|
7
11
|
## [2.1.0](https://github.com/lostisland/faraday/compare/v2.0.1...v2.1.0) (2022-01-15)
|
8
12
|
|
9
13
|
* Fix test adapter thread safety by @iMacTia in [#1380](https://github.com/lostisland/faraday/pull/1380)
|
@@ -62,11 +62,17 @@ module Faraday
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def encode_array(parent, value)
|
65
|
-
|
66
|
-
return new_parent if value.empty?
|
65
|
+
return "#{parent}%5B%5D" if value.empty?
|
67
66
|
|
68
67
|
buffer = +''
|
69
|
-
value.
|
68
|
+
value.each_with_index do |val, index|
|
69
|
+
new_parent = if @array_indices
|
70
|
+
"#{parent}%5B#{index}%5D"
|
71
|
+
else
|
72
|
+
"#{parent}%5B%5D"
|
73
|
+
end
|
74
|
+
buffer << "#{encode_pair(new_parent, val)}&"
|
75
|
+
end
|
70
76
|
buffer.chop
|
71
77
|
end
|
72
78
|
end
|
@@ -161,7 +167,7 @@ module Faraday
|
|
161
167
|
# for your requests.
|
162
168
|
module NestedParamsEncoder
|
163
169
|
class << self
|
164
|
-
attr_accessor :sort_params
|
170
|
+
attr_accessor :sort_params, :array_indices
|
165
171
|
|
166
172
|
extend Forwardable
|
167
173
|
def_delegators :'Faraday::Utils', :escape, :unescape
|
@@ -169,6 +175,7 @@ module Faraday
|
|
169
175
|
|
170
176
|
# Useful default for OAuth and caching.
|
171
177
|
@sort_params = true
|
178
|
+
@array_indices = false
|
172
179
|
|
173
180
|
extend EncodeMethods
|
174
181
|
extend DecodeMethods
|
@@ -31,7 +31,9 @@ module Faraday
|
|
31
31
|
return unless process_request?(env)
|
32
32
|
|
33
33
|
env.request_headers[CONTENT_TYPE] ||= self.class.mime_type
|
34
|
-
|
34
|
+
return if env.body.respond_to?(:to_str) || env.body.respond_to?(:read)
|
35
|
+
|
36
|
+
yield(env.body)
|
35
37
|
end
|
36
38
|
|
37
39
|
# @param env [Faraday::Env]
|
data/lib/faraday/version.rb
CHANGED
data/lib/faraday.rb
CHANGED
@@ -47,7 +47,7 @@ module Faraday
|
|
47
47
|
|
48
48
|
# @overload default_adapter
|
49
49
|
# Gets the Symbol key identifying a default Adapter to use
|
50
|
-
# for the default {Faraday::Connection}. Defaults to `:
|
50
|
+
# for the default {Faraday::Connection}. Defaults to `:net_http`.
|
51
51
|
# @return [Symbol] the default adapter
|
52
52
|
# @overload default_adapter=(adapter)
|
53
53
|
# Updates default adapter while resetting {.default_connection}.
|
@@ -102,6 +102,14 @@ RSpec.describe Faraday::NestedParamsEncoder do
|
|
102
102
|
Faraday::NestedParamsEncoder.sort_params = true
|
103
103
|
end
|
104
104
|
|
105
|
+
it 'encodes arrays indices when asked' do
|
106
|
+
params = { a: [0, 1, 2] }
|
107
|
+
expect(subject.encode(params)).to eq('a%5B%5D=0&a%5B%5D=1&a%5B%5D=2')
|
108
|
+
Faraday::NestedParamsEncoder.array_indices = true
|
109
|
+
expect(subject.encode(params)).to eq('a%5B0%5D=0&a%5B1%5D=1&a%5B2%5D=2')
|
110
|
+
Faraday::NestedParamsEncoder.array_indices = false
|
111
|
+
end
|
112
|
+
|
105
113
|
shared_examples 'a wrong decoding' do
|
106
114
|
it do
|
107
115
|
expect { subject.decode(query) }.to raise_error(TypeError) do |e|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'stringio'
|
4
|
+
|
3
5
|
RSpec.describe Faraday::Request::UrlEncoded do
|
4
6
|
let(:conn) do
|
5
7
|
Faraday.new do |b|
|
@@ -7,7 +9,11 @@ RSpec.describe Faraday::Request::UrlEncoded do
|
|
7
9
|
b.adapter :test do |stub|
|
8
10
|
stub.post('/echo') do |env|
|
9
11
|
posted_as = env[:request_headers]['Content-Type']
|
10
|
-
|
12
|
+
body = env[:body]
|
13
|
+
if body.respond_to?(:read)
|
14
|
+
body = body.read
|
15
|
+
end
|
16
|
+
[200, { 'Content-Type' => posted_as }, body]
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
@@ -67,6 +73,11 @@ RSpec.describe Faraday::Request::UrlEncoded do
|
|
67
73
|
expect(response.body).to eq('a%5Bb%5D%5Bc%5D%5B%5D=d')
|
68
74
|
end
|
69
75
|
|
76
|
+
it 'works with files' do
|
77
|
+
response = conn.post('/echo', StringIO.new('str=apple'))
|
78
|
+
expect(response.body).to eq('str=apple')
|
79
|
+
end
|
80
|
+
|
70
81
|
context 'customising default_space_encoding' do
|
71
82
|
around do |example|
|
72
83
|
Faraday::Utils.default_space_encoding = '%20'
|
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: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-05-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-net_http
|
@@ -125,7 +125,7 @@ licenses:
|
|
125
125
|
- MIT
|
126
126
|
metadata:
|
127
127
|
homepage_uri: https://lostisland.github.io/faraday
|
128
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
128
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.3.0
|
129
129
|
source_code_uri: https://github.com/lostisland/faraday
|
130
130
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
131
131
|
post_install_message:
|