faraday 2.7.9 → 2.7.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83ff6180688a921d25648a542c61ed892a45073f0847c7596e3758c3e0840736
4
- data.tar.gz: 074e9f49f201d6ac82317775e5afcbacebdb1fa82314e31945fb2ca7f2382640
3
+ metadata.gz: 72fbb1db4fce28541cd53b5908e1fc18539ead8322d0b642069bd2e63d2a6543
4
+ data.tar.gz: a5e4f596d8f23e00f064c9789f85fa1cb194cac85168177750b76b3a3e9c7f4d
5
5
  SHA512:
6
- metadata.gz: a54d949779bac334681a0d860f6ada434bb48ff9497b2388fb75dd3e1686b9b4fe0fd203d79e7fb5c88dfa16a824c24feee29595914ed9ecdeff3119c4c1e7f3
7
- data.tar.gz: 70d759d4b358898746df53e29e9b2cb4d05466bc158f6d433e26fde3471123295a46c3f53da3214bfe992680e28db5cdd5c418c1a1fc3e05b45417bd09436036
6
+ metadata.gz: f880cdd4a42f22ac4eafeab1ddfcfb9e7a8ff0299956a279b207e4ed50d9b86fa09e44e74c4810b9ace3748db5edf6a9f62c73310d09ec1bbf73ec981356d921
7
+ data.tar.gz: 159e971ec7168017e0053511217a8b89314cd25aaf626a3a409db800218e39b172741a1264616c7b770a3ce45e9ee9a0bd5f9dc6fd43511cc4b9f8ae5fa8304a
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
@@ -13,25 +13,26 @@ module Faraday
13
13
 
14
14
  def initialize(logger:, options:)
15
15
  @logger = logger
16
- @filter = []
17
16
  @options = DEFAULT_OPTIONS.merge(options)
17
+ unless %i[debug info warn error fatal].include?(@options[:log_level])
18
+ @options[:log_level] = :info
19
+ end
20
+ @filter = []
18
21
  end
19
22
 
20
23
  def_delegators :@logger, :debug, :info, :warn, :error, :fatal
21
24
 
22
25
  def request(env)
23
- request_log = proc do
26
+ public_send(log_level, 'request') do
24
27
  "#{env.method.upcase} #{apply_filters(env.url.to_s)}"
25
28
  end
26
- public_send(log_level, 'request', &request_log)
27
29
 
28
30
  log_headers('request', env.request_headers) if log_headers?(:request)
29
31
  log_body('request', env[:body]) if env[:body] && log_body?(:request)
30
32
  end
31
33
 
32
34
  def response(env)
33
- status = proc { "Status #{env.status}" }
34
- public_send(log_level, 'response', &status)
35
+ public_send(log_level, 'response') { "Status #{env.status}" }
35
36
 
36
37
  log_headers('response', env.response_headers) if log_headers?(:response)
37
38
  log_body('response', env[:body]) if env[:body] && log_body?(:response)
@@ -40,8 +41,7 @@ module Faraday
40
41
  def exception(exc)
41
42
  return unless log_errors?
42
43
 
43
- error_log = proc { exc.full_message }
44
- public_send(log_level, 'error', &error_log)
44
+ public_send(log_level, 'error') { exc.full_message }
45
45
 
46
46
  log_headers('error', exc.response_headers) if exc.respond_to?(:response_headers) && log_headers?(:error)
47
47
  return unless exc.respond_to?(:response_body) && exc.response_body && log_body?(:error)
@@ -103,21 +103,15 @@ module Faraday
103
103
  end
104
104
 
105
105
  def log_level
106
- unless %i[debug info warn error fatal].include?(@options[:log_level])
107
- return :info
108
- end
109
-
110
106
  @options[:log_level]
111
107
  end
112
108
 
113
109
  def log_headers(type, headers)
114
- headers_log = proc { apply_filters(dump_headers(headers)) }
115
- public_send(log_level, type, &headers_log)
110
+ public_send(log_level, type) { apply_filters(dump_headers(headers)) }
116
111
  end
117
112
 
118
113
  def log_body(type, body)
119
- body_log = proc { apply_filters(dump_body(body)) }
120
- public_send(log_level, type, &body_log)
114
+ public_send(log_level, type) { apply_filters(dump_body(body)) }
121
115
  end
122
116
  end
123
117
  end
@@ -39,11 +39,26 @@ module Faraday
39
39
  end
40
40
  end
41
41
 
42
+ # Returns a hash of response data with the following keys:
43
+ # - status
44
+ # - headers
45
+ # - body
46
+ # - request
47
+ #
48
+ # The `request` key is omitted when the middleware is explicitly
49
+ # configured with the option `include_request: false`.
42
50
  def response_values(env)
43
- {
51
+ response = {
44
52
  status: env.status,
45
53
  headers: env.response_headers,
46
- body: env.body,
54
+ body: env.body
55
+ }
56
+
57
+ # Include the request data by default. If the middleware was explicitly
58
+ # configured to _not_ include request data, then omit it.
59
+ return response unless options.fetch(:include_request, true)
60
+
61
+ response.merge(
47
62
  request: {
48
63
  method: env.method,
49
64
  url: env.url,
@@ -52,7 +67,7 @@ module Faraday
52
67
  headers: env.request_headers,
53
68
  body: env.request_body
54
69
  }
55
- }
70
+ )
56
71
  end
57
72
 
58
73
  def query_params(env)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.7.9'
4
+ VERSION = '2.7.11'
5
5
  end
@@ -149,7 +149,7 @@ RSpec.describe Faraday::Response::RaiseError do
149
149
  describe 'request info' do
150
150
  let(:conn) do
151
151
  Faraday.new do |b|
152
- b.response :raise_error
152
+ b.response :raise_error, **middleware_options
153
153
  b.adapter :test do |stub|
154
154
  stub.post(url, request_body, request_headers) do
155
155
  [400, { 'X-Reason' => 'because' }, 'keep looking']
@@ -157,6 +157,7 @@ RSpec.describe Faraday::Response::RaiseError do
157
157
  end
158
158
  end
159
159
  end
160
+ let(:middleware_options) { {} }
160
161
  let(:request_body) { JSON.generate({ 'item' => 'sth' }) }
161
162
  let(:request_headers) { { 'Authorization' => 'Basic 123' } }
162
163
  let(:url_path) { 'request' }
@@ -180,5 +181,19 @@ RSpec.describe Faraday::Response::RaiseError do
180
181
  expect(ex.response[:request][:body]).to eq(request_body)
181
182
  end
182
183
  end
184
+
185
+ context 'when the include_request option is set to false' do
186
+ let(:middleware_options) { { include_request: false } }
187
+
188
+ it 'does not include request info in the exception' do
189
+ expect { perform_request }.to raise_error(Faraday::BadRequestError) do |ex|
190
+ expect(ex.response.keys).to contain_exactly(
191
+ :status,
192
+ :headers,
193
+ :body
194
+ )
195
+ end
196
+ end
197
+ end
183
198
  end
184
199
  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.9
4
+ version: 2.7.11
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-06-30 00:00:00.000000000 Z
13
+ date: 2023-09-12 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.9
148
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.11
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: