faraday 2.7.10 → 2.7.12

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: e4aa57af93476ba31117b14ed37bea950bf9b677d4dcca13ca1296a3ac2c3ff7
4
- data.tar.gz: 98b3cb7b7c5c08eba9f58ad96181757d6cd7fc7431ac47ae19e8c95a25de12f9
3
+ metadata.gz: 975b437b7cfe03559c0c2affea747fb2bc10c8439d1f05c8f901261ebf8ff956
4
+ data.tar.gz: aa20a42dc8dbd47d970e28000cbf693e39c80a3806d6b3f5348759858e7d4812
5
5
  SHA512:
6
- metadata.gz: 28f98f568e844799353a00d5ff49511f7bdb759a50edd3de2d4194fbb348dc14d1ef0294d854016ccdcbec915546225ebb2cf6dec354d6e7fbbf707b00cfc170
7
- data.tar.gz: 3506cebb9ad1fbd1dd38c1804e18cfd7d7352796d11fa564cde9ce0eee1b1a8ba6d07acda4b179662e5b6eb23baf6f70173240cf8a6b69834d2db9c740a80e25
6
+ metadata.gz: 31eaeb27af10b33774afbb9c83d46a2c310dd422602345c94d198737a1f1ff95692aa48235e47082177b15f540caaa4c3733bd739b17375da71f02851913e353
7
+ data.tar.gz: 6d610f6e22f77447b0eaef8ab5c5cd424e119a1db1f654affd1eb1dd9f6064ba53f837ba0e36130a2454826656f7113aba54af0c393ac9dae6f255468ae007ac
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [![Faraday](./docs/assets/img/repo-card-slim.png)][website]
1
+ # [![Faraday](./docs/_media/home-logo.svg)][website]
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
4
  [![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
@@ -6,14 +6,29 @@
6
6
 
7
7
  Faraday is an HTTP client library abstraction layer that provides a common interface over many
8
8
  adapters (such as Net::HTTP) and embraces the concept of Rack middleware when processing the request/response cycle.
9
- You probably don't want to use Faraday directly in your project, as it will lack an actual client library to perform
10
- requests. Instead, you probably want to have a look at [Awesome Faraday][awesome] for a list of available adapters.
9
+ Take a look at [Awesome Faraday][awesome] for a list of available adapters and middleware.
10
+
11
+ ## Why use Faraday?
12
+
13
+ Faraday gives you the power of Rack middleware for manipulating HTTP requests and responses,
14
+ making it easier to build sophisticated API clients or web service libraries that abstract away
15
+ the details of how HTTP requests are made.
16
+
17
+ Faraday comes with a lot of features out of the box, such as:
18
+ * Support for multiple adapters (Net::HTTP, Typhoeus, Patron, Excon, HTTPClient, and more)
19
+ * Persistent connections (keep-alive)
20
+ * Parallel requests
21
+ * Automatic response parsing (JSON, XML, YAML)
22
+ * Customization of the request/response cycle with middleware
23
+ * Support for streaming responses
24
+ * Support for uploading files
25
+ * And much more!
11
26
 
12
27
  ## Getting Started
13
28
 
14
29
  The best starting point is the [Faraday Website][website], with its introduction and explanation.
15
30
 
16
- Need more details? See the [Faraday API Documentation][apidoc] to see how it works internally, or take a look at [Advanced techniques for calling HTTP APIs in Ruby](https://mattbrictson.com/blog/advanced-http-techniques-in-ruby) blog post from @mattbrictson 🚀
31
+ Need more details? See the [Faraday API Documentation][apidoc] to see how it works internally, or take a look at [Advanced techniques for calling HTTP APIs in Ruby](https://mattbrictson.com/blog/advanced-http-techniques-in-ruby) blog post from [@mattbrictson](https://github.com/mattbrictson) 🚀
17
32
 
18
33
  ## Supported Ruby versions
19
34
 
@@ -43,14 +58,10 @@ But before you start coding, please read our [Contributing Guide][contributing]
43
58
 
44
59
  ## Copyright
45
60
 
46
- © 2009 - 2023, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
61
+ © 2009 - 2023, the Faraday Team. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
47
62
 
48
63
  [awesome]: https://github.com/lostisland/awesome-faraday/#adapters
49
64
  [website]: https://lostisland.github.io/faraday
50
- [faraday_team]: https://lostisland.github.io/faraday/team
51
- [contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
65
+ [contributing]: https://github.com/lostisland/faraday/blob/main/.github/CONTRIBUTING.md
52
66
  [apidoc]: https://www.rubydoc.info/github/lostisland/faraday
53
67
  [actions]: https://github.com/lostisland/faraday/actions
54
- [jruby]: http://jruby.org/
55
- [rubinius]: http://rubini.us/
56
- [license]: LICENSE.md
data/lib/faraday/error.rb CHANGED
@@ -124,6 +124,10 @@ module Faraday
124
124
  class UnprocessableEntityError < ClientError
125
125
  end
126
126
 
127
+ # Raised by Faraday::Response::RaiseError in case of a 429 response.
128
+ class TooManyRequestsError < ClientError
129
+ end
130
+
127
131
  # Faraday server error class. Represents 5xx status responses.
128
132
  class ServerError < Error
129
133
  end
@@ -30,6 +30,8 @@ module Faraday
30
30
  raise Faraday::ConflictError, response_values(env)
31
31
  when 422
32
32
  raise Faraday::UnprocessableEntityError, response_values(env)
33
+ when 429
34
+ raise Faraday::TooManyRequestsError, response_values(env)
33
35
  when ClientErrorStatuses
34
36
  raise Faraday::ClientError, response_values(env)
35
37
  when ServerErrorStatuses
@@ -39,11 +41,26 @@ module Faraday
39
41
  end
40
42
  end
41
43
 
44
+ # Returns a hash of response data with the following keys:
45
+ # - status
46
+ # - headers
47
+ # - body
48
+ # - request
49
+ #
50
+ # The `request` key is omitted when the middleware is explicitly
51
+ # configured with the option `include_request: false`.
42
52
  def response_values(env)
43
- {
53
+ response = {
44
54
  status: env.status,
45
55
  headers: env.response_headers,
46
- body: env.body,
56
+ body: env.body
57
+ }
58
+
59
+ # Include the request data by default. If the middleware was explicitly
60
+ # configured to _not_ include request data, then omit it.
61
+ return response unless options.fetch(:include_request, true)
62
+
63
+ response.merge(
47
64
  request: {
48
65
  method: env.method,
49
66
  url: env.url,
@@ -52,7 +69,7 @@ module Faraday
52
69
  headers: env.request_headers,
53
70
  body: env.request_body
54
71
  }
55
- }
72
+ )
56
73
  end
57
74
 
58
75
  def query_params(env)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.7.10'
4
+ VERSION = '2.7.12'
5
5
  end
@@ -14,6 +14,7 @@ RSpec.describe Faraday::Response::RaiseError do
14
14
  stub.get('request-timeout') { [408, { 'X-Reason' => 'because' }, 'keep looking'] }
15
15
  stub.get('conflict') { [409, { 'X-Reason' => 'because' }, 'keep looking'] }
16
16
  stub.get('unprocessable-entity') { [422, { 'X-Reason' => 'because' }, 'keep looking'] }
17
+ stub.get('too-many-requests') { [429, { 'X-Reason' => 'because' }, 'keep looking'] }
17
18
  stub.get('4xx') { [499, { 'X-Reason' => 'because' }, 'keep looking'] }
18
19
  stub.get('nil-status') { [nil, { 'X-Reason' => 'nil' }, 'fail'] }
19
20
  stub.get('server-error') { [500, { 'X-Error' => 'bailout' }, 'fail'] }
@@ -113,6 +114,17 @@ RSpec.describe Faraday::Response::RaiseError do
113
114
  end
114
115
  end
115
116
 
117
+ it 'raises Faraday::TooManyRequestsError for 429 responses' do
118
+ expect { conn.get('too-many-requests') }.to raise_error(Faraday::TooManyRequestsError) do |ex|
119
+ expect(ex.message).to eq('the server responded with status 429')
120
+ expect(ex.response[:headers]['X-Reason']).to eq('because')
121
+ expect(ex.response[:status]).to eq(429)
122
+ expect(ex.response_status).to eq(429)
123
+ expect(ex.response_body).to eq('keep looking')
124
+ expect(ex.response_headers['X-Reason']).to eq('because')
125
+ end
126
+ end
127
+
116
128
  it 'raises Faraday::NilStatusError for nil status in response' do
117
129
  expect { conn.get('nil-status') }.to raise_error(Faraday::NilStatusError) do |ex|
118
130
  expect(ex.message).to eq('http status could not be derived from the server response')
@@ -149,7 +161,7 @@ RSpec.describe Faraday::Response::RaiseError do
149
161
  describe 'request info' do
150
162
  let(:conn) do
151
163
  Faraday.new do |b|
152
- b.response :raise_error
164
+ b.response :raise_error, **middleware_options
153
165
  b.adapter :test do |stub|
154
166
  stub.post(url, request_body, request_headers) do
155
167
  [400, { 'X-Reason' => 'because' }, 'keep looking']
@@ -157,6 +169,7 @@ RSpec.describe Faraday::Response::RaiseError do
157
169
  end
158
170
  end
159
171
  end
172
+ let(:middleware_options) { {} }
160
173
  let(:request_body) { JSON.generate({ 'item' => 'sth' }) }
161
174
  let(:request_headers) { { 'Authorization' => 'Basic 123' } }
162
175
  let(:url_path) { 'request' }
@@ -180,5 +193,19 @@ RSpec.describe Faraday::Response::RaiseError do
180
193
  expect(ex.response[:request][:body]).to eq(request_body)
181
194
  end
182
195
  end
196
+
197
+ context 'when the include_request option is set to false' do
198
+ let(:middleware_options) { { include_request: false } }
199
+
200
+ it 'does not include request info in the exception' do
201
+ expect { perform_request }.to raise_error(Faraday::BadRequestError) do |ex|
202
+ expect(ex.response.keys).to contain_exactly(
203
+ :status,
204
+ :headers,
205
+ :body
206
+ )
207
+ end
208
+ end
209
+ end
183
210
  end
184
211
  end
data/spec/faraday_spec.rb CHANGED
@@ -18,10 +18,14 @@ RSpec.describe Faraday do
18
18
  end
19
19
 
20
20
  it 'uses method_missing on Faraday if there is no proxyable method' do
21
- expect { Faraday.this_method_does_not_exist }.to raise_error(
22
- NoMethodError,
23
- "undefined method `this_method_does_not_exist' for Faraday:Module"
24
- )
21
+ expected_message =
22
+ if RUBY_VERSION >= '3.3'
23
+ "undefined method `this_method_does_not_exist' for module Faraday"
24
+ else
25
+ "undefined method `this_method_does_not_exist' for Faraday:Module"
26
+ end
27
+
28
+ expect { Faraday.this_method_does_not_exist }.to raise_error(NoMethodError, expected_message)
25
29
  end
26
30
 
27
31
  it 'proxied methods can be accessed' do
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: 2.7.10
4
+ version: 2.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-07-06 00:00:00.000000000 Z
13
+ date: 2023-11-21 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: base64
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: faraday-net_http
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -131,7 +145,7 @@ licenses:
131
145
  - MIT
132
146
  metadata:
133
147
  homepage_uri: https://lostisland.github.io/faraday
134
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.10
148
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.12
135
149
  source_code_uri: https://github.com/lostisland/faraday
136
150
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
137
151
  post_install_message: