faraday-rack 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 +7 -0
- data/LICENSE.md +21 -0
- data/README.md +61 -0
- data/lib/faraday/adapter/rack.rb +75 -0
- data/lib/faraday/rack.rb +11 -0
- data/lib/faraday/rack/version.rb +7 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 143c8c75985d0d0f17bad4fe469bc4ff4df31c789fd09301e8509ecb2cab5ef8
|
4
|
+
data.tar.gz: a4809a9f6ed7c030568d0afc19db711639a91b4316b0816200749705e4e35ffa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c7fc77cff012d78684038c16e5dc0a8873d06bb07d0f5dc26d03823bbc97b1046021a4ca63dc8f9872396cf64cce3a0f7604d6d9f34bcf260920a662d4cc9e1
|
7
|
+
data.tar.gz: 62bda4f576d8dd9ccd9a6431f624ffe75e1a0589154ef80067526122f5b31135c65b4be45f6304c3b730c705388ab89bafc3fb150f679d191d3ddb2fe054125d
|
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,61 @@
|
|
1
|
+
# Faraday Rack adapter
|
2
|
+
|
3
|
+
This gem is a [Faraday][faraday] adapter for a [Rack][rack] app.
|
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 a Rack app.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add these lines to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rack'
|
13
|
+
gem 'faraday'
|
14
|
+
gem 'faraday-rack'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install them yourself as:
|
22
|
+
|
23
|
+
$ gem install rack faraday faraday-rack
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Configure your Faraday connection to use this adapter like this:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
connection = Faraday.new(url, conn_options) do |conn|
|
31
|
+
conn.adapter(:rack)
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
For more information on how to setup your Faraday connection and adapters usage, please refer to the [Faraday Website][faraday-website].
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
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.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on [GitHub][repo].
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [license][license].
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the Faraday Rack adapter project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
|
54
|
+
|
55
|
+
[faraday]: https://github.com/lostisland/faraday
|
56
|
+
[faraday-website]: https://lostisland.github.io/faraday
|
57
|
+
[rack]: https://github.com/rack/rack
|
58
|
+
[rubygems]: https://rubygems.org
|
59
|
+
[repo]: https://github.com/lostisland/faraday-rack
|
60
|
+
[license]: https://github.com/lostisland/faraday-rack/blob/main/LICENSE.md
|
61
|
+
[code-of-conduct]: https://github.com/lostisland/faraday-rack/blob/main/CODE_OF_CONDUCT.md
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Adapter
|
5
|
+
# Sends requests to a Rack app.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
#
|
9
|
+
# class MyRackApp
|
10
|
+
# def call(env)
|
11
|
+
# [200, {'Content-Type' => 'text/html'}, ["hello world"]]
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Faraday.new do |conn|
|
16
|
+
# conn.adapter :rack, MyRackApp.new
|
17
|
+
# end
|
18
|
+
class Rack < Faraday::Adapter
|
19
|
+
dependency 'rack/test'
|
20
|
+
|
21
|
+
# not prefixed with "HTTP_"
|
22
|
+
SPECIAL_HEADERS = %w[CONTENT_LENGTH CONTENT_TYPE].freeze
|
23
|
+
|
24
|
+
def initialize(faraday_app, rack_app)
|
25
|
+
super(faraday_app)
|
26
|
+
mock_session = ::Rack::MockSession.new(rack_app)
|
27
|
+
@session = ::Rack::Test::Session.new(mock_session)
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
super
|
32
|
+
rack_env = build_rack_env(env)
|
33
|
+
|
34
|
+
env[:request_headers]&.each do |name, value|
|
35
|
+
name = name.upcase.tr('-', '_')
|
36
|
+
name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name
|
37
|
+
rack_env[name] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
timeout = request_timeout(:open, env[:request])
|
41
|
+
timeout ||= request_timeout(:read, env[:request])
|
42
|
+
response = if timeout
|
43
|
+
Timer.timeout(timeout, Faraday::TimeoutError) do
|
44
|
+
execute_request(env, rack_env)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
execute_request(env, rack_env)
|
48
|
+
end
|
49
|
+
|
50
|
+
if (req = env[:request]).stream_response?
|
51
|
+
warn "Streaming downloads for #{self.class.name} " \
|
52
|
+
'are not yet implemented.'
|
53
|
+
req.on_data.call(response.body, response.body.bytesize)
|
54
|
+
end
|
55
|
+
|
56
|
+
save_response(env, response.status, response.body, response.headers)
|
57
|
+
@app.call env
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def execute_request(env, rack_env)
|
63
|
+
@session.request(env[:url].to_s, rack_env)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_rack_env(env)
|
67
|
+
{
|
68
|
+
method: env[:method],
|
69
|
+
input: env[:body].respond_to?(:read) ? env[:body].read : env[:body],
|
70
|
+
'rack.url_scheme' => env[:url].scheme
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/faraday/rack.rb
ADDED
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "@iMacTia"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-test
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.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: 1.12.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.12.0
|
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 Rack
|
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/rack.rb
|
177
|
+
- lib/faraday/rack.rb
|
178
|
+
- lib/faraday/rack/version.rb
|
179
|
+
homepage: https://github.com/lostisland/faraday-rack
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata:
|
183
|
+
homepage_uri: https://github.com/lostisland/faraday-rack
|
184
|
+
source_code_uri: https://github.com/lostisland/faraday-rack
|
185
|
+
changelog_uri: https://github.com/lostisland/faraday-rack
|
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.6
|
202
|
+
signing_key:
|
203
|
+
specification_version: 4
|
204
|
+
summary: Faraday adapter for Rack
|
205
|
+
test_files: []
|