nova-api 0.4.0 → 0.5.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/CHANGELOG.md +10 -2
- data/Gemfile.lock +1 -1
- data/lib/nova/api.rb +13 -0
- data/lib/nova/api/base.rb +22 -10
- data/lib/nova/api/resource/bill.rb +39 -0
- data/lib/nova/api/resource/card.rb +11 -0
- data/lib/nova/api/resource/installment.rb +19 -0
- data/lib/nova/api/resource/payable.rb +57 -0
- data/lib/nova/api/resource/receivable.rb +61 -0
- data/lib/nova/api/resource/third_party.rb +4 -1
- data/lib/nova/api/utils/base_struct.rb +26 -0
- data/lib/nova/api/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a8e79b9a9865e156d8a56b694ba90e42f2f484b4b4000c4aab312387ebbf292
|
4
|
+
data.tar.gz: 8412dbb5038ce302b39fe96fd3fb723a4b0bd48b008f7747dfe908e7672f2576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005e85aeb3b00d333df06230e5efbfba42a1f219bd09615cfdf5fc5a6be93e68ad89921ec4d19b21b2628fca85693bf4ffd2826bfe140960fea33dd715e44ea9
|
7
|
+
data.tar.gz: 9b9079d0ed717d5c6f6c45c988059724f8e40e85b67bd03a163485686b543e52864cfd385075a7e0998bf39c8bf3aca28e1b0e5bb489e518ff2a4b954efac1cc
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## [
|
8
|
+
## [0.5.0] - 2021-03-09
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Payables & Receivables related stuff
|
13
|
+
|
14
|
+
- Card taxes to cards asset
|
9
15
|
|
10
16
|
## [0.4.0] - 2021-03-05
|
11
17
|
|
@@ -41,7 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
41
47
|
|
42
48
|
- Apportionment related stuff
|
43
49
|
|
44
|
-
[unreleased]: https://github.com/coyosoftware/nova-api/compare/0.
|
50
|
+
[unreleased]: https://github.com/coyosoftware/nova-api/compare/0.5.0...HEAD
|
51
|
+
[0.5.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.5.0
|
52
|
+
[0.4.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.4.0
|
45
53
|
[0.3.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.3.0
|
46
54
|
[0.2.0]: https://github.com/coyosoftware/nova-api/releases/tag/0.2.0
|
47
55
|
[0.1.1]: https://github.com/coyosoftware/nova-api/releases/tag/0.1.1
|
data/Gemfile.lock
CHANGED
data/lib/nova/api.rb
CHANGED
@@ -10,6 +10,11 @@ require "nova/api/resource/apportionment_value"
|
|
10
10
|
require "nova/api/resource/apportionment"
|
11
11
|
require "nova/api/resource/company"
|
12
12
|
|
13
|
+
require "nova/api/resource/installment"
|
14
|
+
require "nova/api/resource/bill"
|
15
|
+
require "nova/api/resource/payable"
|
16
|
+
require "nova/api/resource/receivable"
|
17
|
+
|
13
18
|
require "nova/api/resource/current_asset"
|
14
19
|
require "nova/api/resource/bank"
|
15
20
|
require "nova/api/resource/card"
|
@@ -76,6 +81,14 @@ module Nova
|
|
76
81
|
Nova::API::Resource::FinancialAccount
|
77
82
|
end
|
78
83
|
|
84
|
+
def payables
|
85
|
+
Nova::API::Resource::Payable
|
86
|
+
end
|
87
|
+
|
88
|
+
def receivables
|
89
|
+
Nova::API::Resource::Receivable
|
90
|
+
end
|
91
|
+
|
79
92
|
def third_parties
|
80
93
|
Nova::API::Resource::ThirdParty
|
81
94
|
end
|
data/lib/nova/api/base.rb
CHANGED
@@ -28,18 +28,18 @@ module Nova
|
|
28
28
|
|
29
29
|
protected
|
30
30
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
data = attributes.dup
|
35
|
-
|
36
|
-
data.keys.each { |key| data.delete(key.to_sym) unless self.class.const_get('ALLOWED_ATTRIBUTES').include?(key.to_sym) }
|
31
|
+
def self.initialize_empty_model_with_id(klass, id, additional_attributes = {})
|
32
|
+
data = klass.schema.type.keys.map do |field|
|
33
|
+
name = field.name
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
if additional_attributes[name]
|
36
|
+
[name, additional_attributes[name]]
|
37
|
+
else
|
38
|
+
type = field.type
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
type.optional? ? [name, nil] : [name, generate_valid_value_for(type)]
|
41
|
+
end
|
42
|
+
end
|
43
43
|
|
44
44
|
klass.new(Hash[*data.flatten].merge(id: id))
|
45
45
|
end
|
@@ -121,6 +121,18 @@ module Nova
|
|
121
121
|
base_uri base_url
|
122
122
|
end
|
123
123
|
def_delegator self, :set_base_uri
|
124
|
+
|
125
|
+
def self.generate_valid_value_for(type)
|
126
|
+
case type.name
|
127
|
+
when Dry::Types['integer'].name, Dry::Types['float'].name, Dry::Types['decimal'].name
|
128
|
+
0
|
129
|
+
when Dry::Types['bool'].name
|
130
|
+
false
|
131
|
+
else
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
def_delegator self, :generate_valid_value_for
|
124
136
|
end
|
125
137
|
end
|
126
138
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Nova
|
2
|
+
module API
|
3
|
+
module Resource
|
4
|
+
class Bill < Nova::API::Base
|
5
|
+
class Apportionment < Nova::API::Utils::BaseStruct
|
6
|
+
ALLOWED_ATTRIBUTES = [:value, :apportionment_value_ids]
|
7
|
+
|
8
|
+
attribute :apportionment_value_ids, Dry::Types['strict.array'].of(Dry::Types['coercible.integer'].optional)
|
9
|
+
attribute :value, Dry::Types['coercible.decimal']
|
10
|
+
end
|
11
|
+
|
12
|
+
ALLOWED_ATTRIBUTES = [
|
13
|
+
:additional_information, :apportionments, :company_id, :date, :document_type, :document_number, :due_type, :financial_account_id,
|
14
|
+
:first_due_date, :forecast, :installments, :installments_number, :third_party_id, :total_value
|
15
|
+
]
|
16
|
+
|
17
|
+
attribute? :id, Dry::Types['coercible.integer'].optional
|
18
|
+
attribute? :additional_information, Dry::Types['coercible.string'].optional
|
19
|
+
attribute? :apportionments, Dry::Types['strict.array'].of(Nova::API::Resource::Bill::Apportionment).optional
|
20
|
+
attribute :company_id, Dry::Types['coercible.integer']
|
21
|
+
attribute :date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
|
22
|
+
attribute :document_type, Dry::Types['coercible.integer']
|
23
|
+
attribute? :document_number, Dry::Types['coercible.string']
|
24
|
+
attribute? :due_type, Dry::Types['coercible.integer']
|
25
|
+
attribute :financial_account_id, Dry::Types['coercible.integer']
|
26
|
+
attribute :first_due_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
|
27
|
+
attribute :forecast, Dry::Types['strict.bool']
|
28
|
+
attribute? :installments, Dry::Types['strict.array'].of(Nova::API::Resource::Installment).optional
|
29
|
+
attribute :installments_number, Dry::Types['coercible.integer']
|
30
|
+
attribute :third_party_id, Dry::Types['coercible.integer']
|
31
|
+
attribute :total_value, Dry::Types['coercible.decimal']
|
32
|
+
|
33
|
+
def self.endpoint
|
34
|
+
'/api/bills'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -2,10 +2,21 @@ module Nova
|
|
2
2
|
module API
|
3
3
|
module Resource
|
4
4
|
class Card < Nova::API::Resource::CurrentAsset
|
5
|
+
class Tax < Nova::API::Utils::BaseStruct
|
6
|
+
ALLOWED_ATTRIBUTES = %i[]
|
7
|
+
|
8
|
+
attribute :percentage, Dry::Types['coercible.decimal']
|
9
|
+
attribute :fixed, Dry::Types['coercible.decimal']
|
10
|
+
attribute :type, Dry::Types['coercible.string']
|
11
|
+
attribute :installments, Dry::Types['coercible.integer']
|
12
|
+
attribute :days, Dry::Types['coercible.integer']
|
13
|
+
end
|
14
|
+
|
5
15
|
ALLOWED_ATTRIBUTES = %i[]
|
6
16
|
|
7
17
|
attribute? :description, Dry::Types['coercible.string'].optional
|
8
18
|
attribute? :institution, Dry::Types['coercible.string'].optional
|
19
|
+
attribute :taxes, Dry::Types['strict.array'].of(Nova::API::Resource::Card::Tax)
|
9
20
|
|
10
21
|
def self.endpoint
|
11
22
|
'/api/cards'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nova
|
2
|
+
module API
|
3
|
+
module Resource
|
4
|
+
class Installment < Nova::API::Base
|
5
|
+
ALLOWED_ATTRIBUTES = %i[due_date gross_value number value]
|
6
|
+
|
7
|
+
attribute? :id, Dry::Types['coercible.integer'].optional
|
8
|
+
attribute :due_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
|
9
|
+
attribute? :gross_value, Dry::Types['coercible.decimal'].optional
|
10
|
+
attribute :number, Dry::Types['coercible.integer']
|
11
|
+
attribute :value, Dry::Types['coercible.decimal']
|
12
|
+
|
13
|
+
def self.endpoint
|
14
|
+
'/api/installments'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Nova
|
2
|
+
module API
|
3
|
+
module Resource
|
4
|
+
class Payable < Nova::API::Resource::Bill
|
5
|
+
def self.endpoint
|
6
|
+
'/api/payables'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(parameters)
|
10
|
+
model = new parameters
|
11
|
+
|
12
|
+
model.attributes.delete(:id)
|
13
|
+
|
14
|
+
model.save
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.update(id, parameters)
|
18
|
+
model = new parameters.merge(id: id)
|
19
|
+
|
20
|
+
model.update
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.destroy(id)
|
24
|
+
model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
|
25
|
+
|
26
|
+
model.destroy
|
27
|
+
end
|
28
|
+
|
29
|
+
def endpoint
|
30
|
+
protect_operation_from_missing_value
|
31
|
+
|
32
|
+
"/api/payables/#{id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def save
|
36
|
+
if id.nil?
|
37
|
+
do_post(self.class.endpoint, allowed_attributes)
|
38
|
+
else
|
39
|
+
do_patch("#{endpoint}", allowed_attributes)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
protect_operation_from_missing_value
|
45
|
+
|
46
|
+
do_patch("#{endpoint}", allowed_attributes)
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
protect_operation_from_missing_value
|
51
|
+
|
52
|
+
do_delete("#{endpoint}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Nova
|
2
|
+
module API
|
3
|
+
module Resource
|
4
|
+
class Receivable < Nova::API::Resource::Bill
|
5
|
+
ALLOWED_ATTRIBUTES = Nova::API::Resource::Bill::ALLOWED_ATTRIBUTES.dup << :gross_value
|
6
|
+
|
7
|
+
attribute? :gross_value, Dry::Types['coercible.decimal'].optional
|
8
|
+
|
9
|
+
def self.endpoint
|
10
|
+
'/api/receivables'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create(parameters)
|
14
|
+
model = new parameters
|
15
|
+
|
16
|
+
model.attributes.delete(:id)
|
17
|
+
|
18
|
+
model.save
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, parameters)
|
22
|
+
model = new parameters.merge(id: id)
|
23
|
+
|
24
|
+
model.update
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.destroy(id)
|
28
|
+
model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
|
29
|
+
|
30
|
+
model.destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
def endpoint
|
34
|
+
protect_operation_from_missing_value
|
35
|
+
|
36
|
+
"/api/receivables/#{id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
if id.nil?
|
41
|
+
do_post(self.class.endpoint, allowed_attributes)
|
42
|
+
else
|
43
|
+
do_patch("#{endpoint}", allowed_attributes)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
protect_operation_from_missing_value
|
49
|
+
|
50
|
+
do_patch("#{endpoint}", allowed_attributes)
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
protect_operation_from_missing_value
|
55
|
+
|
56
|
+
do_delete("#{endpoint}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -2,7 +2,10 @@ module Nova
|
|
2
2
|
module API
|
3
3
|
module Resource
|
4
4
|
class ThirdParty < Nova::API::Base
|
5
|
-
ALLOWED_ATTRIBUTES = %i[
|
5
|
+
ALLOWED_ATTRIBUTES = %i[
|
6
|
+
trading_name identification address phone social_reason municipal_inscription state_inscription email notes supplier
|
7
|
+
customer retention whatsapp twitter facebook linkedin google instagram site csll pis cofins irpj values_past
|
8
|
+
]
|
6
9
|
|
7
10
|
attribute? :id, Dry::Types['coercible.integer'].optional
|
8
11
|
attribute :trading_name, Dry::Types['coercible.string']
|
@@ -8,6 +8,32 @@ module Nova
|
|
8
8
|
DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/
|
9
9
|
|
10
10
|
transform_keys(&:to_sym)
|
11
|
+
|
12
|
+
def allowed_attributes
|
13
|
+
return attributes unless self.class.const_defined?('ALLOWED_ATTRIBUTES')
|
14
|
+
|
15
|
+
data = {}
|
16
|
+
|
17
|
+
self.class.const_get('ALLOWED_ATTRIBUTES').each do |key|
|
18
|
+
next unless attributes.keys.include? key
|
19
|
+
|
20
|
+
value = attributes[key]
|
21
|
+
|
22
|
+
if value.is_a? Array
|
23
|
+
data[key.to_sym] = value.map { |attribute| permit_value(key, attribute) }
|
24
|
+
else
|
25
|
+
data[key.to_sym] = permit_value(key, value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
data
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def permit_value(key, value)
|
35
|
+
value.respond_to?(:allowed_attributes) ? value.allowed_attributes : value
|
36
|
+
end
|
11
37
|
end
|
12
38
|
end
|
13
39
|
end
|
data/lib/nova/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nova-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Coyô Software
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -177,11 +177,15 @@ files:
|
|
177
177
|
- lib/nova/api/resource/apportionment.rb
|
178
178
|
- lib/nova/api/resource/apportionment_value.rb
|
179
179
|
- lib/nova/api/resource/bank.rb
|
180
|
+
- lib/nova/api/resource/bill.rb
|
180
181
|
- lib/nova/api/resource/card.rb
|
181
182
|
- lib/nova/api/resource/cash.rb
|
182
183
|
- lib/nova/api/resource/company.rb
|
183
184
|
- lib/nova/api/resource/current_asset.rb
|
184
185
|
- lib/nova/api/resource/financial_account.rb
|
186
|
+
- lib/nova/api/resource/installment.rb
|
187
|
+
- lib/nova/api/resource/payable.rb
|
188
|
+
- lib/nova/api/resource/receivable.rb
|
185
189
|
- lib/nova/api/resource/response/current_asset_statement.rb
|
186
190
|
- lib/nova/api/resource/third_party.rb
|
187
191
|
- lib/nova/api/resource/write_off.rb
|