faraday-excon 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b78b8cf1e6b7dfecc1beb94c545a64be9c7c29f2dc71b88ddf52a954154f99d2
4
+ data.tar.gz: d6f22b96924c1221e19d62250a2250cdb3990f7da1d6bdfdd524ee7d969d5f9d
5
+ SHA512:
6
+ metadata.gz: 4db552b4e3b61fa66dd169405cb113f6b0de62f75f07b822c91b7152d01de96b761ba5528b9b8c9c09889c070d2e4788b31441216b75af1a188e67a7779915ec
7
+ data.tar.gz: 0a82f49683023ff4c9099820fe70fdb2f2c446dd2abcfeff30e180546ddc40eec6f39f1ea946cf94cae267a0cbc1d9ffdbe68c62f3147439a917da20a446958e
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jan van der Pas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Faraday Excon adapter
2
+
3
+ This gem is a [Faraday][faraday] adapter for the [Excon][excon] library.
4
+ Faraday is an HTTP client library that provides a common interface over many adapters.
5
+ Every adapter is defined into its own gem. This gem defines the adapter for Excon.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'faraday-excon'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install faraday-excon
22
+
23
+ ## Usage
24
+
25
+ Configure your Faraday connection to use this adapter like this:
26
+
27
+ ```ruby
28
+ connection = Faraday.new(url, conn_options) do |conn|
29
+ conn.adapter(:excon)
30
+ end
31
+ ```
32
+
33
+ For more information on how to setup your Faraday connection and adapters usage, please refer to the [Faraday Website][faraday-website].
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](rubygems).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on [GitHub][repo].
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [license][license].
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the Faraday Excon adapter project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
52
+
53
+ [faraday]: https://github.com/lostisland/faraday
54
+ [faraday-website]: https://lostisland.github.io/faraday
55
+ [excon]: https://github.com/excon/excon
56
+ [rubygems]: https://rubygems.org
57
+ [repo]: https://github.com/lostisland/faraday-excon
58
+ [license]: https://github.com/lostisland/faraday-excon/blob/main/LICENSE.md
59
+ [code-of-conduct]: https://github.com/lostisland/faraday-excon/blob/main/CODE_OF_CONDUCT.md
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ class Adapter
5
+ # Excon adapter.
6
+ class Excon < Faraday::Adapter
7
+ dependency 'excon'
8
+
9
+ def build_connection(env)
10
+ opts = opts_from_env(env)
11
+ ::Excon.new(env[:url].to_s, opts.merge(@connection_options))
12
+ end
13
+
14
+ def call(env)
15
+ super
16
+
17
+ req_opts = {
18
+ method: env[:method].to_s.upcase,
19
+ headers: env[:request_headers],
20
+ body: read_body(env)
21
+ }
22
+
23
+ req = env[:request]
24
+ if req&.stream_response?
25
+ total = 0
26
+ req_opts[:response_block] = lambda do |chunk, _remain, _total|
27
+ req.on_data.call(chunk, total += chunk.size)
28
+ end
29
+ end
30
+
31
+ resp = connection(env) { |http| http.request(req_opts) }
32
+ save_response(env, resp.status.to_i, resp.body, resp.headers,
33
+ resp.reason_phrase)
34
+
35
+ @app.call(env)
36
+ rescue ::Excon::Errors::SocketError => e
37
+ raise Faraday::TimeoutError, e if e.message.match?(/\btimeout\b/)
38
+
39
+ raise Faraday::SSLError, e if e.message.match?(/\bcertificate\b/)
40
+
41
+ raise Faraday::ConnectionFailed, e
42
+ rescue ::Excon::Errors::Timeout => e
43
+ raise Faraday::TimeoutError, e
44
+ end
45
+
46
+ # TODO: support streaming requests
47
+ def read_body(env)
48
+ env[:body].respond_to?(:read) ? env[:body].read : env[:body]
49
+ end
50
+
51
+ private
52
+
53
+ def opts_from_env(env)
54
+ opts = {}
55
+ amend_opts_with_ssl!(opts, env[:ssl]) if needs_ssl_settings?(env)
56
+
57
+ if (req = env[:request])
58
+ amend_opts_with_timeouts!(opts, req)
59
+ amend_opts_with_proxy_settings!(opts, req)
60
+ end
61
+
62
+ opts
63
+ end
64
+
65
+ def needs_ssl_settings?(env)
66
+ env[:url].scheme == 'https' && env[:ssl]
67
+ end
68
+
69
+ OPTS_KEYS = [
70
+ %i[client_cert client_cert],
71
+ %i[client_key client_key],
72
+ %i[certificate certificate],
73
+ %i[private_key private_key],
74
+ %i[ssl_ca_path ca_path],
75
+ %i[ssl_ca_file ca_file],
76
+ %i[ssl_version version],
77
+ %i[ssl_min_version min_version],
78
+ %i[ssl_max_version max_version]
79
+ ].freeze
80
+
81
+ def amend_opts_with_ssl!(opts, ssl)
82
+ opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
83
+ # https://github.com/geemus/excon/issues/106
84
+ # https://github.com/jruby/jruby-ossl/issues/19
85
+ opts[:nonblock] = false
86
+
87
+ OPTS_KEYS.each do |(key_in_opts, key_in_ssl)|
88
+ next unless ssl[key_in_ssl]
89
+
90
+ opts[key_in_opts] = ssl[key_in_ssl]
91
+ end
92
+ end
93
+
94
+ def amend_opts_with_timeouts!(opts, req)
95
+ if (sec = request_timeout(:read, req))
96
+ opts[:read_timeout] = sec
97
+ end
98
+
99
+ if (sec = request_timeout(:write, req))
100
+ opts[:write_timeout] = sec
101
+ end
102
+
103
+ return unless (sec = request_timeout(:open, req))
104
+
105
+ opts[:connect_timeout] = sec
106
+ end
107
+
108
+ def amend_opts_with_proxy_settings!(opts, req)
109
+ opts[:proxy] = proxy_settings_for_opts(req[:proxy]) if req[:proxy]
110
+ end
111
+
112
+ def proxy_settings_for_opts(proxy)
113
+ {
114
+ host: proxy[:uri].host,
115
+ hostname: proxy[:uri].hostname,
116
+ port: proxy[:uri].port,
117
+ scheme: proxy[:uri].scheme,
118
+ user: proxy[:user],
119
+ password: proxy[:password]
120
+ }
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'adapter/excon'
4
+ require_relative 'excon/version'
5
+
6
+ module Faraday
7
+ # Main Faraday::Excon module
8
+ module Excon
9
+ Faraday::Adapter.register_middleware(excon: Faraday::Adapter::Excon)
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Excon
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-excon
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mattia Giuffrida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.27.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.27.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.19.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.19.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: multipart-parser
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.91.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.91.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-packaging
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-performance
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
167
+ description: Faraday adapter for Excon
168
+ email:
169
+ - giuffrida.mattia@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - LICENSE.md
175
+ - README.md
176
+ - lib/faraday/adapter/excon.rb
177
+ - lib/faraday/excon.rb
178
+ - lib/faraday/excon/version.rb
179
+ homepage: https://github.com/lostisland/faraday-excon
180
+ licenses:
181
+ - MIT
182
+ metadata:
183
+ homepage_uri: https://github.com/lostisland/faraday-excon
184
+ source_code_uri: https://github.com/lostisland/faraday-excon
185
+ changelog_uri: https://github.com/lostisland/faraday-excon
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 2.4.0
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubygems_version: 3.1.4
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Faraday adapter for Excon
205
+ test_files: []