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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e09c6384f02137e31adab5115524beb33decdf03cff1e52b6e37f660a5956256
4
- data.tar.gz: 5a2e181da1de4da73edb2be5d970b9ad4afbe2f2c9edcc8421ba3c885908f7a5
3
+ metadata.gz: e781be9d32ee208fa4d379569b05bd2d4e9f30c4b29e0895aaea20e8ae193206
4
+ data.tar.gz: 8745d97530d549d45e94f9901a50ba6f0ee88177074b2411c56f03f7ac66134c
5
5
  SHA512:
6
- metadata.gz: ade103ecd25eb756f92421d673ab68af8629c40ed6b2633af6cdf0d5173c4a9332aa7bf33970c85e2b1926ee5c4b3d2dc0d33f4eaa506512b36da398e9a4b402
7
- data.tar.gz: d89facbae50f67e1fb8f08b4395e37b6477a21c5d83bbe4efcebef488204020f100ef525e5141fbfa7186e905815662c8093a90b576ac8d19b3976c5e1d1da3a
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
@@ -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 = ensure_hash data
46
- klass = multipart?(data) ? Multipart : Urlencoded
44
+ def create(data, encoder: nil)
45
+ data = ensure_hash data
47
46
 
48
- klass.new data
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
- @io = StringIO.new(self.class.encoder.call(FormData.ensure_hash(data)))
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.
@@ -3,6 +3,6 @@
3
3
  module HTTP
4
4
  module FormData
5
5
  # Gem version.
6
- VERSION = "2.2.0"
6
+ VERSION = "2.3.0"
7
7
  end
8
8
  end
@@ -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.2.0
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-01-09 00:00:00.000000000 Z
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
- rubygems_version: 3.1.2
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.2.0
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