eac_tools 0.65.0 → 0.65.1

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +28 -22
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/aranha-parsers/aranha-parsers.gemspec +4 -4
  5. data/sub/aranha-parsers/lib/aranha/parsers/base.rb +10 -5
  6. data/sub/aranha-parsers/lib/aranha/parsers/html/base.rb +14 -0
  7. data/sub/aranha-parsers/lib/aranha/parsers/html/node/default/string_support.rb +6 -6
  8. data/sub/aranha-parsers/lib/aranha/parsers/html/node/default.rb +16 -2
  9. data/sub/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
  10. data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +4 -3
  11. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/launcher_stereotypes/base/publish.rb +8 -9
  12. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  13. data/sub/eac_envs-http/Gemfile +8 -0
  14. data/sub/eac_envs-http/eac_envs-http.gemspec +25 -0
  15. data/sub/eac_envs-http/lib/eac_envs/http/error.rb +8 -0
  16. data/sub/eac_envs-http/lib/eac_envs/http/request/body_field.rb +51 -0
  17. data/sub/eac_envs-http/lib/eac_envs/http/request/body_field_value.rb +32 -0
  18. data/sub/eac_envs-http/lib/eac_envs/http/request/body_fields.rb +39 -0
  19. data/sub/eac_envs-http/lib/eac_envs/http/request/faraday_connection.rb +75 -0
  20. data/sub/eac_envs-http/lib/eac_envs/http/request.rb +58 -0
  21. data/sub/eac_envs-http/lib/eac_envs/http/response/body.rb +57 -0
  22. data/sub/eac_envs-http/lib/eac_envs/http/response/headers.rb +41 -0
  23. data/sub/eac_envs-http/lib/eac_envs/http/response/links.rb +28 -0
  24. data/sub/eac_envs-http/lib/eac_envs/http/response/statuses.rb +21 -0
  25. data/sub/eac_envs-http/lib/eac_envs/http/response.rb +30 -0
  26. data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server/request_processor.rb +42 -0
  27. data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server/webrick_servlet.rb +22 -0
  28. data/sub/eac_envs-http/lib/eac_envs/http/rspec/echo_server.rb +63 -0
  29. data/sub/eac_envs-http/lib/eac_envs/http/rspec.rb +11 -0
  30. data/sub/eac_envs-http/lib/eac_envs/http/version.rb +7 -0
  31. data/sub/eac_envs-http/lib/eac_envs/http.rb +9 -0
  32. data/sub/eac_envs-http/spec/lib/eac_envs/http/request/body_fields_spec.rb +47 -0
  33. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec.rb +68 -0
  34. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get.source.yaml +5 -0
  35. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get.target.yaml +9 -0
  36. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get_with_auth.source.yaml +8 -0
  37. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/get_with_auth.target.yaml +10 -0
  38. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_array_body.source.yaml +10 -0
  39. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_array_body.target.yaml +11 -0
  40. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_string_body.source.yaml +4 -0
  41. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/post_string_body.target.yaml +11 -0
  42. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_hash_body.source.yaml +6 -0
  43. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_hash_body.target.yaml +11 -0
  44. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_with_file.source.yaml +5 -0
  45. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/put_with_file.target.yaml +13 -0
  46. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/root.source.yaml +2 -0
  47. data/sub/eac_envs-http/spec/lib/eac_envs/http/request_spec_files/root.target.yaml +9 -0
  48. data/sub/eac_envs-http/spec/rubocop_spec.rb +3 -0
  49. data/sub/eac_envs-http/spec/spec_helper/request_builder.rb +61 -0
  50. data/sub/eac_envs-http/spec/spec_helper.rb +7 -0
  51. data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +14 -2
  52. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  53. metadata +44 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47a797b3de79a663eae4d7dc4c3cdc600756b13f53386dbcd88fb4732b195eeb
4
- data.tar.gz: 263a4b784e9cb99e1a9c023efdd2f048d4b83dfb73247300f6fe92db97c76dd7
3
+ metadata.gz: 8723a175022efba79f604084a0180cbeaf95a4f2505c3eeb40c5bb6e305f3a24
4
+ data.tar.gz: 64b727ef144842f33fb362a51677c595ec12b9703ec68b7ddc686c93f4429f65
5
5
  SHA512:
6
- metadata.gz: ad1076587dc04620251e5a391e0c169467aaaae2db7c725589322abad1f84c2c14e53056f07db414549e80864b3775e18105d1c3a25a7e2db2fb6c3adcaa97c8
7
- data.tar.gz: f38150d6c56ceb13ff86d8c921fa6867a3cb65e4f36050f2fcf790558832f0b4d1641f7fefdc125a276b1cab512538668b8d30396ff5c0bf50cfc5cb0c43c3bc
6
+ metadata.gz: 5a546f59fb7e0e70180a13ec0cf47a8901b413e017ca5c3118dd6e4485e11dd10d88d1b8e0b49070a1c55972ad51e9ae0b53d8e0d46ea354072e75adbb05d19b
7
+ data.tar.gz: 185f2fe7167b8f6b338cae914d2763758bd41e9f3aa7b79bcd56131beaab4e96f83dfcf6a2a512ec69afca44063cb58004a4814eeca6c16da19be24c5cff579a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.65.0)
4
+ eac_tools (0.65.1)
5
5
  avm (~> 0.71)
6
6
  avm-eac_asciidoctor_base0 (~> 0.19)
7
7
  avm-eac_generic_base0 (~> 0.12)
@@ -13,22 +13,22 @@ PATH
13
13
  avm-eac_rails_base1 (~> 0.8, >= 0.8.4)
14
14
  avm-eac_redmine_base0 (~> 0.20, >= 0.20.1)
15
15
  avm-eac_redmine_plugin_base0 (~> 0.4)
16
- avm-eac_ruby_base1 (~> 0.30, >= 0.30.2)
16
+ avm-eac_ruby_base1 (~> 0.30, >= 0.30.3)
17
17
  avm-eac_webapp_base0 (~> 0.17)
18
18
  avm-eac_wordpress_base0 (~> 0.3, >= 0.3.1)
19
19
  avm-git (~> 0.13, >= 0.13.2)
20
20
  avm-tools (~> 0.147)
21
- eac_ruby_utils (~> 0.115)
21
+ eac_ruby_utils (~> 0.116)
22
22
 
23
23
  PATH
24
24
  remote: sub/aranha-parsers
25
25
  specs:
26
- aranha-parsers (0.17.1)
26
+ aranha-parsers (0.18.0)
27
27
  activesupport (>= 4.0.0)
28
- addressable (~> 2.8, >= 2.8.3)
29
- eac_envs-http (~> 0.3)
30
- eac_ruby_utils (~> 0.112)
31
- nokogiri (~> 1.14, >= 1.14.2)
28
+ addressable (~> 2.8, >= 2.8.4)
29
+ eac_envs-http (~> 0.3, >= 0.3.1)
30
+ eac_ruby_utils (~> 0.116)
31
+ nokogiri (~> 1.14, >= 1.14.4)
32
32
  ofx-parser (~> 1.1)
33
33
 
34
34
  PATH
@@ -117,11 +117,12 @@ PATH
117
117
  PATH
118
118
  remote: sub/avm-eac_ruby_base1
119
119
  specs:
120
- avm-eac_ruby_base1 (0.30.2)
121
- aranha-parsers (~> 0.17, >= 0.17.1)
122
- avm (~> 0.67, >= 0.67.1)
120
+ avm-eac_ruby_base1 (0.30.3)
121
+ aranha-parsers (~> 0.18)
122
+ avm (~> 0.71)
123
123
  avm-eac_generic_base0 (~> 0.12)
124
- eac_ruby_utils (~> 0.112)
124
+ eac_envs-http (~> 0.3, >= 0.3.2)
125
+ eac_ruby_utils (~> 0.116)
125
126
 
126
127
  PATH
127
128
  remote: sub/avm-eac_ubuntu_base0
@@ -226,6 +227,18 @@ PATH
226
227
  eac_ruby_utils (~> 0.112)
227
228
  eac_templates (~> 0.3, >= 0.3.2)
228
229
 
230
+ PATH
231
+ remote: sub/eac_envs-http
232
+ specs:
233
+ eac_envs-http (0.3.2)
234
+ eac_fs (~> 0.16)
235
+ eac_ruby_utils (~> 0.116)
236
+ faraday (~> 2.7, >= 2.7.4)
237
+ faraday-follow_redirects (~> 0.3)
238
+ faraday-gzip (~> 0.1)
239
+ faraday-multipart (~> 1.0, >= 1.0.4)
240
+ faraday-retry (~> 2.1)
241
+
229
242
  PATH
230
243
  remote: sub/eac_fs
231
244
  specs:
@@ -261,7 +274,7 @@ PATH
261
274
  PATH
262
275
  remote: sub/eac_ruby_utils
263
276
  specs:
264
- eac_ruby_utils (0.115.0)
277
+ eac_ruby_utils (0.116.0)
265
278
  activesupport (>= 4, < 7)
266
279
  addressable (~> 2.8, >= 2.8.4)
267
280
  bundler
@@ -295,14 +308,6 @@ GEM
295
308
  parslet (~> 2.0)
296
309
  curb (0.9.11)
297
310
  diff-lcs (1.5.0)
298
- eac_envs-http (0.3.1)
299
- eac_fs (~> 0.16)
300
- eac_ruby_utils (~> 0.112)
301
- faraday (~> 2.7, >= 2.7.4)
302
- faraday-follow_redirects (~> 0.3)
303
- faraday-gzip (~> 0.1)
304
- faraday-multipart (~> 1.0, >= 1.0.4)
305
- faraday-retry (~> 2.1)
306
311
  eac_ruby_gem_support (0.5.1)
307
312
  eac_ruby_utils (~> 0.74)
308
313
  rspec (~> 3.9)
@@ -335,7 +340,7 @@ GEM
335
340
  minitest (5.18.0)
336
341
  multipart-post (2.3.0)
337
342
  net-ssh (4.2.0)
338
- nokogiri (1.14.4-x86_64-linux)
343
+ nokogiri (1.15.0-x86_64-linux)
339
344
  racc (~> 1.4)
340
345
  ofx-parser (1.1.0)
341
346
  hpricot (>= 0.6)
@@ -413,6 +418,7 @@ DEPENDENCIES
413
418
  eac_cli!
414
419
  eac_config!
415
420
  eac_docker!
421
+ eac_envs-http!
416
422
  eac_fs!
417
423
  eac_git!
418
424
  eac_rest!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.65.0'
4
+ VERSION = '0.65.1'
5
5
  end
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
15
  s.add_dependency 'activesupport', '>= 4.0.0'
16
- s.add_dependency 'addressable', '~> 2.8', '>= 2.8.3'
17
- s.add_dependency 'eac_envs-http', '~> 0.3'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.112'
19
- s.add_dependency 'nokogiri', '~> 1.14', '>= 1.14.2'
16
+ s.add_dependency 'addressable', '~> 2.8', '>= 2.8.4'
17
+ s.add_dependency 'eac_envs-http', '~> 0.3', '>= 0.3.1'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.116'
19
+ s.add_dependency 'nokogiri', '~> 1.14', '>= 1.14.4'
20
20
  s.add_dependency 'ofx-parser', '~> 1.1'
21
21
 
22
22
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
@@ -9,20 +9,25 @@ module Aranha
9
9
  module Parsers
10
10
  class Base
11
11
  class << self
12
+ # @deprecated Use {#from_string} instead.
13
+ # @param content [String]
14
+ # @return [Aranha::Parsers::Base]
12
15
  def from_content(content)
16
+ from_string(content)
17
+ end
18
+
19
+ # @param string [String]
20
+ # @return [Aranha::Parsers::Base]
21
+ def from_string(string)
13
22
  ::EacRubyUtils::Fs::Temp.on_file do |path|
14
23
  ::File.open(path.to_s, 'w:UTF-8') do |f|
15
- f.write content.dup.force_encoding('UTF-8')
24
+ f.write string.dup.force_encoding('UTF-8')
16
25
  end
17
26
  r = new(path.to_path)
18
27
  r.content
19
28
  r
20
29
  end
21
30
  end
22
-
23
- def parse_content(content)
24
- from_content(content).data
25
- end
26
31
  end
27
32
 
28
33
  LOG_DIR_ENVVAR = 'ARANHA_PARSERS_LOG_DIR'
@@ -19,6 +19,20 @@ module Aranha
19
19
  @fields << Field.new(name, type, xpath)
20
20
  end
21
21
 
22
+ # @param node [Nokogiri::XML::Node]
23
+ # @return [Aranha::Parsers::Html::Base]
24
+ def from_node(node)
25
+ from_string(node.to_html)
26
+ end
27
+
28
+ # @param haystack [String]
29
+ # @param needle [String]
30
+ # @return [String]
31
+ def xpath_ends_with(haystack, needle)
32
+ "substring(#{haystack}, string-length(#{haystack}) - string-length(#{needle}) + 1) " \
33
+ "= #{needle}"
34
+ end
35
+
22
36
  Field = Struct.new(:name, :type, :xpath)
23
37
  end
24
38
 
@@ -27,16 +27,16 @@ module Aranha
27
27
  raise "Pattern \"#{pattern}\" not found in string \"#{s}\""
28
28
  end
29
29
 
30
+ # @param node [Nokogiri::XML::Node]
31
+ # @param xpath [String]
32
+ # @return [String]
30
33
  def string_value(node, xpath)
31
- if node.at_xpath(xpath)
32
- sanitize_string(node.at_xpath(xpath).text)
33
- else
34
- ''
35
- end
34
+ found = node_value(node, xpath)
35
+ found ? sanitize_string(found.text) : ''
36
36
  end
37
37
 
38
38
  def string_recursive_value(node, xpath, required = true)
39
- root = node.at_xpath(xpath)
39
+ root = node_value(node, xpath)
40
40
  if root.blank?
41
41
  return nil unless required
42
42
 
@@ -11,13 +11,13 @@ module Aranha
11
11
  require_sub __FILE__, include_modules: true
12
12
 
13
13
  def array_value(node, xpath)
14
- r = node.xpath(xpath).map { |n| n.text.strip }
14
+ r = node_set_value(node, xpath).map { |n| n.text.strip }
15
15
  r.join('|')
16
16
  end
17
17
 
18
18
  def join_value(node, xpath)
19
19
  m = ''
20
- node.xpath(xpath).each do |n|
20
+ node_set_value(node, xpath).each do |n|
21
21
  m << n.text.strip
22
22
  end
23
23
  m
@@ -27,6 +27,20 @@ module Aranha
27
27
  m = /(\d+) m/.match(join_value(node, xpath))
28
28
  m ? m[1].to_i : nil
29
29
  end
30
+
31
+ # @param node [Nokogiri::XML::Node]
32
+ # @param xpath [String]
33
+ # @return [Nokogiri::XML::NodeSet]
34
+ def node_set_value(node, xpath)
35
+ node.xpath(xpath)
36
+ end
37
+
38
+ # @param node [Nokogiri::XML::Node]
39
+ # @param xpath [String]
40
+ # @return [Nokogiri::XML::Node]
41
+ def node_value(node, xpath)
42
+ node.at_xpath(xpath)
43
+ end
30
44
  end
31
45
  end
32
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aranha
4
4
  module Parsers
5
- VERSION = '0.17.1'
5
+ VERSION = '0.18.0'
6
6
  end
7
7
  end
@@ -12,10 +12,11 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale,template}/**/*']
14
14
 
15
- s.add_dependency 'aranha-parsers', '~> 0.17', '>= 0.17.1'
16
- s.add_dependency 'avm', '~> 0.67', '>= 0.67.1'
15
+ s.add_dependency 'aranha-parsers', '~> 0.18'
16
+ s.add_dependency 'avm', '~> 0.71'
17
17
  s.add_dependency 'avm-eac_generic_base0', '~> 0.12'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.112'
18
+ s.add_dependency 'eac_envs-http', '~> 0.3', '>= 0.3.2'
19
+ s.add_dependency 'eac_ruby_utils', '~> 0.116'
19
20
 
20
21
  s.add_development_dependency 'aranha-parsers', '~> 0.14', '>= 0.14.1'
21
22
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
3
  require 'eac_ruby_utils/simple_cache'
5
4
  require 'rubygems'
6
5
  require 'eac_cli/speaker'
7
- require 'aranha/parsers/source_address'
8
6
  require 'avm/launcher/publish/base'
9
7
  require 'avm/launcher/publish/check_result'
10
8
  require 'avm/eac_ruby_base1/launcher/gem'
9
+ require 'eac_envs/http/request'
10
+ require 'eac_envs/http/response'
11
11
 
12
12
  module Avm
13
13
  module EacRubyBase1
@@ -97,14 +97,13 @@ module Avm
97
97
  gem_version_max.present? && ::Gem::Version.new(gem_spec.version) < gem_version_max
98
98
  end
99
99
 
100
+ # @return [Array]
100
101
  def gem_versions_uncached
101
- ::JSON.parse!(
102
- ::Aranha::Parsers::SourceAddress.detect_sub(
103
- "https://rubygems.org/api/v1/versions/#{gem_spec.name}.json"
104
- ).content
105
- )
106
- rescue ::Aranha::Parsers::SourceAddress::FetchContentError => e
107
- e.request.status == 404 ? [] : raise(e)
102
+ ::EacEnvs::Http::Request.new
103
+ .url("https://rubygems.org/api/v1/versions/#{gem_spec.name}.json")
104
+ .response.body_data_or_raise
105
+ rescue EacEnvs::Http::Response => e
106
+ e.status == 404 ? [] : raise(e)
108
107
  end
109
108
 
110
109
  def gem_version_max_uncached
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRubyBase1
5
- VERSION = '0.30.2'
5
+ VERSION = '0.30.3'
6
6
  end
7
7
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
8
+ eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
@@ -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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacEnvs
4
+ module Http
5
+ class Error < ::RuntimeError
6
+ end
7
+ end
8
+ 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