faraday 1.0.0.pre.rc1 → 1.0.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 +276 -0
- data/README.md +4 -4
- data/Rakefile +7 -0
- data/UPGRADING.md +55 -0
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday.rb +4 -4
- data/lib/faraday/adapter.rb +46 -0
- data/lib/faraday/adapter/em_http.rb +5 -6
- data/lib/faraday/adapter/em_http_ssl_patch.rb +1 -1
- data/lib/faraday/adapter/excon.rb +24 -22
- data/lib/faraday/adapter/httpclient.rb +40 -39
- data/lib/faraday/adapter/net_http.rb +42 -38
- data/lib/faraday/adapter/net_http_persistent.rb +3 -1
- data/lib/faraday/adapter/patron.rb +42 -24
- data/lib/faraday/adapter/rack.rb +2 -1
- data/lib/faraday/connection.rb +10 -22
- data/lib/faraday/encoders/flat_params_encoder.rb +7 -3
- data/lib/faraday/error.rb +44 -12
- data/lib/faraday/{upload_io.rb → file_part.rb} +53 -3
- data/lib/faraday/logging/formatter.rb +28 -15
- data/lib/faraday/middleware.rb +8 -0
- data/lib/faraday/options.rb +1 -1
- data/lib/faraday/options/env.rb +1 -1
- data/lib/faraday/options/request_options.rb +3 -2
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/request/multipart.rb +9 -1
- data/lib/faraday/response.rb +2 -2
- data/lib/faraday/response/raise_error.rb +2 -0
- data/spec/faraday/adapter/em_http_spec.rb +47 -0
- data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
- data/spec/faraday/adapter/excon_spec.rb +49 -0
- data/spec/faraday/adapter/httpclient_spec.rb +73 -0
- data/spec/faraday/adapter/net_http_persistent_spec.rb +57 -0
- data/spec/faraday/adapter/net_http_spec.rb +64 -0
- data/spec/faraday/adapter/patron_spec.rb +18 -0
- data/spec/faraday/adapter/rack_spec.rb +8 -0
- data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/composite_read_io_spec.rb +80 -0
- data/spec/faraday/connection_spec.rb +691 -0
- data/spec/faraday/error_spec.rb +45 -0
- data/spec/faraday/middleware_spec.rb +26 -0
- data/spec/faraday/options/env_spec.rb +70 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +37 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +34 -0
- data/spec/faraday/params_encoders/nested_spec.rb +134 -0
- data/spec/faraday/rack_builder_spec.rb +196 -0
- data/spec/faraday/request/authorization_spec.rb +88 -0
- data/spec/faraday/request/instrumentation_spec.rb +76 -0
- data/spec/faraday/request/multipart_spec.rb +274 -0
- data/spec/faraday/request/retry_spec.rb +242 -0
- data/spec/faraday/request/url_encoded_spec.rb +70 -0
- data/spec/faraday/request_spec.rb +109 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/middleware_spec.rb +52 -0
- data/spec/faraday/response/raise_error_spec.rb +106 -0
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +56 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +132 -0
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +133 -0
- data/spec/support/shared_examples/adapter.rb +104 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +234 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +65 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d3d650c5d465a0862cddd7ab2ed27fbfb4a6e5f2cfcbb54ba753bcc1ce9e40e
|
4
|
+
data.tar.gz: 953336deeb3dd2e0228368209bdffc7815b376772269c439e21374bc22b70484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b80c084a8714d995dec61c918891a63720dbcdddf2eb3ecb7106f40a03bb341c4f03ffe976365c5450b2dcffd0b1f52c1cd4320ea24591dfaef7d5fdbbe12562
|
7
|
+
data.tar.gz: 67f8134fae885d3bb2e621afa701d6d535409bbb0141ad699f4d290059d61bf856915f622e214251f05e8b893a69bf68439118074712a22e75e3705b249dbb85
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
# Faraday Changelog
|
2
|
+
|
3
|
+
## v1.0
|
4
|
+
|
5
|
+
Features:
|
6
|
+
|
7
|
+
* Add #trace support to Faraday::Connection #861 (@technoweenie)
|
8
|
+
* Add the log formatter that is easy to override and safe to inherit #889 (@prikha)
|
9
|
+
* Support standalone adapters #941 (@iMacTia)
|
10
|
+
* Introduce Faraday::ConflictError for 409 response code #979 (@lucasmoreno)
|
11
|
+
* Add support for setting `read_timeout` option separately #1003 (@springerigor)
|
12
|
+
* Refactor and cleanup timeout settings across adapters #1022 (@technoweenie)
|
13
|
+
* Create ParamPart class to allow multipart posts with JSON content and file upload at the same time #1017 (@jeremy-israel)
|
14
|
+
* Copy UploadIO const -> FilePart for consistency with ParamPart #1018, #1021 (@technoweenie)
|
15
|
+
* Implement streaming responses in the Excon adapter #1026 (@technoweenie)
|
16
|
+
* Add default implementation of `Middleware#close`. #1069 (@ioquatix)
|
17
|
+
* Add `Adapter#close` so that derived classes can call super. #1091 (@ioquatix)
|
18
|
+
* Add log_level option to logger default formatter #1079 (@amrrbakry)
|
19
|
+
* Fix empty array for FlatParamsEncoder `{key: []} -> "key="` #1084 (@mrexox)
|
20
|
+
|
21
|
+
Bugs:
|
22
|
+
|
23
|
+
* Explicitly require date for DateTime library in Retry middleware #844 (@nickpresta)
|
24
|
+
* Refactor Adapter as final endpoints #846 (@iMacTia)
|
25
|
+
* Separate Request and Response bodies in Faraday::Env #847 (@iMacTia)
|
26
|
+
* Implement Faraday::Connection#options to make HTTP requests with the OPTIONS verb. #857 (@technoweenie)
|
27
|
+
* Multipart: Drop Ruby 1.8 String behavior compat #892 (@olleolleolle)
|
28
|
+
* Fix Ruby warnings in Faraday::Options.memoized #962 (@technoweenie)
|
29
|
+
* Allow setting min/max SSL version for a Net::HTTP::Persistent connection #972, #973 (@bdewater, @olleolleolle)
|
30
|
+
* Fix instances of frozen empty string literals #1040 (@BobbyMcWho)
|
31
|
+
* remove temp_proxy and improve proxy tests #1063 (@technoweenie)
|
32
|
+
* improve error initializer consistency #1095 (@technoweenie)
|
33
|
+
|
34
|
+
Misc:
|
35
|
+
|
36
|
+
* Convert minitest suite to RSpec #832 (@iMacTia, with help from @gaynetdinov, @Insti, @technoweenie)
|
37
|
+
* Major effort to update code to RuboCop standards. #854 (@olleolleolle, @iMacTia, @technoweenie, @htwroclau, @jherdman, @Drenmi, @Insti)
|
38
|
+
* Rubocop #1044, #1047 (@BobbyMcWho, @olleolleolle)
|
39
|
+
* Documentation tweaks (@adsteel, @Hubro, @iMacTia, @olleolleolle, @technoweenie)
|
40
|
+
* Update license year #981 (@Kevin-Kawai)
|
41
|
+
* Configure Jekyll plugin jekyll-remote-theme to support Docker usage #999 (@Lewiscowles1986)
|
42
|
+
* Fix Ruby 2.7 warnings #1009 (@tenderlove)
|
43
|
+
* Cleanup adapter connections #1023 (@technoweenie)
|
44
|
+
* Describe clearing cached stubs #1045 (@viraptor)
|
45
|
+
* Add project metadata to the gemspec #1046 (@orien)
|
46
|
+
|
47
|
+
## v0.17.3
|
48
|
+
|
49
|
+
Fixes:
|
50
|
+
|
51
|
+
* Reverts changes in error classes hierarchy. #1092 (@iMacTia)
|
52
|
+
* Fix Ruby 1.9 syntax errors and improve Error class testing #1094 (@BanzaiMan,
|
53
|
+
@mrexox, @technoweenie)
|
54
|
+
|
55
|
+
Misc:
|
56
|
+
|
57
|
+
* Stops using `&Proc.new` for block forwarding. #1083 (@olleolleolle)
|
58
|
+
* Update CI to test against ruby 2.0-2.7 #1087, #1099 (@iMacTia, @olleolleolle,
|
59
|
+
@technoweenie)
|
60
|
+
* require FARADAY_DEPRECATE=warn to show Faraday v1.0 deprecation warnings
|
61
|
+
#1098 (@technoweenie)
|
62
|
+
|
63
|
+
## v0.17.1
|
64
|
+
|
65
|
+
Final release before Faraday v1.0, with important fixes for Ruby 2.7.
|
66
|
+
|
67
|
+
Fixes:
|
68
|
+
|
69
|
+
* RaiseError response middleware raises exception if HTTP client returns a nil
|
70
|
+
status. #1042 (@jonnyom, @BobbyMcWho)
|
71
|
+
|
72
|
+
Misc:
|
73
|
+
|
74
|
+
* Fix Ruby 2.7 warnings (#1009)
|
75
|
+
* Add `Faraday::Deprecate` to warn about upcoming v1.0 changes. (#1054, #1059,
|
76
|
+
#1076, #1077)
|
77
|
+
* Add release notes up to current in CHANGELOG.md (#1066)
|
78
|
+
* Port minimal rspec suite from main branch to run backported tests. (#1058)
|
79
|
+
|
80
|
+
## v0.17.0
|
81
|
+
|
82
|
+
This release is the same as v0.15.4. It was pushed to cover up releases
|
83
|
+
v0.16.0-v0.16.2.
|
84
|
+
|
85
|
+
## v0.15.4
|
86
|
+
|
87
|
+
* Expose `pool_size` as a option for the NetHttpPersistent adapter (#834)
|
88
|
+
|
89
|
+
## v0.15.3
|
90
|
+
|
91
|
+
* Make Faraday::Request serialisable with Marshal. (#803)
|
92
|
+
* Add DEFAULT_EXCEPTIONS constant to Request::Retry (#814)
|
93
|
+
* Add support for Ruby 2.6 Net::HTTP write_timeout (#824)
|
94
|
+
|
95
|
+
## v0.15.2
|
96
|
+
|
97
|
+
* Prevents `Net::HTTP` adapters to retry request internally by setting `max_retries` to 0 if available (Ruby 2.5+). (#799)
|
98
|
+
* Fixes `NestedParamsEncoder` handling of empty array values (#801)
|
99
|
+
|
100
|
+
## v0.15.1
|
101
|
+
|
102
|
+
* NetHttpPersistent adapter better reuse of SSL connections (#793)
|
103
|
+
* Refactor: inline cached_connection (#797)
|
104
|
+
* Logger middleware: use $stdout instead of STDOUT (#794)
|
105
|
+
* Fix: do not memoize/reuse Patron session (#796)
|
106
|
+
|
107
|
+
Also in this release:
|
108
|
+
|
109
|
+
* Allow setting min/max ssl version for Net::HTTP (#792)
|
110
|
+
* Allow setting min/max ssl version for Excon (#795)
|
111
|
+
|
112
|
+
## v0.15.0
|
113
|
+
|
114
|
+
Features:
|
115
|
+
|
116
|
+
* Added retry block option to retry middleware. (#770)
|
117
|
+
* Retry middleware improvements (honour Retry-After header, retry statuses) (#773)
|
118
|
+
* Improve response logger middleware output (#784)
|
119
|
+
|
120
|
+
Fixes:
|
121
|
+
|
122
|
+
* Remove unused class error (#767)
|
123
|
+
* Fix minor typo in README (#760)
|
124
|
+
* Reuse persistent connections when using net-http-persistent (#778)
|
125
|
+
* Fix Retry middleware documentation (#781)
|
126
|
+
* Returns the http response when giving up on retrying by status (#783)
|
127
|
+
|
128
|
+
## v0.14.0
|
129
|
+
|
130
|
+
Features:
|
131
|
+
|
132
|
+
* Allow overriding env proxy #754 (@iMacTia)
|
133
|
+
* Remove legacy Typhoeus adapter #715 (@olleolleolle)
|
134
|
+
* External Typhoeus Adapter Compatibility #748 (@iMacTia)
|
135
|
+
* Warn about missing adapter when making a request #743 (@antstorm)
|
136
|
+
* Faraday::Adapter::Test stubs now support entire urls (with host) #741 (@erik-escobedo)
|
137
|
+
|
138
|
+
Fixes:
|
139
|
+
|
140
|
+
* If proxy is manually provided, this takes priority over `find_proxy` #724 (@iMacTia)
|
141
|
+
* Fixes the behaviour for Excon's open_timeout (not setting write_timeout anymore) #731 (@apachelogger)
|
142
|
+
* Handle all connection timeout messages in Patron #687 (@stayhero)
|
143
|
+
|
144
|
+
## v0.13.1
|
145
|
+
|
146
|
+
* Fixes an incompatibility with Addressable::URI being used as uri_parser
|
147
|
+
|
148
|
+
## v0.13.0
|
149
|
+
|
150
|
+
Features:
|
151
|
+
|
152
|
+
* Dynamically reloads the proxy when performing a request on an absolute domain (#701)
|
153
|
+
* Adapter support for Net::HTTP::Persistent v3.0.0 (#619)
|
154
|
+
|
155
|
+
Fixes:
|
156
|
+
|
157
|
+
* Prefer #hostname over #host. (#714)
|
158
|
+
* Fixes an edge-case issue with response headers parsing (missing HTTP header) (#719)
|
159
|
+
|
160
|
+
## v0.12.2
|
161
|
+
|
162
|
+
* Parse headers from aggregated proxy requests/responses (#681)
|
163
|
+
* Guard against invalid middleware configuration with warning (#685)
|
164
|
+
* Do not use :insecure option by default in Patron (#691)
|
165
|
+
* Fixes an issue with HTTPClient not raising a `Faraday::ConnectionFailed` (#702)
|
166
|
+
* Fixes YAML serialization/deserialization for `Faraday::Utils::Headers` (#690)
|
167
|
+
* Fixes an issue with Options having a nil value (#694)
|
168
|
+
* Fixes an issue with Faraday.default_connection not using Faraday.default_connection_options (#698)
|
169
|
+
* Fixes an issue with Options.merge! and Faraday instrumentation middleware (#710)
|
170
|
+
|
171
|
+
## v0.12.1
|
172
|
+
|
173
|
+
* Fix an issue with Patron tests failing on jruby
|
174
|
+
* Fix an issue with new `rewind_files` feature that was causing an exception when the body was not an Hash
|
175
|
+
* Expose wrapped_exception in all client errors
|
176
|
+
* Add Authentication Section to the ReadMe
|
177
|
+
|
178
|
+
## v0.12.0.1
|
179
|
+
|
180
|
+
* Hotfix release to address an issue with TravisCI deploy on Rubygems
|
181
|
+
|
182
|
+
## v0.12.0
|
183
|
+
|
184
|
+
Features:
|
185
|
+
|
186
|
+
* Proxy feature now relies on Ruby `URI::Generic#find_proxy` and can use `no_proxy` ENV variable (not compatible with ruby < 2.0)
|
187
|
+
* Adds support for `context` request option to pass arbitrary information to middlewares
|
188
|
+
|
189
|
+
Fixes:
|
190
|
+
|
191
|
+
* Fix an issue with options that was causing new options to override defaults ones unexpectedly
|
192
|
+
* Rewind `UploadIO`s on retry to fix a compatibility issue
|
193
|
+
* Make multipart boundary unique
|
194
|
+
* Improvements in `README.md`
|
195
|
+
|
196
|
+
## v0.11.0
|
197
|
+
|
198
|
+
Features:
|
199
|
+
|
200
|
+
* Add `filter` method to Logger middleware
|
201
|
+
* Add support for Ruby2.4 and Minitest 6
|
202
|
+
* Introduce block syntax to customise the adapter
|
203
|
+
|
204
|
+
Fixes:
|
205
|
+
|
206
|
+
* Fix an issue that was allowing to override `default_connection_options` from a connection instance
|
207
|
+
* Fix a bug that was causing newline escape characters ("\n") to be used when building the Authorization header
|
208
|
+
|
209
|
+
## v0.10.1
|
210
|
+
|
211
|
+
- Fix an issue with HTTPClient adapter that was causing the SSL to be reset on every request
|
212
|
+
- Rescue `IOError` instead of specific subclass
|
213
|
+
- `Faraday::Utils::Headers` can now be successfully serialised in YAML
|
214
|
+
- Handle `default_connection_options` set with hash
|
215
|
+
|
216
|
+
## v0.10.0
|
217
|
+
|
218
|
+
Breaking changes:
|
219
|
+
- Drop support for Ruby 1.8
|
220
|
+
|
221
|
+
Features:
|
222
|
+
- Include wrapped exception/reponse in ClientErrors
|
223
|
+
- Add `response.reason_phrase`
|
224
|
+
- Provide option to selectively skip logging request/response headers
|
225
|
+
- Add regex support for pattern matching in `test` adapter
|
226
|
+
|
227
|
+
Fixes:
|
228
|
+
- Add `Faraday.respond_to?` to find methods managed by `method_missing`
|
229
|
+
- em-http: `request.host` instead of `connection.host` should be taken for SSL validations
|
230
|
+
- Allow `default_connection_options` to be merged when options are passed as url parameter
|
231
|
+
- Improve splitting key-value pairs in raw HTTP headers
|
232
|
+
|
233
|
+
## v0.9.2
|
234
|
+
|
235
|
+
Adapters:
|
236
|
+
- Enable gzip compression for httpclient
|
237
|
+
- Fixes default certificate store for httpclient not having default paths.
|
238
|
+
- Make excon adapter compatible with 0.44 excon version
|
239
|
+
- Add compatibility with Patron 0.4.20
|
240
|
+
- Determine default port numbers in Net::HTTP adapters (Addressable compatibility)
|
241
|
+
- em-http: wrap "connection closed by server" as ConnectionFailed type
|
242
|
+
- Wrap Errno::ETIMEDOUT in Faraday::Error::TimeoutError
|
243
|
+
|
244
|
+
Utils:
|
245
|
+
- Add Rack-compatible support for parsing `a[][b]=c` nested queries
|
246
|
+
- Encode nil values in queries different than empty strings. Before: `a=`; now: `a`.
|
247
|
+
- Have `Faraday::Utils::Headers#replace` clear internal key cache
|
248
|
+
- Dup the internal key cache when a Headers hash is copied
|
249
|
+
|
250
|
+
Env and middleware:
|
251
|
+
- Ensure `env` stored on middleware response has reference to the response
|
252
|
+
- Ensure that Response properties are initialized during `on_complete` (VCR compatibility)
|
253
|
+
- Copy request options in Faraday::Connection#dup
|
254
|
+
- Env custom members should be copied by Env.from(env)
|
255
|
+
- Honour per-request `request.options.params_encoder`
|
256
|
+
- Fix `interval_randomness` data type for Retry middleware
|
257
|
+
- Add maximum interval option for Retry middleware
|
258
|
+
|
259
|
+
## v0.9.1
|
260
|
+
|
261
|
+
* Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M)
|
262
|
+
* Add configurable methods that bypass `retry_if` in the Retry request middleware. (@mike-bourgeous)
|
263
|
+
|
264
|
+
## v0.9.0
|
265
|
+
|
266
|
+
* Add HTTPClient adapter (@hakanensari)
|
267
|
+
* Improve Retry handler (@mislav)
|
268
|
+
* Remove autoloading by default (@technoweenie)
|
269
|
+
* Improve internal docs (@technoweenie, @mislav)
|
270
|
+
* Respect user/password in http proxy string (@mislav)
|
271
|
+
* Adapter options are structs. Reinforces consistent options across adapters
|
272
|
+
(@technoweenie)
|
273
|
+
* Stop stripping trailing / off base URLs in a Faraday::Connection. (@technoweenie)
|
274
|
+
* Add a configurable URI parser. (@technoweenie)
|
275
|
+
* Remove need to manually autoload when using the authorization header helpers on `Faraday::Connection`. (@technoweenie)
|
276
|
+
* `Faraday::Adapter::Test` respects the `Faraday::RequestOptions#params_encoder` option. (@technoweenie)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# 
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/faraday)
|
4
|
-
|
4
|
+

|
5
5
|
[](https://codeclimate.com/github/lostisland/faraday/test_coverage)
|
6
6
|
[](https://codeclimate.com/github/lostisland/faraday/maintainability)
|
7
7
|
[](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
@@ -18,10 +18,10 @@ Need more details? See the [Faraday API Documentation][apidoc] to see how it wor
|
|
18
18
|
|
19
19
|
## Supported Ruby versions
|
20
20
|
|
21
|
-
This library aims to support and is [tested against][
|
21
|
+
This library aims to support and is [tested against][actions] the following Ruby
|
22
22
|
implementations:
|
23
23
|
|
24
|
-
* Ruby 2.
|
24
|
+
* Ruby 2.4+
|
25
25
|
|
26
26
|
If something doesn't work on one of these Ruby versions, it's a bug.
|
27
27
|
|
@@ -49,7 +49,7 @@ But before you start coding, please read our [Contributing Guide][contributing]
|
|
49
49
|
[faraday_team]: https://lostisland.github.io/faraday/team
|
50
50
|
[contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
|
51
51
|
[apidoc]: http://www.rubydoc.info/gems/faraday
|
52
|
-
[
|
52
|
+
[actions]: https://github.com/lostisland/faraday/actions
|
53
53
|
[jruby]: http://jruby.org/
|
54
54
|
[rubinius]: http://rubini.us/
|
55
55
|
[license]: LICENSE.md
|
data/Rakefile
ADDED
data/UPGRADING.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
## Faraday 1.0
|
2
|
+
|
3
|
+
### Errors
|
4
|
+
* Removes sub-class constants definition from `Faraday::Error`. A sub-class (e.g. `ClientError`) was previously accessible
|
5
|
+
either through the `Faraday` module (e.g. `Faraday::ClientError`) or through the `Faraday::Error` class (e.g. `Faraday::Error::ClientError`).
|
6
|
+
The latter is no longer available and the former should be used instead, so check your `rescue`s.
|
7
|
+
* Introduces a new `Faraday::ServerError` (5xx status codes) alongside the existing `Faraday::ClientError` (4xx status codes).
|
8
|
+
Please note `Faraday::ClientError` was previously used for both.
|
9
|
+
* Introduces new Errors that describe the most common REST status codes:
|
10
|
+
* Faraday::BadRequestError (400)
|
11
|
+
* Faraday::UnauthorizedError (401)
|
12
|
+
* Faraday::ForbiddenError (403)
|
13
|
+
* Faraday::ProxyAuthError (407). Please note this raised a `Faraday::ConnectionFailed` before.
|
14
|
+
* Faraday::ConflictError (409)
|
15
|
+
* Faraday::UnprocessableEntityError (422)
|
16
|
+
* The following error classes have changed the hierarchy to better mirror their real-world usage and semantic meaning:
|
17
|
+
* TimeoutError < ServerError (was < ClientError)
|
18
|
+
* ConnectionFailed < Error (was < ClientError)
|
19
|
+
* SSLError < Error (was < ClientError)
|
20
|
+
* ParsingError < Error (was < ClientError)
|
21
|
+
* RetriableResponse < Error (was < ClientError)
|
22
|
+
|
23
|
+
### Custom adapters
|
24
|
+
If you have written a custom adapter, please be aware that `env.body` is now an alias to the two new properties `request_body` and `response_body`.
|
25
|
+
This should work without you noticing if your adapter inherits from `Faraday::Adapter` and calls `save_response`, but if it doesn't, then please ensure you set the `status` BEFORE the `body` while processing the response.
|
26
|
+
|
27
|
+
### Others
|
28
|
+
* Dropped support for jruby and Rubinius.
|
29
|
+
* Officially supports Ruby 2.4+
|
30
|
+
* In order to specify the adapter you now MUST use the `#adapter` method on the connection builder. If you don't do so and your adapter inherits from `Faraday::Adapter` then Faraday will raise an exception. Otherwise, Faraday will automatically push the default adapter at the end of the stack causing your request to be executed twice.
|
31
|
+
```ruby
|
32
|
+
class OfficialAdapter < Faraday::Adapter
|
33
|
+
...
|
34
|
+
end
|
35
|
+
|
36
|
+
class MyAdapter
|
37
|
+
...
|
38
|
+
end
|
39
|
+
|
40
|
+
# This will raise an exception
|
41
|
+
conn = Faraday.new(...) do |f|
|
42
|
+
f.use OfficialAdapter
|
43
|
+
end
|
44
|
+
|
45
|
+
# This will cause Faraday inserting the default adapter at the end of the stack
|
46
|
+
conn = Faraday.new(...) do |f|
|
47
|
+
f.use MyAdapter
|
48
|
+
end
|
49
|
+
|
50
|
+
# You MUST use `adapter` method
|
51
|
+
conn = Faraday.new(...) do |f|
|
52
|
+
f.adapter AnyAdapter
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Requires Ruby with rspec and faraday gems.
|
4
|
+
# rspec client_spec.rb
|
5
|
+
|
6
|
+
require 'faraday'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
# Example API client
|
10
|
+
class Client
|
11
|
+
def initialize(conn)
|
12
|
+
@conn = conn
|
13
|
+
end
|
14
|
+
|
15
|
+
def sushi(jname)
|
16
|
+
res = @conn.get("/#{jname}")
|
17
|
+
data = JSON.parse(res.body)
|
18
|
+
data['name']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Rspec.describe Client do
|
23
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
24
|
+
let(:conn) { Faraday.new { |b| b.adapter(:test, stubs) } }
|
25
|
+
let(:client) { Client.new(conn) }
|
26
|
+
|
27
|
+
it 'parses name' do
|
28
|
+
stubs.get('/ebi') do |env|
|
29
|
+
# optional: you can inspect the Faraday::Env
|
30
|
+
expect(env.url.path).to eq('/ebi')
|
31
|
+
[
|
32
|
+
200,
|
33
|
+
{ 'Content-Type': 'application/javascript' },
|
34
|
+
'{"name": "shrimp"}'
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
# uncomment to trigger stubs.verify_stubbed_calls failure
|
39
|
+
# stubs.get('/unused') { [404, {}, ''] }
|
40
|
+
|
41
|
+
expect(client.sushi('ebi')).to eq('shrimp')
|
42
|
+
stubs.verify_stubbed_calls
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'handles 404' do
|
46
|
+
stubs.get('/ebi') do
|
47
|
+
[
|
48
|
+
404,
|
49
|
+
{ 'Content-Type': 'application/javascript' },
|
50
|
+
'{}'
|
51
|
+
]
|
52
|
+
end
|
53
|
+
expect(client.sushi('ebi')).to be_nil
|
54
|
+
stubs.verify_stubbed_calls
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'handles exception' do
|
58
|
+
stubs.get('/ebi') do
|
59
|
+
raise Faraday::ConnectionFailed, nil
|
60
|
+
end
|
61
|
+
|
62
|
+
expect { client.sushi('ebi') }.to raise_error(Faraday::ConnectionFailed)
|
63
|
+
stubs.verify_stubbed_calls
|
64
|
+
end
|
65
|
+
end
|