ehbrs_ruby_utils 0.13.0 → 0.14.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: 5aaed3c96601c1f0e58b967d6329f6f78b9e4c4b71af95a938c7315cceaf33dd
4
- data.tar.gz: 07aa64f3b9f8681a497e803fd6a5dd750efb8d334953b82e51ec56b96835a36b
3
+ metadata.gz: eb132b2dc682b7683edc567c4716ef2f34aa93d2b63b11bc03de8e7aa217ff02
4
+ data.tar.gz: 022db3bbe7aa0dc1fb8aa746f04ffcd7d7c8f96f06415d599a7f3b244c299719
5
5
  SHA512:
6
- metadata.gz: fb8e0db71d2926730c2ac6850769bc5f93965a42480c8fabfdaaeaeef65c5317bc5bb445e38aee185fe226dcd46c6dcc0f9287ee1a3e82b576d7e2239cb173e5
7
- data.tar.gz: 07e0d381377ba0678607414120e349211a1e09bd5ba02ac71acb4e069da6e33ca202eb383b0dc7d18306516cd987b24213c9a821e140197008743b6a09bc699c
6
+ metadata.gz: 5cdc02ecfd1f669e49f59f0ba2d93a7e3182cbf26cbda07865e9cf488d18359fef81c6b9470c9db74c328608e3016793d15b8cf892e22ab213795be5efe617c8
7
+ data.tar.gz: fc57f7bd021af03b4c9cbbea611cecaa9926f5cc59098d7662f213a3485c557b0a70f449b47e797f99ef6f6302a52e2f43298030d2f5012cf0cf555fd7cc1c72
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.13.0'
4
+ VERSION = '0.14.0'
5
5
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/result'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module WebUtils
9
+ class Instance < ::Avm::Instances::Base
10
+ class Finances
11
+ class Bills
12
+ class Consume
13
+ class File
14
+ enable_speaker
15
+ enable_simple_cache
16
+ common_constructor(:bills, :path) { perform }
17
+ delegate :instance, to: :bills
18
+
19
+ protected
20
+
21
+ def perform
22
+ infov 'Relative path', relative_path
23
+ process_response
24
+ end
25
+
26
+ def relative_path
27
+ path.relative_path_from(bills.pending_directory.to_path)
28
+ end
29
+
30
+ def process_response
31
+ if response_status_result.success?
32
+ move_to_registered
33
+ else
34
+ warn(" * Retornou com status de erro:\n\n#{response.body}")
35
+ end
36
+ infov ' * Response status', response_status_result.label
37
+ end
38
+
39
+ def move_to_registered
40
+ ::FileUtils.mkdir_p(::File.dirname(target_path))
41
+ ::File.rename(path, target_path)
42
+ end
43
+
44
+ def target_path
45
+ ::File.join(bills.registered_directory, relative_path)
46
+ end
47
+
48
+ def response_uncached
49
+ bills.instance.http_request(
50
+ '/finances/file_imports',
51
+ method: :post,
52
+ body: {
53
+ 'record[file]' => ::File.new(path)
54
+ },
55
+ header: {
56
+ 'Accept' => 'application/json'
57
+ }
58
+ )
59
+ 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
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ class Consume
12
+ require_sub __FILE__
13
+ common_constructor(:bills)
14
+ delegate :instance, :pending_directory, :registered_directory, to: :bills
15
+
16
+ def perform
17
+ bills.pending_directory.glob('**/*').each do |path|
18
+ next unless path.file?
19
+
20
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume::File.new(self, path)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ require_sub __FILE__
12
+ common_constructor :finances
13
+ delegate :instance, to: :finances
14
+
15
+ # @return [Pathname]
16
+ def bills_directory(suffix)
17
+ instance.read_entry('finances.bills.directory').to_pathname.join(suffix)
18
+ end
19
+
20
+ # @return [EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume]
21
+ def consume
22
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume.new(self)
23
+ end
24
+
25
+ # @return [Pathname]
26
+ def pending_directory
27
+ bills_directory('pending')
28
+ end
29
+
30
+ # @return [Pathname]
31
+ def registered_directory
32
+ bills_directory('registered')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ require_sub __FILE__
11
+ enable_simple_cache
12
+ common_constructor :instance
13
+
14
+ private
15
+
16
+ def bills_uncached
17
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills.new(self)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,6 +7,12 @@ require 'httpclient'
7
7
  module EhbrsRubyUtils
8
8
  module WebUtils
9
9
  class Instance < ::Avm::Instances::Base
10
+ require_sub __FILE__
11
+
12
+ def finances
13
+ @finances ||= ::EhbrsRubyUtils::WebUtils::Instance::Finances.new(self)
14
+ end
15
+
10
16
  def root_url
11
17
  read_entry(:url)
12
18
  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.13.0
4
+ version: 0.14.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: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -188,6 +188,10 @@ files:
188
188
  - lib/ehbrs_ruby_utils/videos/stream.rb
189
189
  - lib/ehbrs_ruby_utils/web_utils.rb
190
190
  - lib/ehbrs_ruby_utils/web_utils/instance.rb
191
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances.rb
192
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills.rb
193
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume.rb
194
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume/file.rb
191
195
  - lib/ehbrs_ruby_utils/web_utils/videos.rb
192
196
  - lib/ehbrs_ruby_utils/web_utils/videos/file.rb
193
197
  - lib/ehbrs_ruby_utils/web_utils/videos/file/rename.rb