nova-api 0.6.0 → 0.7.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: 35cedd3144e19d9be95589ac45569af5cff50031c6f01d9b7bd41aa082537f30
4
- data.tar.gz: 0aee3a26bf704fcb224fa79e93970b0d485f10e2991fe23ad3dbfd79559b3839
3
+ metadata.gz: b216822cbce6773c2c57891e535c183cce4fa84a659c58ea03b57f9137fd7a06
4
+ data.tar.gz: 9a0203ee8e6fffda09ea938d49d02394148ba5cb04514962aaa6150d8a918fa1
5
5
  SHA512:
6
- metadata.gz: dbd47b17aa69cd822b3a0a1f97783ad9aafcc3d65a2d6c20be78f9fb9b036785d8c449ff97c6a18a2d9ed7a35429bcc8827585dcb8fd329ea01997326cc21016
7
- data.tar.gz: e02499eb4e05c8ece8527f1bb7d901bf072008cb17b66fd450ba7cbbf8bcd48094ad8a84eeb4a0f6df7061e1ea57b9e098967885f1a8be8145d08e320b8bdf93
6
+ metadata.gz: c02e39188f050e491dae8d8cea5cf96650e7718bef05b8d9bb0d5161396e89daecd10ff5751b2c1cb68030bdef3bfb07d8f0f6ff5489a5bdaefe2d31144fcd7d
7
+ data.tar.gz: 603d6ec2bad145e6e7917819407c6db33f03ec9a2e23c0ab17768fc3b71763a3a239115110e622335ac0b838cb10d8a8fc25cebdb44a758aa0f8cba9d7ce83f6
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ 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
+ ## [0.7.0] - 2021-03-12
9
+
10
+ ### Added
11
+
12
+ - Bill document types constants
13
+
14
+ - Bill due types constants
15
+
16
+ - Identifier attribute to bill resource
17
+
18
+ - Receivables search endpoint
19
+
20
+ - Payables search endpoint
21
+
8
22
  ## [0.6.0] - 2021-03-10
9
23
 
10
24
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nova-api (0.6.0)
4
+ nova-api (0.7.0)
5
5
  dry-struct (~> 1.4.0)
6
6
  dry-types (~> 1.5.1)
7
7
  httparty (~> 0.1)
data/lib/nova/api.rb CHANGED
@@ -27,6 +27,7 @@ require "nova/api/resource/write_off"
27
27
  require "nova/api/resource/response/current_asset_statement"
28
28
 
29
29
  require "nova/api/search_params/apportionment"
30
+ require "nova/api/search_params/bill"
30
31
  require "nova/api/search_params/current_asset"
31
32
  require "nova/api/search_params/current_asset_statement"
32
33
  require "nova/api/search_params/third_party"
data/lib/nova/api/base.rb CHANGED
@@ -32,13 +32,7 @@ module Nova
32
32
  data = klass.schema.type.keys.map do |field|
33
33
  name = field.name
34
34
 
35
- if additional_attributes[name]
36
- [name, additional_attributes[name]]
37
- else
38
- type = field.type
39
-
40
- type.optional? ? [name, nil] : [name, generate_valid_value_for(type)]
41
- end
35
+ value_for_field(name, additional_attributes[name], field)
42
36
  end
43
37
 
44
38
  klass.new(Hash[*data.flatten].merge(id: id))
@@ -96,6 +90,14 @@ module Nova
96
90
 
97
91
  private
98
92
 
93
+ def self.value_for_field(name, override_value, field)
94
+ return [name, override_value] if override_value
95
+
96
+ type = field.type
97
+
98
+ type.optional? ? [name, nil] : [name, generate_valid_value_for(type)]
99
+ end
100
+
99
101
  def self.perform_get(endpoint, query, headers = {})
100
102
  set_base_uri
101
103
 
@@ -17,7 +17,7 @@ module Nova
17
17
  records = nil
18
18
 
19
19
  if parsed_response.is_a?(Array)
20
- records = klass.nil? ? nil : parsed_response.map { |object| klass.new(object) }
20
+ records = build_records(klass, parsed_response)
21
21
  else
22
22
  parsed_response = parsed_response.to_h
23
23
 
@@ -37,6 +37,10 @@ module Nova
37
37
 
38
38
  response[field].is_a?(Array) ? response[field] : [response[field]]
39
39
  end
40
+
41
+ def self.build_records(klass, response)
42
+ response.map { |object| klass.new(object) } unless klass.nil?
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -2,16 +2,38 @@ module Nova
2
2
  module API
3
3
  module Resource
4
4
  class Bill < Nova::API::Base
5
+ module DOCUMENT_TYPE
6
+ INVOICE = 0
7
+ RECEIPT = 1
8
+ COUPON_TAX = 2
9
+ BILL = 3
10
+ BILLET = 4
11
+ CHEQUE = 5
12
+ INITIAL_BALANCE = 6
13
+ TRANSFERENCE = 7
14
+ CONTRACT = 8
15
+ OTHER = 9
16
+ STATEMENT = 10
17
+ end
18
+
19
+ module DUE_TYPE
20
+ MONTHLY = 0
21
+ BIWEEKLY = 1
22
+ TEN_DAYS = 2
23
+ FIXED = 3
24
+ WEEKLY = 4
25
+ end
26
+
5
27
  class Apportionment < Nova::API::Utils::BaseStruct
6
28
  ALLOWED_ATTRIBUTES = [:value, :apportionment_value_ids]
7
29
 
8
30
  attribute :apportionment_value_ids, Dry::Types['strict.array'].of(Dry::Types['coercible.integer'].optional)
9
- attribute :value, Dry::Types['coercible.decimal']
31
+ attribute :value, Dry::Types['coercible.float']
10
32
  end
11
33
 
12
34
  ALLOWED_ATTRIBUTES = [
13
35
  :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
36
+ :first_due_date, :forecast, :identifier, :installments, :installments_number, :third_party_id, :total_value
15
37
  ]
16
38
 
17
39
  attribute? :id, Dry::Types['coercible.integer'].optional
@@ -25,10 +47,11 @@ module Nova
25
47
  attribute :financial_account_id, Dry::Types['coercible.integer']
26
48
  attribute :first_due_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
27
49
  attribute :forecast, Dry::Types['strict.bool']
50
+ attribute? :identifier, Dry::Types['coercible.string'].optional
28
51
  attribute? :installments, Dry::Types['strict.array'].of(Nova::API::Resource::Installment).optional
29
52
  attribute :installments_number, Dry::Types['coercible.integer']
30
53
  attribute :third_party_id, Dry::Types['coercible.integer']
31
- attribute :total_value, Dry::Types['coercible.decimal']
54
+ attribute :total_value, Dry::Types['coercible.float']
32
55
 
33
56
  def self.endpoint
34
57
  '/api/bills'
@@ -5,8 +5,8 @@ module Nova
5
5
  class Tax < Nova::API::Utils::BaseStruct
6
6
  ALLOWED_ATTRIBUTES = %i[]
7
7
 
8
- attribute :percentage, Dry::Types['coercible.decimal']
9
- attribute :fixed, Dry::Types['coercible.decimal']
8
+ attribute :percentage, Dry::Types['coercible.float']
9
+ attribute :fixed, Dry::Types['coercible.float']
10
10
  attribute :type, Dry::Types['coercible.string']
11
11
  attribute :installments, Dry::Types['coercible.integer']
12
12
  attribute :days, Dry::Types['coercible.integer']
@@ -8,7 +8,7 @@ module Nova
8
8
  attribute? :company, Nova::API::Resource::Company.optional
9
9
  attribute? :active, Dry::Types['strict.bool'].optional
10
10
  attribute? :image, Dry::Types['coercible.string'].optional
11
- attribute? :balance, Dry::Types['coercible.decimal'].optional
11
+ attribute? :balance, Dry::Types['coercible.float'].optional
12
12
 
13
13
  def self.endpoint
14
14
  '/api/current_assets'
@@ -6,9 +6,9 @@ module Nova
6
6
 
7
7
  attribute? :id, Dry::Types['coercible.integer'].optional
8
8
  attribute :due_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
9
- attribute? :gross_value, Dry::Types['coercible.decimal'].optional
9
+ attribute? :gross_value, Dry::Types['coercible.float'].optional
10
10
  attribute :number, Dry::Types['coercible.integer']
11
- attribute :value, Dry::Types['coercible.decimal']
11
+ attribute :value, Dry::Types['coercible.float']
12
12
 
13
13
  def self.endpoint
14
14
  '/api/installments'
@@ -6,6 +6,10 @@ module Nova
6
6
  '/api/payables'
7
7
  end
8
8
 
9
+ def self.list(parameters = {})
10
+ do_get_search(endpoint, parameters.to_h)
11
+ end
12
+
9
13
  def self.create(parameters)
10
14
  model = new parameters
11
15
 
@@ -4,12 +4,16 @@ module Nova
4
4
  class Receivable < Nova::API::Resource::Bill
5
5
  ALLOWED_ATTRIBUTES = Nova::API::Resource::Bill::ALLOWED_ATTRIBUTES.dup << :gross_value
6
6
 
7
- attribute? :gross_value, Dry::Types['coercible.decimal'].optional
7
+ attribute? :gross_value, Dry::Types['coercible.float'].optional
8
8
 
9
9
  def self.endpoint
10
10
  '/api/receivables'
11
11
  end
12
12
 
13
+ def self.list(parameters = {})
14
+ do_get_search(endpoint, parameters.to_h)
15
+ end
16
+
13
17
  def self.create(parameters)
14
18
  model = new parameters
15
19
 
@@ -3,7 +3,7 @@ module Nova
3
3
  module Resource
4
4
  module Response
5
5
  class CurrentAssetStatement < Nova::API::Utils::BaseStruct
6
- attribute? :last_statement, Dry::Types['coercible.decimal'].optional
6
+ attribute? :last_statement, Dry::Types['coercible.float'].optional
7
7
  attribute? :write_offs, Dry::Types['strict.array'].of(Nova::API::Resource::WriteOff).optional
8
8
  end
9
9
  end
@@ -27,11 +27,11 @@ module Nova
27
27
  attribute? :google, Dry::Types['coercible.string'].optional
28
28
  attribute? :instagram, Dry::Types['coercible.string'].optional
29
29
  attribute? :site, Dry::Types['coercible.string'].optional
30
- attribute? :csll, Dry::Types['coercible.decimal'].optional
31
- attribute? :pis, Dry::Types['coercible.decimal'].optional
32
- attribute? :cofins, Dry::Types['coercible.decimal'].optional
33
- attribute? :irpj, Dry::Types['coercible.decimal'].optional
34
- attribute? :values_past, Dry::Types['coercible.decimal'].optional
30
+ attribute? :csll, Dry::Types['coercible.float'].optional
31
+ attribute? :pis, Dry::Types['coercible.float'].optional
32
+ attribute? :cofins, Dry::Types['coercible.float'].optional
33
+ attribute? :irpj, Dry::Types['coercible.float'].optional
34
+ attribute? :values_past, Dry::Types['coercible.float'].optional
35
35
 
36
36
  def self.endpoint
37
37
  '/api/third_parties'
@@ -5,7 +5,7 @@ module Nova
5
5
  ALLOWED_ATTRIBUTES = %i[]
6
6
 
7
7
  attribute? :date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX).optional
8
- attribute? :value, Dry::Types['coercible.decimal'].optional
8
+ attribute? :value, Dry::Types['coercible.float'].optional
9
9
  attribute? :financial_account, Nova::API::Resource::FinancialAccount.optional
10
10
  attribute? :third_party, Nova::API::Resource::ThirdParty.optional
11
11
  end
@@ -0,0 +1,9 @@
1
+ module Nova
2
+ module API
3
+ module SearchParams
4
+ class Bill < Nova::API::Utils::BaseStruct
5
+ attribute? :identifier, Dry::Types['coercible.string'].optional
6
+ end
7
+ end
8
+ end
9
+ end
@@ -19,7 +19,7 @@ module Nova
19
19
 
20
20
  value = attributes[key]
21
21
 
22
- data[key.to_sym] = value.is_a?(Array) ? value.map { |attribute| permit_value(key, attribute) } : permit_value(key, value)
22
+ data[key.to_sym] = extract_value(key, value)
23
23
  end
24
24
 
25
25
  data
@@ -27,6 +27,10 @@ module Nova
27
27
 
28
28
  private
29
29
 
30
+ def extract_value(key, value)
31
+ value.is_a?(Array) ? value.map { |attribute| permit_value(key, attribute) } : permit_value(key, value)
32
+ end
33
+
30
34
  def permit_value(key, value)
31
35
  value.respond_to?(:allowed_attributes) ? value.allowed_attributes : value
32
36
  end
@@ -1,5 +1,5 @@
1
1
  module Nova
2
2
  module API
3
- VERSION = "0.6.0"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
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.6.0
4
+ version: 0.7.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-10 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,6 +191,7 @@ files:
191
191
  - lib/nova/api/resource/write_off.rb
192
192
  - lib/nova/api/response.rb
193
193
  - lib/nova/api/search_params/apportionment.rb
194
+ - lib/nova/api/search_params/bill.rb
194
195
  - lib/nova/api/search_params/current_asset.rb
195
196
  - lib/nova/api/search_params/current_asset_statement.rb
196
197
  - lib/nova/api/search_params/third_party.rb