faraday 1.8.0 → 2.7.11
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 +197 -3
- data/LICENSE.md +1 -1
- data/README.md +34 -20
- data/Rakefile +3 -1
- data/examples/client_spec.rb +41 -19
- data/examples/client_test.rb +48 -22
- data/lib/faraday/adapter/test.rb +61 -12
- data/lib/faraday/adapter.rb +5 -9
- data/lib/faraday/connection.rb +58 -145
- data/lib/faraday/encoders/nested_params_encoder.rb +13 -6
- data/lib/faraday/error.rb +16 -11
- data/lib/faraday/logging/formatter.rb +27 -14
- data/lib/faraday/middleware.rb +3 -1
- data/lib/faraday/middleware_registry.rb +17 -63
- data/lib/faraday/options/connection_options.rb +7 -6
- data/lib/faraday/options/env.rb +85 -62
- data/lib/faraday/options/proxy_options.rb +7 -3
- data/lib/faraday/options/request_options.rb +7 -6
- data/lib/faraday/options/ssl_options.rb +56 -45
- data/lib/faraday/options.rb +4 -3
- data/lib/faraday/rack_builder.rb +23 -20
- data/lib/faraday/request/authorization.rb +33 -41
- data/lib/faraday/request/instrumentation.rb +5 -1
- data/lib/faraday/request/json.rb +64 -0
- data/lib/faraday/request/url_encoded.rb +5 -1
- data/lib/faraday/request.rb +20 -37
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +8 -4
- data/lib/faraday/response/raise_error.rb +29 -4
- data/lib/faraday/response.rb +10 -20
- data/lib/faraday/utils/headers.rb +7 -2
- data/lib/faraday/utils.rb +10 -5
- data/lib/faraday/version.rb +1 -1
- data/lib/faraday.rb +10 -38
- data/spec/faraday/adapter/test_spec.rb +65 -0
- data/spec/faraday/connection_spec.rb +163 -91
- data/spec/faraday/error_spec.rb +31 -6
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/middleware_spec.rb +18 -0
- data/spec/faraday/options/env_spec.rb +8 -2
- data/spec/faraday/options/options_spec.rb +1 -1
- data/spec/faraday/options/proxy_options_spec.rb +8 -0
- data/spec/faraday/params_encoders/nested_spec.rb +8 -0
- data/spec/faraday/rack_builder_spec.rb +26 -54
- data/spec/faraday/request/authorization_spec.rb +50 -28
- data/spec/faraday/request/instrumentation_spec.rb +5 -7
- data/spec/faraday/request/json_spec.rb +135 -0
- data/spec/faraday/request/url_encoded_spec.rb +12 -2
- data/spec/faraday/request_spec.rb +5 -15
- data/spec/faraday/response/json_spec.rb +117 -0
- data/spec/faraday/response/logger_spec.rb +38 -0
- data/spec/faraday/response/raise_error_spec.rb +35 -5
- data/spec/faraday/response_spec.rb +3 -1
- data/spec/faraday/utils/headers_spec.rb +22 -4
- data/spec/faraday/utils_spec.rb +63 -1
- data/spec/faraday_spec.rb +8 -4
- data/spec/support/fake_safe_buffer.rb +1 -1
- data/spec/support/helper_methods.rb +0 -37
- data/spec/support/shared_examples/adapter.rb +2 -2
- data/spec/support/shared_examples/request_method.rb +22 -21
- metadata +19 -134
- data/lib/faraday/adapter/typhoeus.rb +0 -15
- data/lib/faraday/autoload.rb +0 -87
- data/lib/faraday/dependency_loader.rb +0 -37
- data/lib/faraday/file_part.rb +0 -128
- data/lib/faraday/param_part.rb +0 -53
- data/lib/faraday/request/basic_authentication.rb +0 -20
- data/lib/faraday/request/multipart.rb +0 -106
- data/lib/faraday/request/retry.rb +0 -239
- data/lib/faraday/request/token_authentication.rb +0 -20
- data/spec/faraday/adapter/em_http_spec.rb +0 -49
- data/spec/faraday/adapter/em_synchrony_spec.rb +0 -18
- data/spec/faraday/adapter/excon_spec.rb +0 -49
- data/spec/faraday/adapter/httpclient_spec.rb +0 -73
- data/spec/faraday/adapter/net_http_spec.rb +0 -64
- data/spec/faraday/adapter/patron_spec.rb +0 -18
- data/spec/faraday/adapter/rack_spec.rb +0 -8
- data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
- data/spec/faraday/composite_read_io_spec.rb +0 -80
- data/spec/faraday/request/multipart_spec.rb +0 -302
- data/spec/faraday/request/retry_spec.rb +0 -242
- data/spec/faraday/response/middleware_spec.rb +0 -68
- data/spec/support/webmock_rack_app.rb +0 -68
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:
|
4
|
+
version: 2.7.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,140 +10,42 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-09-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: base64
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '1.0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - "~>"
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '1.0'
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: faraday-em_synchrony
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - "~>"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '1.0'
|
36
|
-
type: :runtime
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '1.0'
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: faraday-excon
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '1.1'
|
50
|
-
type: :runtime
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '1.1'
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
name: faraday-httpclient
|
59
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
19
|
+
- - ">="
|
62
20
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
21
|
+
version: '0'
|
64
22
|
type: :runtime
|
65
23
|
prerelease: false
|
66
24
|
version_requirements: !ruby/object:Gem::Requirement
|
67
25
|
requirements:
|
68
|
-
- - "
|
26
|
+
- - ">="
|
69
27
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
28
|
+
version: '0'
|
71
29
|
- !ruby/object:Gem::Dependency
|
72
30
|
name: faraday-net_http
|
73
|
-
requirement: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - "~>"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '1.0'
|
78
|
-
type: :runtime
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - "~>"
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '1.0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: faraday-net_http_persistent
|
87
|
-
requirement: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - "~>"
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '1.1'
|
92
|
-
type: :runtime
|
93
|
-
prerelease: false
|
94
|
-
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - "~>"
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: '1.1'
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: faraday-patron
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - "~>"
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '1.0'
|
106
|
-
type: :runtime
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - "~>"
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '1.0'
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
name: faraday-rack
|
115
|
-
requirement: !ruby/object:Gem::Requirement
|
116
|
-
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: '1.0'
|
120
|
-
type: :runtime
|
121
|
-
prerelease: false
|
122
|
-
version_requirements: !ruby/object:Gem::Requirement
|
123
|
-
requirements:
|
124
|
-
- - "~>"
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
version: '1.0'
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
-
name: multipart-post
|
129
31
|
requirement: !ruby/object:Gem::Requirement
|
130
32
|
requirements:
|
131
33
|
- - ">="
|
132
34
|
- !ruby/object:Gem::Version
|
133
|
-
version: '
|
35
|
+
version: '2.0'
|
134
36
|
- - "<"
|
135
37
|
- !ruby/object:Gem::Version
|
136
|
-
version: '3'
|
38
|
+
version: '3.1'
|
137
39
|
type: :runtime
|
138
40
|
prerelease: false
|
139
41
|
version_requirements: !ruby/object:Gem::Requirement
|
140
42
|
requirements:
|
141
43
|
- - ">="
|
142
44
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
45
|
+
version: '2.0'
|
144
46
|
- - "<"
|
145
47
|
- !ruby/object:Gem::Version
|
146
|
-
version: '3'
|
48
|
+
version: '3.1'
|
147
49
|
- !ruby/object:Gem::Dependency
|
148
50
|
name: ruby2_keywords
|
149
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,15 +75,11 @@ files:
|
|
173
75
|
- lib/faraday.rb
|
174
76
|
- lib/faraday/adapter.rb
|
175
77
|
- lib/faraday/adapter/test.rb
|
176
|
-
- lib/faraday/adapter/typhoeus.rb
|
177
78
|
- lib/faraday/adapter_registry.rb
|
178
|
-
- lib/faraday/autoload.rb
|
179
79
|
- lib/faraday/connection.rb
|
180
|
-
- lib/faraday/dependency_loader.rb
|
181
80
|
- lib/faraday/encoders/flat_params_encoder.rb
|
182
81
|
- lib/faraday/encoders/nested_params_encoder.rb
|
183
82
|
- lib/faraday/error.rb
|
184
|
-
- lib/faraday/file_part.rb
|
185
83
|
- lib/faraday/logging/formatter.rb
|
186
84
|
- lib/faraday/methods.rb
|
187
85
|
- lib/faraday/middleware.rb
|
@@ -192,18 +90,15 @@ files:
|
|
192
90
|
- lib/faraday/options/proxy_options.rb
|
193
91
|
- lib/faraday/options/request_options.rb
|
194
92
|
- lib/faraday/options/ssl_options.rb
|
195
|
-
- lib/faraday/param_part.rb
|
196
93
|
- lib/faraday/parameters.rb
|
197
94
|
- lib/faraday/rack_builder.rb
|
198
95
|
- lib/faraday/request.rb
|
199
96
|
- lib/faraday/request/authorization.rb
|
200
|
-
- lib/faraday/request/basic_authentication.rb
|
201
97
|
- lib/faraday/request/instrumentation.rb
|
202
|
-
- lib/faraday/request/
|
203
|
-
- lib/faraday/request/retry.rb
|
204
|
-
- lib/faraday/request/token_authentication.rb
|
98
|
+
- lib/faraday/request/json.rb
|
205
99
|
- lib/faraday/request/url_encoded.rb
|
206
100
|
- lib/faraday/response.rb
|
101
|
+
- lib/faraday/response/json.rb
|
207
102
|
- lib/faraday/response/logger.rb
|
208
103
|
- lib/faraday/response/raise_error.rb
|
209
104
|
- lib/faraday/utils.rb
|
@@ -211,20 +106,12 @@ files:
|
|
211
106
|
- lib/faraday/utils/params_hash.rb
|
212
107
|
- lib/faraday/version.rb
|
213
108
|
- spec/external_adapters/faraday_specs_setup.rb
|
214
|
-
- spec/faraday/adapter/em_http_spec.rb
|
215
|
-
- spec/faraday/adapter/em_synchrony_spec.rb
|
216
|
-
- spec/faraday/adapter/excon_spec.rb
|
217
|
-
- spec/faraday/adapter/httpclient_spec.rb
|
218
|
-
- spec/faraday/adapter/net_http_spec.rb
|
219
|
-
- spec/faraday/adapter/patron_spec.rb
|
220
|
-
- spec/faraday/adapter/rack_spec.rb
|
221
109
|
- spec/faraday/adapter/test_spec.rb
|
222
|
-
- spec/faraday/adapter/typhoeus_spec.rb
|
223
110
|
- spec/faraday/adapter_registry_spec.rb
|
224
111
|
- spec/faraday/adapter_spec.rb
|
225
|
-
- spec/faraday/composite_read_io_spec.rb
|
226
112
|
- spec/faraday/connection_spec.rb
|
227
113
|
- spec/faraday/error_spec.rb
|
114
|
+
- spec/faraday/middleware_registry_spec.rb
|
228
115
|
- spec/faraday/middleware_spec.rb
|
229
116
|
- spec/faraday/options/env_spec.rb
|
230
117
|
- spec/faraday/options/options_spec.rb
|
@@ -235,12 +122,11 @@ files:
|
|
235
122
|
- spec/faraday/rack_builder_spec.rb
|
236
123
|
- spec/faraday/request/authorization_spec.rb
|
237
124
|
- spec/faraday/request/instrumentation_spec.rb
|
238
|
-
- spec/faraday/request/
|
239
|
-
- spec/faraday/request/retry_spec.rb
|
125
|
+
- spec/faraday/request/json_spec.rb
|
240
126
|
- spec/faraday/request/url_encoded_spec.rb
|
241
127
|
- spec/faraday/request_spec.rb
|
128
|
+
- spec/faraday/response/json_spec.rb
|
242
129
|
- spec/faraday/response/logger_spec.rb
|
243
|
-
- spec/faraday/response/middleware_spec.rb
|
244
130
|
- spec/faraday/response/raise_error_spec.rb
|
245
131
|
- spec/faraday/response_spec.rb
|
246
132
|
- spec/faraday/utils/headers_spec.rb
|
@@ -254,13 +140,12 @@ files:
|
|
254
140
|
- spec/support/shared_examples/params_encoder.rb
|
255
141
|
- spec/support/shared_examples/request_method.rb
|
256
142
|
- spec/support/streaming_response_checker.rb
|
257
|
-
- spec/support/webmock_rack_app.rb
|
258
143
|
homepage: https://lostisland.github.io/faraday
|
259
144
|
licenses:
|
260
145
|
- MIT
|
261
146
|
metadata:
|
262
147
|
homepage_uri: https://lostisland.github.io/faraday
|
263
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/
|
148
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.11
|
264
149
|
source_code_uri: https://github.com/lostisland/faraday
|
265
150
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
266
151
|
post_install_message:
|
@@ -272,14 +157,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
272
157
|
requirements:
|
273
158
|
- - ">="
|
274
159
|
- !ruby/object:Gem::Version
|
275
|
-
version: '2.
|
160
|
+
version: '2.6'
|
276
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
277
162
|
requirements:
|
278
163
|
- - ">="
|
279
164
|
- !ruby/object:Gem::Version
|
280
165
|
version: '0'
|
281
166
|
requirements: []
|
282
|
-
rubygems_version: 3.
|
167
|
+
rubygems_version: 3.1.6
|
283
168
|
signing_key:
|
284
169
|
specification_version: 4
|
285
170
|
summary: HTTP/REST API client library.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Adapter
|
5
|
-
# Typhoeus adapter. This class is just a stub, the real adapter is in
|
6
|
-
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb
|
7
|
-
class Typhoeus < Faraday::Adapter
|
8
|
-
# Needs to define this method in order to support Typhoeus <= 1.3.0
|
9
|
-
def call; end
|
10
|
-
|
11
|
-
dependency 'typhoeus'
|
12
|
-
dependency 'typhoeus/adapters/faraday'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/faraday/autoload.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
# Adds the ability for other modules to manage autoloadable
|
5
|
-
# constants.
|
6
|
-
#
|
7
|
-
# @api private
|
8
|
-
module AutoloadHelper
|
9
|
-
# Registers the constants to be auto loaded.
|
10
|
-
#
|
11
|
-
# @param prefix [String] The require prefix. If the path is inside Faraday,
|
12
|
-
# then it will be prefixed with the root path of this loaded
|
13
|
-
# Faraday version.
|
14
|
-
# @param options [{ Symbol => String }] library names.
|
15
|
-
#
|
16
|
-
# @example
|
17
|
-
#
|
18
|
-
# Faraday.autoload_all 'faraday/foo',
|
19
|
-
# Bar: 'bar'
|
20
|
-
#
|
21
|
-
# # requires faraday/foo/bar to load Faraday::Bar.
|
22
|
-
# Faraday::Bar
|
23
|
-
#
|
24
|
-
# @return [void]
|
25
|
-
def autoload_all(prefix, options)
|
26
|
-
if prefix.match? %r{^faraday(/|$)}i
|
27
|
-
prefix = File.join(Faraday.root_path, prefix)
|
28
|
-
end
|
29
|
-
|
30
|
-
options.each do |const_name, path|
|
31
|
-
autoload const_name, File.join(prefix, path)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Loads each autoloaded constant. If thread safety is a concern,
|
36
|
-
# wrap this in a Mutex.
|
37
|
-
#
|
38
|
-
# @return [void]
|
39
|
-
def load_autoloaded_constants
|
40
|
-
constants.each do |const|
|
41
|
-
const_get(const) if autoload?(const)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Filters the module's contents with those that have been already
|
46
|
-
# autoloaded.
|
47
|
-
#
|
48
|
-
# @return [Array<Class, Module>]
|
49
|
-
def all_loaded_constants
|
50
|
-
constants
|
51
|
-
.map { |c| const_get(c) }
|
52
|
-
.select { |a| a.respond_to?(:loaded?) && a.loaded? }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Adapter is the base class for all Faraday adapters.
|
57
|
-
# @see lib/faraday/adapter.rb Original class location
|
58
|
-
class Adapter
|
59
|
-
extend AutoloadHelper
|
60
|
-
autoload_all 'faraday/adapter',
|
61
|
-
Typhoeus: 'typhoeus',
|
62
|
-
Test: 'test'
|
63
|
-
end
|
64
|
-
|
65
|
-
# Request represents a single HTTP request for a Faraday adapter to make.
|
66
|
-
# @see lib/faraday/request.rb Original class location
|
67
|
-
class Request
|
68
|
-
extend AutoloadHelper
|
69
|
-
autoload_all 'faraday/request',
|
70
|
-
UrlEncoded: 'url_encoded',
|
71
|
-
Multipart: 'multipart',
|
72
|
-
Retry: 'retry',
|
73
|
-
Authorization: 'authorization',
|
74
|
-
BasicAuthentication: 'basic_authentication',
|
75
|
-
TokenAuthentication: 'token_authentication',
|
76
|
-
Instrumentation: 'instrumentation'
|
77
|
-
end
|
78
|
-
|
79
|
-
# Response represents the returned value of a sent Faraday request.
|
80
|
-
# @see lib/faraday/response.rb Original class location
|
81
|
-
class Response
|
82
|
-
extend AutoloadHelper
|
83
|
-
autoload_all 'faraday/response',
|
84
|
-
RaiseError: 'raise_error',
|
85
|
-
Logger: 'logger'
|
86
|
-
end
|
87
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
# DependencyLoader helps Faraday adapters and middleware load dependencies.
|
5
|
-
module DependencyLoader
|
6
|
-
attr_reader :load_error
|
7
|
-
|
8
|
-
# Executes a block which should try to require and reference dependent
|
9
|
-
# libraries
|
10
|
-
def dependency(lib = nil)
|
11
|
-
lib ? require(lib) : yield
|
12
|
-
rescue LoadError, NameError => e
|
13
|
-
self.load_error = e
|
14
|
-
end
|
15
|
-
|
16
|
-
def new(*)
|
17
|
-
unless loaded?
|
18
|
-
raise "missing dependency for #{self}: #{load_error.message}"
|
19
|
-
end
|
20
|
-
|
21
|
-
super
|
22
|
-
end
|
23
|
-
|
24
|
-
def loaded?
|
25
|
-
load_error.nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
def inherited(subclass)
|
29
|
-
super
|
30
|
-
subclass.send(:load_error=, load_error)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
attr_writer :load_error
|
36
|
-
end
|
37
|
-
end
|
data/lib/faraday/file_part.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
# multipart-post gem
|
6
|
-
require 'composite_io'
|
7
|
-
require 'parts'
|
8
|
-
|
9
|
-
module Faraday
|
10
|
-
# Multipart value used to POST a binary data from a file or
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# payload = { file: Faraday::FilePart.new("file_name.ext", "content/type") }
|
14
|
-
# http.post("/upload", payload)
|
15
|
-
#
|
16
|
-
|
17
|
-
# @!method initialize(filename_or_io, content_type, filename = nil, opts = {})
|
18
|
-
#
|
19
|
-
# @param filename_or_io [String, IO] Either a String filename to a local
|
20
|
-
# file or an open IO object.
|
21
|
-
# @param content_type [String] String content type of the file data.
|
22
|
-
# @param filename [String] Optional String filename, usually to add context
|
23
|
-
# to a given IO object.
|
24
|
-
# @param opts [Hash] Optional Hash of String key/value pairs to describethis
|
25
|
-
# this uploaded file. Expected Header keys include:
|
26
|
-
# * Content-Transfer-Encoding - Defaults to "binary"
|
27
|
-
# * Content-Disposition - Defaults to "form-data"
|
28
|
-
# * Content-Type - Defaults to the content_type argument.
|
29
|
-
# * Content-ID - Optional.
|
30
|
-
#
|
31
|
-
# @return [Faraday::FilePart]
|
32
|
-
#
|
33
|
-
# @!attribute [r] content_type
|
34
|
-
# The uploaded binary data's content type.
|
35
|
-
#
|
36
|
-
# @return [String]
|
37
|
-
#
|
38
|
-
# @!attribute [r] original_filename
|
39
|
-
# The base filename, taken either from the filename_or_io or filename
|
40
|
-
# arguments in #initialize.
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
#
|
44
|
-
# @!attribute [r] opts
|
45
|
-
# Extra String key/value pairs to make up the header for this uploaded file.
|
46
|
-
#
|
47
|
-
# @return [Hash]
|
48
|
-
#
|
49
|
-
# @!attribute [r] io
|
50
|
-
# The open IO object for the uploaded file.
|
51
|
-
#
|
52
|
-
# @return [IO]
|
53
|
-
FilePart = ::UploadIO
|
54
|
-
|
55
|
-
# Multipart value used to POST a file.
|
56
|
-
#
|
57
|
-
# @deprecated Use FilePart instead of this class. It behaves identically, with
|
58
|
-
# a matching name to ParamPart.
|
59
|
-
UploadIO = ::UploadIO
|
60
|
-
|
61
|
-
Parts = ::Parts
|
62
|
-
|
63
|
-
# Similar to, but not compatible with CompositeReadIO provided by the
|
64
|
-
# multipart-post gem.
|
65
|
-
# https://github.com/nicksieger/multipart-post/blob/master/lib/composite_io.rb
|
66
|
-
class CompositeReadIO
|
67
|
-
def initialize(*parts)
|
68
|
-
@parts = parts.flatten
|
69
|
-
@ios = @parts.map(&:to_io)
|
70
|
-
@index = 0
|
71
|
-
end
|
72
|
-
|
73
|
-
# @return [Integer] sum of the lengths of all the parts
|
74
|
-
def length
|
75
|
-
@parts.inject(0) { |sum, part| sum + part.length }
|
76
|
-
end
|
77
|
-
|
78
|
-
# Rewind each of the IOs and reset the index to 0.
|
79
|
-
#
|
80
|
-
# @return [void]
|
81
|
-
def rewind
|
82
|
-
@ios.each(&:rewind)
|
83
|
-
@index = 0
|
84
|
-
end
|
85
|
-
|
86
|
-
# Read from IOs in order until `length` bytes have been received.
|
87
|
-
#
|
88
|
-
# @param length [Integer, nil]
|
89
|
-
# @param outbuf [String, nil]
|
90
|
-
def read(length = nil, outbuf = nil)
|
91
|
-
got_result = false
|
92
|
-
outbuf = outbuf ? (+outbuf).replace('') : +''
|
93
|
-
|
94
|
-
while (io = current_io)
|
95
|
-
if (result = io.read(length))
|
96
|
-
got_result ||= !result.nil?
|
97
|
-
result.force_encoding('BINARY') if result.respond_to?(:force_encoding)
|
98
|
-
outbuf << result
|
99
|
-
length -= result.length if length
|
100
|
-
break if length&.zero?
|
101
|
-
end
|
102
|
-
advance_io
|
103
|
-
end
|
104
|
-
!got_result && length ? nil : outbuf
|
105
|
-
end
|
106
|
-
|
107
|
-
# Close each of the IOs.
|
108
|
-
#
|
109
|
-
# @return [void]
|
110
|
-
def close
|
111
|
-
@ios.each(&:close)
|
112
|
-
end
|
113
|
-
|
114
|
-
def ensure_open_and_readable
|
115
|
-
# Rubinius compatibility
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
def current_io
|
121
|
-
@ios[@index]
|
122
|
-
end
|
123
|
-
|
124
|
-
def advance_io
|
125
|
-
@index += 1
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
data/lib/faraday/param_part.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
# Multipart value used to POST data with a content type.
|
5
|
-
class ParamPart
|
6
|
-
# @param value [String] Uploaded content as a String.
|
7
|
-
# @param content_type [String] String content type of the value.
|
8
|
-
# @param content_id [String] Optional String of this value's Content-ID.
|
9
|
-
#
|
10
|
-
# @return [Faraday::ParamPart]
|
11
|
-
def initialize(value, content_type, content_id = nil)
|
12
|
-
@value = value
|
13
|
-
@content_type = content_type
|
14
|
-
@content_id = content_id
|
15
|
-
end
|
16
|
-
|
17
|
-
# Converts this value to a form part.
|
18
|
-
#
|
19
|
-
# @param boundary [String] String multipart boundary that must not exist in
|
20
|
-
# the content exactly.
|
21
|
-
# @param key [String] String key name for this value.
|
22
|
-
#
|
23
|
-
# @return [Faraday::Parts::Part]
|
24
|
-
def to_part(boundary, key)
|
25
|
-
Faraday::Parts::Part.new(boundary, key, value, headers)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns a Hash of String key/value pairs.
|
29
|
-
#
|
30
|
-
# @return [Hash]
|
31
|
-
def headers
|
32
|
-
{
|
33
|
-
'Content-Type' => content_type,
|
34
|
-
'Content-ID' => content_id
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
# The content to upload.
|
39
|
-
#
|
40
|
-
# @return [String]
|
41
|
-
attr_reader :value
|
42
|
-
|
43
|
-
# The value's content type.
|
44
|
-
#
|
45
|
-
# @return [String]
|
46
|
-
attr_reader :content_type
|
47
|
-
|
48
|
-
# The value's content ID, if given.
|
49
|
-
#
|
50
|
-
# @return [String, nil]
|
51
|
-
attr_reader :content_id
|
52
|
-
end
|
53
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module Faraday
|
6
|
-
class Request
|
7
|
-
# Authorization middleware for Basic Authentication.
|
8
|
-
class BasicAuthentication < load_middleware(:authorization)
|
9
|
-
# @param login [String]
|
10
|
-
# @param pass [String]
|
11
|
-
#
|
12
|
-
# @return [String] a Basic Authentication header line
|
13
|
-
def self.header(login, pass)
|
14
|
-
value = Base64.encode64([login, pass].join(':'))
|
15
|
-
value.delete!("\n")
|
16
|
-
super(:Basic, value)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|