http-form_data 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/CHANGES.md +8 -0
- data/lib/http/form_data.rb +7 -4
- data/lib/http/form_data/urlencoded.rb +3 -2
- data/lib/http/form_data/version.rb +1 -1
- data/spec/lib/http/form_data/urlencoded_spec.rb +11 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e781be9d32ee208fa4d379569b05bd2d4e9f30c4b29e0895aaea20e8ae193206
|
4
|
+
data.tar.gz: 8745d97530d549d45e94f9901a50ba6f0ee88177074b2411c56f03f7ac66134c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12b410ec71a443a006e0ec62005bc4b829987bc562b0d9604d527b1e6cbfe82ea2ef73ce55d46ea3d3496159b3d0a2233dd6be5ab42a8766aaf7a5be78479e27
|
7
|
+
data.tar.gz: 2644255b6eaaf24b38658894134e62ea45b84dbb8802a4cc920dc2c219e8ca67e9bc432a1d53b84b970b4e26fa833a7d7780c95591b9b0b871eb2ab659fcf13d
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 2.3.0 (2020-03-08)
|
2
|
+
|
3
|
+
* [#29](https://github.com/httprb/form_data/pull/29)
|
4
|
+
Enhance HTTP::FormData::Urlencoded with per-instance encoder.
|
5
|
+
[@summera][]
|
6
|
+
|
7
|
+
|
1
8
|
## 2.2.0 (2020-01-09)
|
2
9
|
|
3
10
|
* [#28](https://github.com/httprb/form_data/pull/28)
|
@@ -86,3 +93,4 @@
|
|
86
93
|
[@mhickman]: https://github.com/mhickman
|
87
94
|
[@HoneyryderChuck]: https://github.com/HoneyryderChuck
|
88
95
|
[@FabienChaynes]: https://github.com/FabienChaynes
|
96
|
+
[@summera]: https://github.com/summera
|
data/lib/http/form_data.rb
CHANGED
@@ -41,11 +41,14 @@ module HTTP
|
|
41
41
|
# @param [#to_h, Hash] data
|
42
42
|
# @return [Multipart] if any of values is a {FormData::File}
|
43
43
|
# @return [Urlencoded] otherwise
|
44
|
-
def create(data)
|
45
|
-
data
|
46
|
-
klass = multipart?(data) ? Multipart : Urlencoded
|
44
|
+
def create(data, encoder: nil)
|
45
|
+
data = ensure_hash data
|
47
46
|
|
48
|
-
|
47
|
+
if multipart?(data)
|
48
|
+
Multipart.new(data)
|
49
|
+
else
|
50
|
+
Urlencoded.new(data, :encoder => encoder)
|
51
|
+
end
|
49
52
|
end
|
50
53
|
|
51
54
|
# Coerce `obj` to Hash.
|
@@ -63,8 +63,9 @@ module HTTP
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# @param [#to_h, Hash] data form data key-value Hash
|
66
|
-
def initialize(data)
|
67
|
-
|
66
|
+
def initialize(data, encoder: nil)
|
67
|
+
encoder ||= self.class.encoder
|
68
|
+
@io = StringIO.new(encoder.call(FormData.ensure_hash(data)))
|
68
69
|
end
|
69
70
|
|
70
71
|
# Returns MIME type to be used for HTTP request `Content-Type` header.
|
@@ -64,4 +64,15 @@ RSpec.describe HTTP::FormData::Urlencoded do
|
|
64
64
|
expect(form_data.to_s).to eq('{"foo[bar]":"test"}')
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
context "with custom instance level encoder" do
|
69
|
+
let(:encoder) { proc { |data| ::JSON.dump(data) } }
|
70
|
+
subject(:form_data) do
|
71
|
+
HTTP::FormData::Urlencoded.new(data, :encoder => encoder)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "uses encoder passed to initializer" do
|
75
|
+
expect(form_data.to_s).to eq('{"foo[bar]":"test"}')
|
76
|
+
end
|
77
|
+
end
|
67
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-form_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey V Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Utility-belt to build form data request bodies. Provides support for
|
14
14
|
`application/x-www-form-urlencoded` and `multipart/form-data` types.
|
@@ -70,10 +70,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.7.6.2
|
74
75
|
signing_key:
|
75
76
|
specification_version: 4
|
76
|
-
summary: http-form_data-2.
|
77
|
+
summary: http-form_data-2.3.0
|
77
78
|
test_files:
|
78
79
|
- spec/fixtures/expected-multipart-body.tpl
|
79
80
|
- spec/fixtures/the-http-gem.info
|