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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48aac22cbdca1645a7b8731a2c83e048cda0b4114c1141e96bf24d401e937832
4
- data.tar.gz: ad039e47c147b31723964127d3845f00b143dd42b8f8e89ada15a26836973ef3
3
+ metadata.gz: d82b2cbc73b9d64b7c61419c06b5aa58fd83f64a13db806e5a768c24cba61893
4
+ data.tar.gz: 2ce8e3958a2d315afd6a482be585c87a20486fa11092445012bf0e605925250b
5
5
  SHA512:
6
- metadata.gz: 0ffde084ecb995723b461aaa7b9db628f7a3b9de880bfcf84daf0a9a6ea06889f295ff4ccbf4af16af37a8db1fd1a881f2c38f2b74e7504a8bbc6c63a94c9869
7
- data.tar.gz: 0c23b6e7688e908cd3fe651cd0dc42fdfcfac54511faf1207373d446b3dc60d1fc8969e57d3fa9f5cf1413b1838039c20368991f8926b72dae0fe2b1c6706472
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
- .map { |v| ::EacEnvs::Http::Request::BodyFieldValue.new(v) }
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
- def body_data_or_raise
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.open(path, 'wb') { |fp| fp.write(performed.body) }
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
- 'body_data_from_' +
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\<(.+)\>\s*;\s*rel\s*=\s*\"(.*)\"\z/.to_parser do |m|
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(',').map { |w| LINK_PARSER.parse!(w.strip) }.to_h
22
+ v.split(',').to_h { |w| LINK_PARSER.parse!(w.strip) }
23
23
  end
24
24
  end
25
25
  end
@@ -6,7 +6,7 @@ module EacEnvs
6
6
  module Http
7
7
  class Response < ::StandardError
8
8
  module Statuses
9
- def raise_unless_200
9
+ def raise_unless_200 # rubocop:disable Naming/VariableNumber
10
10
  return nil if status >= 200 && status < 300
11
11
 
12
12
  raise self
@@ -25,11 +25,11 @@ module EacEnvs
25
25
  end
26
26
 
27
27
  def request_data
28
- REQUEST_TO_DATA.map { |k, v| [k, request.send(v)] }.to_h.merge(headers: request_headers)
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.map { |k, v| [k, v.first] }.to_h
32
+ request.header.transform_values(&:first)
33
33
  end
34
34
 
35
35
  def response_body
@@ -2,6 +2,6 @@
2
2
 
3
3
  module EacEnvs
4
4
  module Http
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
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.1
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-07-22 00:00:00.000000000 Z
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.119'
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.119'
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.10
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.10
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.5'
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.5'
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: '0'
171
+ version: '2.7'
198
172
  required_rubygems_version: !ruby/object:Gem::Requirement
199
173
  requirements:
200
174
  - - ">="