eac_envs-http 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_envs/http/request/body_field.rb +1 -1
- data/lib/eac_envs/http/request.rb +10 -0
- data/lib/eac_envs/http/response/body.rb +12 -4
- data/lib/eac_envs/http/response/links.rb +2 -2
- data/lib/eac_envs/http/response/statuses.rb +1 -1
- data/lib/eac_envs/http/rspec/echo_server/request_processor.rb +2 -2
- data/lib/eac_envs/http/version.rb +1 -1
- metadata +9 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d82b2cbc73b9d64b7c61419c06b5aa58fd83f64a13db806e5a768c24cba61893
|
4
|
+
data.tar.gz: 2ce8e3958a2d315afd6a482be585c87a20486fa11092445012bf0e605925250b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb5831315806a3829d2ea50eda1d5e8e7f230219387d5508f3bf7ffaab204da8f3cd5f86e8211cfee9bebe736e000c697bc42a3d858ad952fbd5d6a5869502a6
|
7
|
+
data.tar.gz: 0d484c4f46cb9780df1f3de777a369c7420574c1e3c0578804423bd08d796cc37d9d139084fefbc808227ecbbb854a0765a8522a9ebfef4139f8c6e2e9189198
|
@@ -28,7 +28,7 @@ module EacEnvs
|
|
28
28
|
common_constructor :key, :values do
|
29
29
|
self.key = key.to_s
|
30
30
|
self.values = (values.is_a?(::Array) ? values.to_a : [values])
|
31
|
-
|
31
|
+
.map { |v| ::EacEnvs::Http::Request::BodyFieldValue.new(v) }
|
32
32
|
end
|
33
33
|
|
34
34
|
# @return [String]
|
@@ -30,6 +30,7 @@ module EacEnvs
|
|
30
30
|
|
31
31
|
# @return [Faraday::Response]
|
32
32
|
def faraday_response
|
33
|
+
validate_url
|
33
34
|
conn = faraday_connection
|
34
35
|
conn.send(sanitized_verb, url) do |req|
|
35
36
|
req.headers = conn.headers.merge(headers)
|
@@ -52,6 +53,15 @@ module EacEnvs
|
|
52
53
|
body_fields.to_h || body_data
|
53
54
|
end
|
54
55
|
|
56
|
+
# @return [void]
|
57
|
+
def validate_url
|
58
|
+
raise 'URL is blank' if url.blank?
|
59
|
+
|
60
|
+
%w[scheme host].each do |attr|
|
61
|
+
raise "URL #{attr} is blank (URL: \"#{url}\")" if url.send(attr).blank?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
55
65
|
require_sub __FILE__, require_dependency: true
|
56
66
|
end
|
57
67
|
end
|
@@ -17,12 +17,21 @@ module EacEnvs
|
|
17
17
|
r
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
# @return [Object]
|
21
|
+
# @raise [EacEnvs::Http::Response]
|
22
|
+
def body_data!
|
21
23
|
raise_unless_200
|
22
24
|
|
23
25
|
body_data
|
24
26
|
end
|
25
27
|
|
28
|
+
# @deprecated Use {#body_data!} instead.
|
29
|
+
# @return [Object]
|
30
|
+
# @raise [EacEnvs::Http::Response]
|
31
|
+
def body_data_or_raise
|
32
|
+
body_data!
|
33
|
+
end
|
34
|
+
|
26
35
|
# @return [String]
|
27
36
|
def body_str
|
28
37
|
performed.body
|
@@ -36,7 +45,7 @@ module EacEnvs
|
|
36
45
|
|
37
46
|
# @param path [Pathname]
|
38
47
|
def write_body(path)
|
39
|
-
::File.
|
48
|
+
::File.binwrite(path, performed.body)
|
40
49
|
end
|
41
50
|
|
42
51
|
private
|
@@ -52,8 +61,7 @@ module EacEnvs
|
|
52
61
|
# @return [String]
|
53
62
|
def body_data_method_name
|
54
63
|
content_type.if_present do |v|
|
55
|
-
|
56
|
-
v.split(';').first.force_encoding(::Encoding::UTF_8).variableize
|
64
|
+
"body_data_from_#{v.split(';').first.force_encoding(::Encoding::UTF_8).variableize}"
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
@@ -9,7 +9,7 @@ module EacEnvs
|
|
9
9
|
LINKS_HEADER_NAME = 'Link'
|
10
10
|
|
11
11
|
# https://www.w3.org/wiki/LinkHeader
|
12
|
-
LINK_PARSER = /\A
|
12
|
+
LINK_PARSER = /\A<(.+)>\s*;\s*rel\s*=\s*"(.*)"\z/.to_parser do |m|
|
13
13
|
[m[2], m[1]]
|
14
14
|
end
|
15
15
|
|
@@ -19,7 +19,7 @@ module EacEnvs
|
|
19
19
|
|
20
20
|
def links
|
21
21
|
header(LINKS_HEADER_NAME).if_present({}) do |v|
|
22
|
-
v.split(',').
|
22
|
+
v.split(',').to_h { |w| LINK_PARSER.parse!(w.strip) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -25,11 +25,11 @@ module EacEnvs
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def request_data
|
28
|
-
REQUEST_TO_DATA.
|
28
|
+
REQUEST_TO_DATA.transform_values { |v| request.send(v) }.merge(headers: request_headers)
|
29
29
|
end
|
30
30
|
|
31
31
|
def request_headers
|
32
|
-
request.header.
|
32
|
+
request.header.transform_values(&:first)
|
33
33
|
end
|
34
34
|
|
35
35
|
def response_body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_envs-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Put here the authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_fs
|
@@ -30,20 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.119.1
|
33
|
+
version: '0.120'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0.
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.119.1
|
40
|
+
version: '0.120'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: faraday
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +47,7 @@ dependencies:
|
|
53
47
|
version: '2.7'
|
54
48
|
- - ">="
|
55
49
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2.7.
|
50
|
+
version: 2.7.12
|
57
51
|
type: :runtime
|
58
52
|
prerelease: false
|
59
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,7 +57,7 @@ dependencies:
|
|
63
57
|
version: '2.7'
|
64
58
|
- - ">="
|
65
59
|
- !ruby/object:Gem::Version
|
66
|
-
version: 2.7.
|
60
|
+
version: 2.7.12
|
67
61
|
- !ruby/object:Gem::Dependency
|
68
62
|
name: faraday-follow_redirects
|
69
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,40 +120,20 @@ dependencies:
|
|
126
120
|
- - "~>"
|
127
121
|
- !ruby/object:Gem::Version
|
128
122
|
version: '2.2'
|
129
|
-
- !ruby/object:Gem::Dependency
|
130
|
-
name: aranha-parsers
|
131
|
-
requirement: !ruby/object:Gem::Requirement
|
132
|
-
requirements:
|
133
|
-
- - "~>"
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version: '0.17'
|
136
|
-
type: :development
|
137
|
-
prerelease: false
|
138
|
-
version_requirements: !ruby/object:Gem::Requirement
|
139
|
-
requirements:
|
140
|
-
- - "~>"
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
version: '0.17'
|
143
123
|
- !ruby/object:Gem::Dependency
|
144
124
|
name: eac_ruby_gem_support
|
145
125
|
requirement: !ruby/object:Gem::Requirement
|
146
126
|
requirements:
|
147
127
|
- - "~>"
|
148
128
|
- !ruby/object:Gem::Version
|
149
|
-
version: '0.
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.5.1
|
129
|
+
version: '0.9'
|
153
130
|
type: :development
|
154
131
|
prerelease: false
|
155
132
|
version_requirements: !ruby/object:Gem::Requirement
|
156
133
|
requirements:
|
157
134
|
- - "~>"
|
158
135
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0.
|
160
|
-
- - ">="
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
version: 0.5.1
|
136
|
+
version: '0.9'
|
163
137
|
description:
|
164
138
|
email:
|
165
139
|
executables: []
|
@@ -194,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
168
|
requirements:
|
195
169
|
- - ">="
|
196
170
|
- !ruby/object:Gem::Version
|
197
|
-
version: '
|
171
|
+
version: '2.7'
|
198
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
173
|
requirements:
|
200
174
|
- - ">="
|