eac_tools 0.65.0 → 0.66.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +45 -39
- data/lib/eac_tools/version.rb +1 -1
- data/sub/aranha-parsers/aranha-parsers.gemspec +4 -4
- data/sub/aranha-parsers/lib/aranha/parsers/base.rb +10 -5
- data/sub/aranha-parsers/lib/aranha/parsers/html/base.rb +14 -0
- data/sub/aranha-parsers/lib/aranha/parsers/html/node/default/string_support.rb +6 -6
- data/sub/aranha-parsers/lib/aranha/parsers/html/node/default.rb +16 -2
- data/sub/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
- data/sub/avm/avm.gemspec +3 -3
- data/sub/avm/lib/avm/data/clearer.rb +18 -0
- data/sub/avm/lib/avm/data/package/clear.rb +23 -0
- data/sub/avm/lib/avm/data/package/dump.rb +0 -10
- data/sub/avm/lib/avm/data/package.rb +8 -1
- data/sub/avm/lib/avm/docker/runner.rb +0 -4
- data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -2
- data/sub/avm/lib/avm/instances/base.rb +10 -0
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +4 -3
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/launcher_stereotypes/base/publish.rb +8 -9
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
- data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +0 -10
- data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
- data/sub/avm-tools/avm-tools.gemspec +3 -3
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/clear.rb +18 -0
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/dump.rb +1 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit/clear.rb +1 -5
- data/sub/avm-tools/lib/avm/tools/runner/instance/data/unit.rb +5 -0
- data/sub/avm-tools/lib/avm/tools/runner/instance/data.rb +5 -0
- data/sub/avm-tools/lib/avm/tools/runner/launcher.rb +0 -1
- data/sub/avm-tools/lib/avm/tools/runner/launcher_stereotypes/list.rb +0 -1
- data/sub/avm-tools/lib/avm/tools/runner_with/instance_data_clear.rb +20 -0
- data/sub/avm-tools/lib/avm/tools/runner_with.rb +11 -0
- data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
- data/sub/eac_cli/eac_cli.gemspec +1 -1
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +9 -6
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +3 -3
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +10 -1
- data/sub/eac_envs-http/Gemfile +8 -0
- data/sub/eac_envs-http/eac_envs-http.gemspec +25 -0
- data/sub/eac_envs-http/lib/eac_envs/http/error.rb +8 -0
- data/sub/eac_envs-http/lib/eac_envs/http/request/body_field.rb +51 -0
- data/sub/eac_envs-http/lib/eac_envs/http/request/body_field_value.rb +32 -0
- data/sub/eac_envs-http/lib/eac_envs/http/request/body_fields.rb +39 -0
- data/sub/eac_envs-http/lib/eac_envs/http/request/faraday_connection.rb +75 -0
- data/sub/eac_envs-http/lib/eac_envs/http/request.rb +58 -0
- data/sub/eac_envs-http/lib/eac_envs/http/response/body.rb +57 -0
- data/sub/eac_envs-http/lib/eac_envs/http/response/headers.rb +41 -0
- data/sub/eac_envs-http/lib/eac_envs/http/response/links.rb +28 -0
- data/sub/eac_envs-http/lib/eac_envs/http/response/statuses.rb +21 -0
- data/sub/eac_envs-http/lib/eac_envs/http/response.rb +30 -0
- data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server/request_processor.rb +42 -0
- data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server/webrick_servlet.rb +22 -0
- data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server.rb +63 -0
- data/sub/eac_envs-http/lib/eac_envs/http/rspec.rb +11 -0
- data/sub/eac_envs-http/lib/eac_envs/http/version.rb +7 -0
- data/sub/{avm-tools/lib/avm/projects.rb → eac_envs-http/lib/eac_envs/http.rb} +2 -2
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request/body_fields_spec.rb +47 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec.rb +68 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get.source.yaml +5 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get.target.yaml +9 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get_with_auth.source.yaml +8 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get_with_auth.target.yaml +10 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_array_body.source.yaml +10 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_array_body.target.yaml +11 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_string_body.source.yaml +4 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_string_body.target.yaml +11 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_hash_body.source.yaml +6 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_hash_body.target.yaml +11 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_with_file.source.yaml +5 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_with_file.target.yaml +13 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/root.source.yaml +2 -0
- data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/root.target.yaml +9 -0
- data/sub/eac_envs-http/spec/rubocop_spec.rb +3 -0
- data/sub/eac_envs-http/spec/spec_helper/request_builder.rb +61 -0
- data/sub/eac_envs-http/spec/spec_helper.rb +7 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +14 -2
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- metadata +59 -12
- data/sub/avm-tools/lib/avm/projects/stereotypes.rb +0 -15
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_cli/runner'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module Tools
|
8
|
+
module RunnerWith
|
9
|
+
module InstanceDataClear
|
10
|
+
common_concern do
|
11
|
+
include ::EacCli::Runner
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
data_owner.clear
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/sub/eac_cli/eac_cli.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency 'colorize', '~> 0.8', '>= 0.8.1'
|
16
16
|
s.add_dependency 'eac_config', '~> 0.12'
|
17
|
-
s.add_dependency 'eac_ruby_utils', '~> 0.
|
17
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.116'
|
18
18
|
|
19
19
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
20
20
|
end
|
@@ -18,19 +18,22 @@ module EacCli
|
|
18
18
|
# Call a method in the runner or in one of it ancestors.
|
19
19
|
def call(method_name, *args)
|
20
20
|
return runner.send(method_name, *args) if runner.respond_to?(method_name)
|
21
|
-
return parent_call(method_name, *args) if
|
21
|
+
return parent_call(method_name, *args) if parent_respond_to?(method_name)
|
22
22
|
|
23
23
|
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
# @param method_name [Symbol]
|
27
|
+
# @return [Boolean]
|
28
|
+
def parent_respond_to?(method_name)
|
29
|
+
parent.if_present(false) do |v|
|
30
|
+
next true if v.respond_to?(method_name)
|
29
31
|
|
30
|
-
|
32
|
+
v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
|
33
|
+
end
|
34
|
+
end
|
31
35
|
|
32
36
|
def parent_call(method_name, *args)
|
33
|
-
return parent.context(method_name, *args) if parent.respond_to?(:context)
|
34
37
|
return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)
|
35
38
|
|
36
39
|
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
@@ -30,13 +30,13 @@ module EacCli
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def respond_to_missing?(method, include_all = false)
|
33
|
-
runner_context.
|
33
|
+
runner_context.parent_respond_to?(method) || super
|
34
34
|
end
|
35
35
|
|
36
36
|
def method_missing(method, *args, &block)
|
37
|
-
return super unless runner_context.
|
37
|
+
return super unless runner_context.parent_respond_to?(method)
|
38
38
|
|
39
|
-
runner_context.
|
39
|
+
runner_context.parent_call(method, *args, &block)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -19,6 +19,8 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
delegate :root_var, to: :parsed
|
22
|
+
|
23
|
+
def method_in_parent_runner; end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -31,7 +33,10 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
|
31
33
|
pos_arg :child_var
|
32
34
|
end
|
33
35
|
|
34
|
-
def run
|
36
|
+
def run
|
37
|
+
runner_context.call(:method_in_parent_runner)
|
38
|
+
method_in_parent_runner
|
39
|
+
end
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
@@ -45,6 +50,10 @@ RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
|
45
50
|
it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
|
46
51
|
it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
|
47
52
|
it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
|
53
|
+
|
54
|
+
it do
|
55
|
+
expect { instance.run_run }.not_to raise_error
|
56
|
+
end
|
48
57
|
end
|
49
58
|
|
50
59
|
context 'when subcommand is not supplied' do
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
require 'eac_envs/http/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'eac_envs-http'
|
9
|
+
s.version = EacEnvs::Http::VERSION
|
10
|
+
s.authors = ['Put here the authors']
|
11
|
+
s.summary = 'Put here de description.'
|
12
|
+
|
13
|
+
s.files = Dir['{lib}/**/*']
|
14
|
+
|
15
|
+
s.add_dependency 'eac_fs', '~> 0.16'
|
16
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.116'
|
17
|
+
s.add_dependency 'faraday', '~> 2.7', '>= 2.7.4'
|
18
|
+
s.add_dependency 'faraday-follow_redirects', '~> 0.3'
|
19
|
+
s.add_dependency 'faraday-gzip', '~> 0.1'
|
20
|
+
s.add_dependency 'faraday-multipart', '~> 1.0', '>= 1.0.4'
|
21
|
+
s.add_dependency 'faraday-retry', '~> 2.1'
|
22
|
+
|
23
|
+
s.add_development_dependency 'aranha-parsers', '~> 0.17'
|
24
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5', '>= 0.5.1'
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_envs/http/request/body_field_value'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'faraday/multipart/file_part'
|
6
|
+
|
7
|
+
module EacEnvs
|
8
|
+
module Http
|
9
|
+
class Request
|
10
|
+
class BodyField
|
11
|
+
class << self
|
12
|
+
# @return [Array<EacEnvs::Http::Request::BodyField>]
|
13
|
+
def list_from_enumerable(enum)
|
14
|
+
hash = {}
|
15
|
+
enum.each do |v|
|
16
|
+
hash[v[0]] ||= []
|
17
|
+
hash[v[0]] << v[1]
|
18
|
+
end
|
19
|
+
list_from_hash(hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Array<EacEnvs::Http::Request::BodyField>]
|
23
|
+
def list_from_hash(hash)
|
24
|
+
hash.map { |k, v| new(k, v) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
common_constructor :key, :values do
|
29
|
+
self.key = key.to_s
|
30
|
+
self.values = (values.is_a?(::Array) ? values.to_a : [values])
|
31
|
+
.map { |v| ::EacEnvs::Http::Request::BodyFieldValue.new(v) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
def hash_key
|
36
|
+
key
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array]
|
40
|
+
def hash_value
|
41
|
+
values.map(&:to_faraday)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean]
|
45
|
+
def with_file?
|
46
|
+
values.any?(&:file?)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_fs/file_info'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'faraday'
|
6
|
+
require 'faraday/multipart'
|
7
|
+
|
8
|
+
module EacEnvs
|
9
|
+
module Http
|
10
|
+
class Request
|
11
|
+
class BodyFieldValue
|
12
|
+
common_constructor :value
|
13
|
+
|
14
|
+
def to_faraday
|
15
|
+
return value unless file?
|
16
|
+
|
17
|
+
::Faraday::Multipart::FilePart.new(value, file_mime_type)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Boolean]
|
21
|
+
def file?
|
22
|
+
value.is_a?(::File)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def file_mime_type
|
27
|
+
::EacFs::FileInfo.new(value.path).mime_type
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_envs/http/request/body_field'
|
5
|
+
|
6
|
+
module EacEnvs
|
7
|
+
module Http
|
8
|
+
class Request
|
9
|
+
class BodyFields
|
10
|
+
common_constructor :source_body
|
11
|
+
|
12
|
+
# @return [Hash, nil]
|
13
|
+
def to_h
|
14
|
+
fields.if_present do |v|
|
15
|
+
v.each_with_object({}) { |e, a| a[e.hash_key] = e.hash_value }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array<EacEnvs::Http::Request::BodyField>, nil]
|
20
|
+
def fields
|
21
|
+
source_body.if_present do |v|
|
22
|
+
next nil unless v.is_a?(::Enumerable)
|
23
|
+
|
24
|
+
if v.is_a?(::Hash)
|
25
|
+
::EacEnvs::Http::Request::BodyField.list_from_hash(v)
|
26
|
+
else
|
27
|
+
::EacEnvs::Http::Request::BodyField.list_from_enumerable(v)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Boolean]
|
33
|
+
def with_file?
|
34
|
+
fields.if_present(false) { |v| v.any?(&:with_file?) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday/follow_redirects'
|
6
|
+
require 'faraday/gzip'
|
7
|
+
require 'faraday/multipart'
|
8
|
+
require 'faraday/retry'
|
9
|
+
|
10
|
+
module EacEnvs
|
11
|
+
module Http
|
12
|
+
class Request
|
13
|
+
class FaradayConnection
|
14
|
+
enable_method_class
|
15
|
+
common_constructor :request
|
16
|
+
|
17
|
+
SETUPS = %i[multipart authorization follow_redirect gzip retry].freeze
|
18
|
+
|
19
|
+
# @return [Faraday::Connection]
|
20
|
+
def result
|
21
|
+
::Faraday.default_connection_options[:headers] = {}
|
22
|
+
::Faraday::Connection.new(connection_options) do |conn|
|
23
|
+
SETUPS.each { |setup| send("setup_#{setup}", conn) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @return [Boolean]
|
30
|
+
def body_with_file?
|
31
|
+
request.body_fields.with_file?
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Hash]
|
35
|
+
def connection_options
|
36
|
+
{
|
37
|
+
request: { params_encoder: Faraday::FlatParamsEncoder },
|
38
|
+
ssl: { verify: request.ssl_verify? }
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param conn [Faraday::Connection]
|
43
|
+
def setup_authorization(conn)
|
44
|
+
request.auth.if_present do |v|
|
45
|
+
conn.request :authorization, :basic, v.username, v.password
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param conn [Faraday::Connection]
|
50
|
+
def setup_follow_redirect(conn)
|
51
|
+
conn.response :follow_redirects if request.follow_redirect?
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param conn [Faraday::Connection]
|
55
|
+
def setup_gzip(conn)
|
56
|
+
conn.request :gzip
|
57
|
+
end
|
58
|
+
|
59
|
+
# @param conn [Faraday::Connection]
|
60
|
+
def setup_multipart(conn)
|
61
|
+
if body_with_file?
|
62
|
+
conn.request :multipart, flat_encode: true
|
63
|
+
else
|
64
|
+
conn.request :url_encoded
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param conn [Faraday::Connection]
|
69
|
+
def setup_retry(conn)
|
70
|
+
conn.request :retry if request.retry?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_envs/http/response'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacEnvs
|
7
|
+
module Http
|
8
|
+
class Request
|
9
|
+
BOOLEAN_MODIFIERS = %w[follow_redirect retry ssl_verify].freeze
|
10
|
+
COMMON_MODIFIERS = %w[auth body_data response_body_data_proc url verb].freeze
|
11
|
+
HASH_MODIFIERS = %w[header].freeze
|
12
|
+
MODIFIERS = COMMON_MODIFIERS + BOOLEAN_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
|
13
|
+
|
14
|
+
enable_immutable
|
15
|
+
immutable_accessor(*BOOLEAN_MODIFIERS, type: :boolean)
|
16
|
+
immutable_accessor(*COMMON_MODIFIERS, type: :common)
|
17
|
+
immutable_accessor(*HASH_MODIFIERS, type: :hash)
|
18
|
+
|
19
|
+
enable_listable
|
20
|
+
lists.add_symbol :verb, :get, :delete, :options, :post, :put
|
21
|
+
|
22
|
+
def basic_auth(username, password)
|
23
|
+
auth(::Struct.new(:username, :password).new(username, password))
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [EacEnvs::Http::Request::BodyFields]
|
27
|
+
def body_fields
|
28
|
+
@body_fields ||= ::EacEnvs::Http::Request::BodyFields.new(body_data)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Faraday::Response]
|
32
|
+
def faraday_response
|
33
|
+
conn = faraday_connection
|
34
|
+
conn.send(sanitized_verb, url) do |req|
|
35
|
+
req.headers = conn.headers.merge(headers)
|
36
|
+
sanitized_body_data.if_present { |v| req.body = v }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def response
|
41
|
+
::EacEnvs::Http::Response.new(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Symbol]
|
45
|
+
def sanitized_verb
|
46
|
+
verb.if_present(VERB_GET) { |v| self.class.lists.verb.value_validate!(v) }
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def sanitized_body_data
|
52
|
+
body_fields.to_h || body_data
|
53
|
+
end
|
54
|
+
|
55
|
+
require_sub __FILE__, require_dependency: true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module EacEnvs
|
7
|
+
module Http
|
8
|
+
class Response < ::StandardError
|
9
|
+
module Body
|
10
|
+
delegate :response_body_data_proc, to: :request
|
11
|
+
|
12
|
+
def body_data
|
13
|
+
r = body_data_method_name.if_present(body_str) do |v|
|
14
|
+
respond_to?(v, true) ? send(v) : body_str
|
15
|
+
end
|
16
|
+
r = response_body_data_proc.call(r) if response_body_data_proc.present?
|
17
|
+
r
|
18
|
+
end
|
19
|
+
|
20
|
+
def body_data_or_raise
|
21
|
+
raise_unless_200
|
22
|
+
|
23
|
+
body_data
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String]
|
27
|
+
def body_str
|
28
|
+
performed.body
|
29
|
+
end
|
30
|
+
|
31
|
+
def body_str_or_raise
|
32
|
+
raise_unless_200
|
33
|
+
|
34
|
+
body_str
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def body_data_from_application_json
|
40
|
+
::JSON.parse(body_str)
|
41
|
+
end
|
42
|
+
|
43
|
+
def body_data_from_application_xml
|
44
|
+
Hash.from_xml(body_str)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [String]
|
48
|
+
def body_data_method_name
|
49
|
+
content_type.if_present do |v|
|
50
|
+
'body_data_from_' +
|
51
|
+
v.split(';').first.force_encoding(::Encoding::UTF_8).variableize
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacEnvs
|
6
|
+
module Http
|
7
|
+
class Response < ::StandardError
|
8
|
+
module Headers
|
9
|
+
COMMON_HEADERS = %w[Content-Type].freeze
|
10
|
+
HEADER_LINE_PARSER = /\A([^:]+):(.*)\z/.to_parser do |m|
|
11
|
+
[m[1].strip, m[2].strip]
|
12
|
+
end
|
13
|
+
|
14
|
+
def header(name)
|
15
|
+
hash_search(headers, name)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Hash<String, String>]
|
19
|
+
def headers
|
20
|
+
performed.headers.to_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
COMMON_HEADERS.each do |header_key|
|
24
|
+
define_method header_key.underscore do
|
25
|
+
header(header_key)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def hash_search(hash, key)
|
32
|
+
key = key.to_s.downcase
|
33
|
+
hash.each do |k, v|
|
34
|
+
return v if k.to_s.downcase == key
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
module EacEnvs
|
5
|
+
module Http
|
6
|
+
class Response < ::StandardError
|
7
|
+
module Links
|
8
|
+
# https://www.w3.org/wiki/LinkHeader
|
9
|
+
LINKS_HEADER_NAME = 'Link'
|
10
|
+
|
11
|
+
# https://www.w3.org/wiki/LinkHeader
|
12
|
+
LINK_PARSER = /\A\<(.+)\>\s*;\s*rel\s*=\s*\"(.*)\"\z/.to_parser do |m|
|
13
|
+
[m[2], m[1]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def link(rel)
|
17
|
+
hash_search(links, rel)
|
18
|
+
end
|
19
|
+
|
20
|
+
def links
|
21
|
+
header(LINKS_HEADER_NAME).if_present({}) do |v|
|
22
|
+
v.split(',').map { |w| LINK_PARSER.parse!(w.strip) }.to_h
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacEnvs
|
6
|
+
module Http
|
7
|
+
class Response < ::StandardError
|
8
|
+
module Statuses
|
9
|
+
def raise_unless_200
|
10
|
+
return nil if status == 200
|
11
|
+
|
12
|
+
raise self
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
performed.status.to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/conversions'
|
4
|
+
require 'eac_envs/http/error'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'faraday'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module EacEnvs
|
10
|
+
module Http
|
11
|
+
class Response < ::StandardError
|
12
|
+
common_constructor :request
|
13
|
+
delegate :url, to: :request
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"URL: #{url}\nStatus: #{status}\nBody:\n\n#{body_str}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def performed
|
22
|
+
@performed ||= request.faraday_response
|
23
|
+
rescue ::Faraday::Error
|
24
|
+
raise ::EacEnvs::Http::Error
|
25
|
+
end
|
26
|
+
|
27
|
+
require_sub __FILE__, include_modules: true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|