faraday-multipart 1.0.1 → 1.0.4

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: f89d6d75b77306ce8ae98d5f67bfb374f2d8c1abb3d93e140f03145cd3af9bf4
4
- data.tar.gz: 53409e6a8ef44fde13e5dae1cd651be72b0c6c530702cb1fc5f5f7e7e321da08
3
+ metadata.gz: 003f27fac04888822e0601b1ff9e67a374d3a07a77cdaa2a59e929956228fe6c
4
+ data.tar.gz: e8bf33e1089e8e3f4b9b2326edcd2e2bb2c32f87bb89b2336b798fed5806c942
5
5
  SHA512:
6
- metadata.gz: 8ba9da6eb5446afb9b351d6ccef7922a395e9310a675864ed72eca191daedb44cd521cbbf94b151f29ef20b7a8c1a178ca9c63d9363262bc7b6606352c4708b0
7
- data.tar.gz: 7a846e4401f7ea6a890c181f59da570c83b88bd89e7f311f3b26ae8f36ac3ac1748d95dbc46aed1f6763bf4c72222f7f049f6d2d1ed7f6db04d9d63ea6f2bb82
6
+ metadata.gz: 8cc6c3ac2a717c353e035f4de9b7486142df5c6266f2464db3dbd533fa4d8236f64498e7cf00b22d8afc3d17fd34d5d387d5665908454061495199ebb031cab7
7
+ data.tar.gz: b59ce976a29a837ff68953db793d28565d8a5579c808d8ce758cdb4663a0bca1e7ce802ab98152874b79dcaea47faa9177578e1b1eae464c5701ecf5dbe20751
data/CHANGELOG.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## [1.0.4](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.3) (2022-06-07)
4
4
 
5
- * Initial release.
5
+ ### What's Changed
6
+
7
+ * Drop support for 'multipart-post' < 2.0.0. This is not a breaking change as this gem's code didn't work with 1.x.
8
+ * Change references to `UploadIO` and `Parts` according to class reorganization in the 'multipart-post' gem 2.2.0 (see [multipart-post gem PR #89](https://github.com/socketry/multipart-post/pull/89))
9
+ * Introduce a backwards compatible safeguard so the gem still works with previous 'multipart-post' 2.x releases.
10
+
11
+ ## [1.0.3](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.3) (2022-01-08)
12
+
13
+ ### What's Changed
14
+
15
+ * Add `Faraday::ParamPart` alias back by @iMacTia in https://github.com/lostisland/faraday-multipart/pull/2
16
+
17
+ **Full Changelog**: https://github.com/lostisland/faraday-multipart/compare/v1.0.2...v1.0.3
18
+
19
+ ## [1.0.2](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.2) (2022-01-06)
20
+
21
+ ### Fixes
22
+
23
+ * Add missing UploadIO alias
24
+ * Re-add support for Ruby 2.4+
25
+
26
+ **Full Changelog**: https://github.com/lostisland/faraday-multipart/compare/v1.0.1...v1.0.2
27
+
28
+ ## [1.0.1](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.1) (2022-01-06)
29
+
30
+ ### What's Changed
31
+ * Add support for Faraday v1 by @iMacTia in https://github.com/lostisland/faraday-multipart/pull/1
32
+
33
+ **Full Changelog**: https://github.com/lostisland/faraday-multipart/compare/v1.0.0...v1.0.1
34
+
35
+ ## [1.0.0](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.0) (2022-01-04)
36
+
37
+ ### Summary
38
+
39
+ The initial release of the `faraday-multipart` gem.
40
+
41
+ This middleware was previously bundled with Faraday but was removed as of v2.0.
42
+
43
+ ### MIGRATION NOTES
44
+
45
+ If you're upgrading from Faraday 1.0 and including this middleware as a gem, please be aware the namespacing for helper classes has changed:
46
+
47
+ * `Faraday::FilePart` is now `Faraday::Multipart::FilePart`
48
+ * `Faraday::Parts` is now `Faraday::Multipart::Parts`
49
+ * `Faraday::CompositeReadIO` is now `Faraday::Multipart::CompositeReadIO`
50
+ * `Faraday::ParamPart` is now `Faraday::Multipart::ParamPart`
51
+
52
+ Moreover, in case you're adding the middleware to your faraday connection with the full qualified name rather than the `:multipart` alias, please be aware the middleware class is now `Faraday::Multipart::Middleware`.
data/README.md CHANGED
@@ -42,14 +42,16 @@ gem install faraday-multipart
42
42
  First of all, you'll need to add the multipart middleware to your Faraday connection:
43
43
 
44
44
  ```ruby
45
+ require 'faraday'
45
46
  require 'faraday/multipart'
46
47
 
47
48
  conn = Faraday.new(...) do |f|
48
- f.request :multipart
49
+ f.request :multipart, **options
49
50
  # ...
50
51
  end
51
52
  ```
52
53
 
54
+
53
55
  Payload can be a mix of POST data and multipart values.
54
56
 
55
57
  ```ruby
@@ -91,6 +93,50 @@ payload[:raw_with_id] = Faraday::Multipart::ParamPart.new(
91
93
  conn.post('/', payload)
92
94
  ```
93
95
 
96
+ ### Sending an array of documents
97
+
98
+ Sometimes, the server you're calling will expect an array of documents or other values for the same key.
99
+ The `multipart` middleware will automatically handle this scenario for you:
100
+
101
+ ```ruby
102
+ payload = {
103
+ files: [
104
+ Faraday::Multipart::FilePart.new(__FILE__, 'text/x-ruby'),
105
+ Faraday::Multipart::FilePart.new(__FILE__, 'text/x-pdf')
106
+ ],
107
+ url: [
108
+ 'http://mydomain.com/callback1',
109
+ 'http://mydomain.com/callback2'
110
+ ]
111
+ }
112
+
113
+ conn.post(url, payload)
114
+ #=> POST url[]=http://mydomain.com/callback1&url[]=http://mydomain.com/callback2
115
+ #=> and includes both files in the request under the `files[]` name
116
+ ```
117
+
118
+ However, by default these will be sent with `files[]` key and the URLs with `url[]`, similarly to arrays in URL parameters.
119
+ Some servers (e.g. Mailgun) expect each document to have the same parameter key instead.
120
+ You can instruct the `multipart` middleware to do so by providing the `flat_encode` option:
121
+
122
+ ```ruby
123
+ require 'faraday'
124
+ require 'faraday/multipart'
125
+
126
+ conn = Faraday.new(...) do |f|
127
+ f.request :multipart, flat_encode: true
128
+ # ...
129
+ end
130
+
131
+ payload = ... # see example above
132
+
133
+ conn.post(url, payload)
134
+ #=> POST url=http://mydomain.com/callback1&url=http://mydomain.com/callback2
135
+ #=> and includes both files in the request under the `files` name
136
+ ```
137
+
138
+ This works for both `UploadIO` and normal parameters alike.
139
+
94
140
  ## Development
95
141
 
96
142
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -99,8 +145,9 @@ Then, run `bin/test` to run the tests.
99
145
 
100
146
  To install this gem onto your local machine, run `rake build`.
101
147
 
102
- To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`. See how it
103
- works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
148
+ ### Releasing a new version
149
+
150
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2", and change the _Unreleased_ heading in `CHANGELOG.md` to a heading like "0.0.2 (2022-01-01)", and then use GitHub Releases to author a release. A GitHub Actions workflow then publishes a new gem to [RubyGems.org](https://rubygems.org/gems/faraday-multipart).
104
151
 
105
152
  ## Contributing
106
153
 
@@ -2,11 +2,10 @@
2
2
 
3
3
  require 'stringio'
4
4
 
5
- # multipart-post gem
6
- require 'composite_io'
7
- require 'parts'
8
-
9
5
  module Faraday
6
+ # Rubocop doesn't seem to understand that this is an extension to the
7
+ # Multipart module, so let's add a nodoc
8
+ # #:nodoc:
10
9
  module Multipart
11
10
  # Multipart value used to POST a binary data from a file or
12
11
  #
@@ -51,9 +50,16 @@ module Faraday
51
50
  # The open IO object for the uploaded file.
52
51
  #
53
52
  # @return [IO]
54
- FilePart = ::UploadIO
55
-
56
- Parts = ::Parts
53
+ if ::Gem::Requirement.new('>= 2.2.0').satisfied_by?(multipart_post_version)
54
+ require 'multipart/post'
55
+ FilePart = ::Multipart::Post::UploadIO
56
+ Parts = ::Multipart::Post::Parts
57
+ else
58
+ require 'composite_io'
59
+ require 'parts'
60
+ FilePart = ::UploadIO
61
+ Parts = ::Parts
62
+ end
57
63
 
58
64
  # Similar to, but not compatible with CompositeReadIO provided by the
59
65
  # multipart-post gem.
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
+ # #:nodoc:
4
5
  module Multipart
5
- VERSION = '1.0.1'
6
+ VERSION = '1.0.4'
7
+
8
+ def self.multipart_post_version
9
+ require 'multipart/post/version'
10
+ ::Gem::Version.new(::Multipart::Post::VERSION)
11
+ rescue LoadError
12
+ require 'multipart_post'
13
+ ::Gem::Version.new(::MultipartPost::VERSION)
14
+ end
6
15
  end
7
16
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'multipart/version'
3
4
  require_relative 'multipart/file_part'
4
5
  require_relative 'multipart/param_part'
5
6
  require_relative 'multipart/middleware'
6
- require_relative 'multipart/version'
7
7
 
8
8
  module Faraday
9
9
  # Main Faraday::Multipart module.
@@ -11,8 +11,16 @@ module Faraday
11
11
  Faraday::Request.register_middleware(multipart: Faraday::Multipart::Middleware)
12
12
  end
13
13
 
14
- # Aliases for Faraday v1
14
+ # Aliases for Faraday v1, these are all deprecated and will be removed in v2 of this middleware
15
15
  FilePart = Multipart::FilePart
16
+ ParamPart = Multipart::ParamPart
16
17
  Parts = Multipart::Parts
17
18
  CompositeReadIO = Multipart::CompositeReadIO
19
+ # multipart-post v2.2.0 introduces a new class hierarchy for classes like Parts and UploadIO
20
+ # For backwards compatibility, detect the gem version and use the right class
21
+ UploadIO = if ::Gem::Requirement.new('>= 2.2.0').satisfied_by?(Multipart.multipart_post_version)
22
+ ::Multipart::Post::UploadIO
23
+ else
24
+ ::UploadIO
25
+ end
18
26
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-multipart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Giuffrida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '3'
19
+ version: '2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '1.2'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '3'
26
+ version: '2'
33
27
  description: 'Perform multipart-post requests using Faraday.
34
28
 
35
29
  '
@@ -52,8 +46,8 @@ licenses:
52
46
  - MIT
53
47
  metadata:
54
48
  bug_tracker_uri: https://github.com/lostisland/faraday-multipart/issues
55
- changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.0.1/CHANGELOG.md
56
- documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.0.1
49
+ changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.0.4/CHANGELOG.md
50
+ documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.0.4
57
51
  homepage_uri: https://github.com/lostisland/faraday-multipart
58
52
  source_code_uri: https://github.com/lostisland/faraday-multipart
59
53
  wiki_uri: https://github.com/lostisland/faraday-multipart/wiki
@@ -65,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
59
  requirements:
66
60
  - - ">="
67
61
  - !ruby/object:Gem::Version
68
- version: '2.6'
62
+ version: '2.4'
69
63
  - - "<"
70
64
  - !ruby/object:Gem::Version
71
65
  version: '4'