nova-api 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 909fbbbedbda0b6714b72a9708cf8232daf171b7c504e81c67480fed614ad808
4
- data.tar.gz: 2330c2270fa4a67e6ea48a34e2ae124ca787e08e921b9b93ee1a9f57a863254a
3
+ metadata.gz: c3289ed438ba6a1ece5a4ff75fa6d26d85ae06960fa702225deee4304099e177
4
+ data.tar.gz: 9bb44585ef0a4d433a3a82dc5a4b5d981b63e1c5ebef56b233756c4c1606b099
5
5
  SHA512:
6
- metadata.gz: '0993c57f427ea33cd105c370a73a9f5759fcd01e4eda3d4349a7287f22d896fdf224323e1cd90376e6d1bd3ec0a7fa4198fc3c1e994a3ce3afcdc4e225a2a58e'
7
- data.tar.gz: 5d06ad945eb4e2abe335ebcf1215ac347fe74877f14ac1eeaf2b906451af972fdedaf10f46c7de038ac1f4dcac15c6d229f84228d287781d7f7f800c01da0e02
6
+ metadata.gz: 7ba034021ea061029e6567e4151802a1e97035f8d8bc23b8b53dacc21267549bbde947421814d87a34c0800b793df6df42844c192a40fc121dd1c8f30e37c122
7
+ data.tar.gz: f24ae827d1050af8e957e990437f45491f994128eb9a5cdce0fae4dbc04e41f9bee856d594c93a34353fc47c51b689661b9101ab15d6ed6ba983688ec69d9ede
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nova-api (1.5.0)
4
+ nova-api (1.6.0)
5
5
  dry-struct (~> 1.6)
6
6
  dry-types (~> 1.7)
7
7
  httparty (~> 0.1)
data/lib/nova/api/base.rb CHANGED
@@ -65,12 +65,12 @@ module Nova
65
65
  end
66
66
  end
67
67
 
68
- def do_post(endpoint, data)
68
+ def do_post(endpoint, data, object = self)
69
69
  Kernel.p "[NOVA-API] Issuing POST to #{base_url}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
70
70
 
71
71
  response = HTTParty.post("#{base_url}#{endpoint}", body: data, headers: authorization_header, format: :json)
72
72
 
73
- Nova::API::Response.build(response, self)
73
+ Nova::API::Response.build(response, object)
74
74
  end
75
75
 
76
76
  def protect_operation_from_missing_value(attribute = :id)
@@ -0,0 +1,31 @@
1
+ module Nova
2
+ module API
3
+ module Resource
4
+ class Invoice < Nova::API::Base
5
+ module STATUS
6
+ AUTHORIZED = 2
7
+ CANCELLED = 3
8
+ end
9
+
10
+ module TYPE
11
+ PRODUCT = 0
12
+ SERVICE = 1
13
+ PRODUCT_REFUND = 2
14
+ end
15
+
16
+ ALLOWED_ATTRIBUTES = %i[danfe_url key number series status type url xml_url]
17
+
18
+ attribute? :id, Dry::Types['coercible.integer'].optional
19
+ attribute :bill_id, Dry::Types['coercible.integer']
20
+ attribute? :danfe_url, Dry::Types['coercible.string'].optional
21
+ attribute? :key, Dry::Types['coercible.string'].optional
22
+ attribute :number, Dry::Types['coercible.string']
23
+ attribute :series, Dry::Types['coercible.string']
24
+ attribute :status, Dry::Types['coercible.integer']
25
+ attribute :type, Dry::Types['coercible.integer']
26
+ attribute? :url, Dry::Types['coercible.string'].optional
27
+ attribute? :xml_url, Dry::Types['coercible.string'].optional
28
+ end
29
+ end
30
+ end
31
+ end
@@ -34,6 +34,12 @@ module Nova
34
34
  model.destroy
35
35
  end
36
36
 
37
+ def self.save_invoice(id, parameters)
38
+ model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
39
+
40
+ model.save_invoice(parameters)
41
+ end
42
+
37
43
  def endpoint
38
44
  protect_operation_from_missing_value
39
45
 
@@ -59,6 +65,14 @@ module Nova
59
65
 
60
66
  do_delete("#{endpoint}")
61
67
  end
68
+
69
+ def save_invoice(parameters)
70
+ protect_operation_from_missing_value
71
+
72
+ invoice = Invoice.new(parameters.merge(bill_id: id))
73
+
74
+ do_post("#{endpoint}/invoices", invoice.allowed_attributes, invoice)
75
+ end
62
76
  end
63
77
  end
64
78
  end
@@ -38,6 +38,12 @@ module Nova
38
38
  model.destroy
39
39
  end
40
40
 
41
+ def self.save_invoice(id, parameters)
42
+ model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
43
+
44
+ model.save_invoice(parameters)
45
+ end
46
+
41
47
  def endpoint
42
48
  protect_operation_from_missing_value
43
49
 
@@ -63,6 +69,14 @@ module Nova
63
69
 
64
70
  do_delete("#{endpoint}")
65
71
  end
72
+
73
+ def save_invoice(parameters)
74
+ protect_operation_from_missing_value
75
+
76
+ invoice = Invoice.new(parameters.merge(bill_id: id))
77
+
78
+ do_post("#{endpoint}/invoices", invoice.allowed_attributes, invoice)
79
+ end
66
80
  end
67
81
  end
68
82
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nova
4
4
  module API
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.0'
6
6
  end
7
7
  end
data/lib/nova/api.rb CHANGED
@@ -14,6 +14,7 @@ require "nova/api/resource/installment"
14
14
  require "nova/api/resource/bill"
15
15
  require "nova/api/resource/payable"
16
16
  require "nova/api/resource/receivable"
17
+ require "nova/api/resource/invoice"
17
18
 
18
19
  require "nova/api/resource/direct_bill"
19
20
  require "nova/api/resource/direct_payable"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nova-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coyô Software
@@ -185,6 +185,7 @@ files:
185
185
  - lib/nova/api/resource/direct_receivable.rb
186
186
  - lib/nova/api/resource/financial_account.rb
187
187
  - lib/nova/api/resource/installment.rb
188
+ - lib/nova/api/resource/invoice.rb
188
189
  - lib/nova/api/resource/payable.rb
189
190
  - lib/nova/api/resource/permission.rb
190
191
  - lib/nova/api/resource/receivable.rb