ehbrs_ruby_utils 0.20.0 → 0.22.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 +4 -4
- data/lib/ehbrs_ruby_utils/executables.rb +1 -1
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume/file.rb +5 -13
- data/lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb +43 -0
- data/lib/ehbrs_ruby_utils/web_utils/instance.rb +1 -23
- data/lib/ehbrs_ruby_utils/web_utils/request_error.rb +51 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a241af9b0a27b447cef66e7d719fbda116547b7cfe5ceac348b9bb1bd5662d9
|
4
|
+
data.tar.gz: b02d61f6840f2a602535c24c655bc6a5655a6daa531995a9d78523165517c066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54762c964c78d7335f8efc92b19c29b6b7281a37d473e1b3cdd5515177e3e54492808c84481ce075c6a758c3d5d6ccb1fe1ad07ca5d75512600cb026a605697d
|
7
|
+
data.tar.gz: bf4f9ea658f93e2285735d98f22dde951a921f8d7f271b16c5d91c677119ef4c1f6c5f073427b30a4dc7b8dd207fe3bea2b05b00db0af76558b6e21cd246ec60
|
@@ -28,17 +28,16 @@ module EhbrsRubyUtils
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def process_response
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
infov ' * Response status', response_status_result.label
|
31
|
+
response
|
32
|
+
move_to_registered
|
33
|
+
rescue ::EhbrsRubyUtils::WebUtils::RequestError
|
34
|
+
warn(" * Retornou com status de erro:\n\n#{response.body}")
|
37
35
|
end
|
38
36
|
|
39
37
|
def move_to_registered
|
40
38
|
::FileUtils.mkdir_p(::File.dirname(target_path))
|
41
39
|
::File.rename(path, target_path)
|
40
|
+
infom 'Moved to registered'
|
42
41
|
end
|
43
42
|
|
44
43
|
def target_path
|
@@ -57,13 +56,6 @@ module EhbrsRubyUtils
|
|
57
56
|
}
|
58
57
|
)
|
59
58
|
end
|
60
|
-
|
61
|
-
def response_status_result
|
62
|
-
::Avm::Result.success_or_error(
|
63
|
-
response.status.to_s.match?(/\A2\d{2}\z/),
|
64
|
-
response.status
|
65
|
-
)
|
66
|
-
end
|
67
59
|
end
|
68
60
|
end
|
69
61
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_rest/api'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'ehbrs_ruby_utils/web_utils/request_error'
|
6
|
+
require 'avm/instances/base'
|
7
|
+
|
8
|
+
module EhbrsRubyUtils
|
9
|
+
module WebUtils
|
10
|
+
class Instance < ::Avm::Instances::Base
|
11
|
+
class HttpRequest
|
12
|
+
enable_method_class
|
13
|
+
enable_simple_cache
|
14
|
+
common_constructor :instance, :resource_url_suffix, :source_options, default: [{}]
|
15
|
+
|
16
|
+
# @return [EacRest::Response]
|
17
|
+
def result
|
18
|
+
r = request.response
|
19
|
+
::EhbrsRubyUtils::WebUtils::RequestError.raise_if_error(r)
|
20
|
+
::Struct.new(:status, :body).new(r.status, ::JSON.parse(r.body_str))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @return [::Struct.new(:verb, :body_data, :headers)]
|
26
|
+
def options_uncached
|
27
|
+
options = source_options.to_options_consumer
|
28
|
+
verb = options.consume(:method, :get).to_sym
|
29
|
+
body_data = options.consume(:body)
|
30
|
+
headers = options.consume(:header)
|
31
|
+
options.validate
|
32
|
+
::Struct.new(:verb, :body_data, :headers).new(verb, body_data, headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [EacRest::Request]
|
36
|
+
def request
|
37
|
+
instance.api.request(resource_url_suffix).verb(options.verb).headers(options.headers)
|
38
|
+
.body_data(options.body_data)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -7,7 +7,7 @@ require 'avm/instances/base'
|
|
7
7
|
module EhbrsRubyUtils
|
8
8
|
module WebUtils
|
9
9
|
class Instance < ::Avm::Instances::Base
|
10
|
-
require_sub __FILE__
|
10
|
+
require_sub __FILE__, require_dependency: true
|
11
11
|
|
12
12
|
# @return [EacRest::Api]
|
13
13
|
def api
|
@@ -21,28 +21,6 @@ module EhbrsRubyUtils
|
|
21
21
|
def root_url
|
22
22
|
read_entry(::Avm::Instances::EntryKeys::WEB_URL)
|
23
23
|
end
|
24
|
-
|
25
|
-
# @param resource_url_suffix [String]
|
26
|
-
# @param options [Hash]
|
27
|
-
# @return [EacRest::Response]
|
28
|
-
def http_request(resource_url_suffix, options = {})
|
29
|
-
options = http_request_options(options)
|
30
|
-
r = api.request(resource_url_suffix).verb(options.verb).headers(options.headers)
|
31
|
-
.body_data(options.body_data).response
|
32
|
-
::Struct.new(:status, :body).new(r.status, r.body_str)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# @return [::Struct.new(:verb, :body_data, :headers)]
|
38
|
-
def http_request_options(options)
|
39
|
-
options = options.to_options_consumer
|
40
|
-
verb = options.consume(:method, :get).to_sym
|
41
|
-
body_data = options.consume(:body)
|
42
|
-
headers = options.consume(:header)
|
43
|
-
options.validate
|
44
|
-
::Struct.new(:verb, :body_data, :headers).new(verb, body_data, headers)
|
45
|
-
end
|
46
24
|
end
|
47
25
|
end
|
48
26
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module WebUtils
|
7
|
+
class RequestError < ::RuntimeError
|
8
|
+
class << self
|
9
|
+
def raise_if_error(response)
|
10
|
+
by_error(response).if_present { |v| raise v }
|
11
|
+
end
|
12
|
+
|
13
|
+
def by_error(response)
|
14
|
+
return new(response, "status #{response.status}") unless
|
15
|
+
response.status.to_s.match?(/\A2\d{2}\z/)
|
16
|
+
|
17
|
+
data = ::JSON.parse(response.body_str)
|
18
|
+
return nil unless data.is_a?(::Hash)
|
19
|
+
|
20
|
+
errors = data['errors'] || {}
|
21
|
+
return nil if errors.empty?
|
22
|
+
|
23
|
+
new(response, "errors #{errors.pretty_inspect}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
enable_simple_cache
|
28
|
+
common_constructor :response, :message_suffix, super_args: -> { build_message }
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def build_message
|
32
|
+
"Request for \"#{response.url}\" failed: #{message_suffix}\nBody file: #{body_file_path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# @return [Pathname]
|
38
|
+
def body_file_path_uncached
|
39
|
+
r = ::EacRubyUtils::Fs::Temp.file(body_file_path_naming)
|
40
|
+
r.write(response.body_str)
|
41
|
+
r.to_path.to_pathname
|
42
|
+
end
|
43
|
+
|
44
|
+
def body_file_path_naming
|
45
|
+
r = ['request_error']
|
46
|
+
r << '.json' if response.status == 200
|
47
|
+
r
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha
|
@@ -66,6 +66,26 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: eac_rest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.7.1
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.7'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.7.1
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
name: eac_ruby_utils
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -235,6 +255,8 @@ files:
|
|
235
255
|
- lib/ehbrs_ruby_utils/web_utils/instance/finances/bills.rb
|
236
256
|
- lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume.rb
|
237
257
|
- lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume/file.rb
|
258
|
+
- lib/ehbrs_ruby_utils/web_utils/instance/http_request.rb
|
259
|
+
- lib/ehbrs_ruby_utils/web_utils/request_error.rb
|
238
260
|
- lib/ehbrs_ruby_utils/web_utils/videos.rb
|
239
261
|
- lib/ehbrs_ruby_utils/web_utils/videos/file.rb
|
240
262
|
- lib/ehbrs_ruby_utils/web_utils/videos/file/rename.rb
|