nova-api 1.4.6 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a236ca75cc785c3010e6fc1b9992038318cdb1518ea54d864e0e8fb21bee85d
4
- data.tar.gz: d1d5eef3db768d89f0dd9b9fb6884bcd0ddd5fa473e7a6098d210d739fc6f738
3
+ metadata.gz: 909fbbbedbda0b6714b72a9708cf8232daf171b7c504e81c67480fed614ad808
4
+ data.tar.gz: 2330c2270fa4a67e6ea48a34e2ae124ca787e08e921b9b93ee1a9f57a863254a
5
5
  SHA512:
6
- metadata.gz: c84eaff31e3cec92bd7675cfa395ef5723e49d95d6137e2b921157e528e8afc7ab6ab178c4f5dd88ebbbbc1f9a25f310808db0799bdfd695aa84e708ae1edba1
7
- data.tar.gz: 22018019dd877ca2c2162108abb456695793c191276caa0c8bfcde3d9ef067b36a04d75b342afc123c0a3073e7c35bfd62a6437c280fce6e60cc896708b36f55
6
+ metadata.gz: '0993c57f427ea33cd105c370a73a9f5759fcd01e4eda3d4349a7287f22d896fdf224323e1cd90376e6d1bd3ec0a7fa4198fc3c1e994a3ce3afcdc4e225a2a58e'
7
+ data.tar.gz: 5d06ad945eb4e2abe335ebcf1215ac347fe74877f14ac1eeaf2b906451af972fdedaf10f46c7de038ac1f4dcac15c6d229f84228d287781d7f7f800c01da0e02
data/.circleci/config.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby: circleci/ruby@2.0.1
3
+ ruby: circleci/ruby@2.5.3
4
4
  jobs:
5
5
  test:
6
6
  docker:
7
- - image: cimg/ruby:3.0.6-node
7
+ - image: cimg/ruby:3.2.9-node
8
8
  steps:
9
9
  - checkout
10
10
  - ruby/install-deps
@@ -13,7 +13,7 @@ jobs:
13
13
  command: bundle exec rake
14
14
  deploy:
15
15
  docker:
16
- - image: cimg/ruby:3.0.6-node
16
+ - image: cimg/ruby:3.2.9-node
17
17
  steps:
18
18
  - checkout
19
19
  - ruby/install-deps
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nova-api (1.4.6)
4
+ nova-api (1.5.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
@@ -4,10 +4,6 @@ require 'forwardable'
4
4
  module Nova
5
5
  module API
6
6
  class Base < Nova::API::Utils::BaseStruct
7
- include HTTParty
8
-
9
- format :json
10
-
11
7
  SCHEME = 'https'
12
8
  PRODUCTION_HOST = 'nova.money'
13
9
  STAGING_HOST = 'staging.nova.money'
@@ -23,6 +19,7 @@ module Nova
23
19
 
24
20
  "#{SCHEME}://#{configuration.subdomain}.#{host}"
25
21
  end
22
+ def_delegator self, :base_url
26
23
 
27
24
  def endpoint
28
25
  raise EndpointNotConfiguredError, 'Each class must implement its own endpoint'
@@ -31,53 +28,47 @@ module Nova
31
28
  protected
32
29
 
33
30
  def self.do_get_search(endpoint, query, object = self)
34
- response = perform_get(endpoint, query, headers)
31
+ response = perform_get(endpoint, query)
35
32
 
36
33
  Nova::API::ListResponse.build(response, object)
37
34
  end
38
35
 
39
36
  def self.do_get(endpoint, query, object = self)
40
- response = perform_get(endpoint, query, headers)
37
+ response = perform_get(endpoint, query)
41
38
 
42
39
  Nova::API::Response.build(response, object)
43
40
  end
44
41
  def_delegator self, :do_get
45
42
 
46
43
  def do_delete(endpoint)
47
- set_base_uri
44
+ Kernel.p "[NOVA-API] Issuing DELETE to #{base_url}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
48
45
 
49
- Kernel.p "[NOVA-API] Issuing DELETE to #{self.class.base_uri}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
50
-
51
- response = self.class.delete(endpoint, headers: authorization_header)
46
+ response = HTTParty.delete("#{base_url}#{endpoint}", headers: authorization_header, format: :json)
52
47
 
53
48
  Nova::API::Response.build(response)
54
49
  end
55
50
 
56
51
  def do_patch(endpoint, data)
57
- set_base_uri
58
-
59
- Kernel.p "[NOVA-API] Issuing PATCH to #{self.class.base_uri}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
52
+ Kernel.p "[NOVA-API] Issuing PATCH to #{base_url}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
60
53
 
61
54
  if data.nil? || data.empty?
62
- response = self.class.patch(endpoint, headers: authorization_header)
55
+ response = HTTParty.patch("#{base_url}#{endpoint}", headers: authorization_header, format: :json)
63
56
 
64
57
  Nova::API::Response.build(response)
65
58
  else
66
59
  payload = data.dup
67
60
  payload.delete(:id)
68
61
 
69
- response = self.class.patch(endpoint, body: payload, headers: authorization_header)
62
+ response = HTTParty.patch("#{base_url}#{endpoint}", body: payload, headers: authorization_header, format: :json)
70
63
 
71
64
  Nova::API::Response.build(response, self)
72
65
  end
73
66
  end
74
67
 
75
68
  def do_post(endpoint, data)
76
- set_base_uri
69
+ Kernel.p "[NOVA-API] Issuing POST to #{base_url}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
77
70
 
78
- Kernel.p "[NOVA-API] Issuing POST to #{self.class.base_uri}#{endpoint}, headers: #{authorization_header}" if configuration.debug?
79
-
80
- response = self.class.post(endpoint, body: data, headers: authorization_header)
71
+ response = HTTParty.post("#{base_url}#{endpoint}", body: data, headers: authorization_header, format: :json)
81
72
 
82
73
  Nova::API::Response.build(response, self)
83
74
  end
@@ -89,16 +80,13 @@ module Nova
89
80
  private
90
81
 
91
82
  def self.perform_get(endpoint, query, headers = {})
92
- set_base_uri
93
-
94
- Kernel.p "[NOVA-API] Issuing GET to #{base_uri}#{endpoint}, headers: #{headers.merge(authorization_header)}" if configuration.debug?
83
+ Kernel.p "[NOVA-API] Issuing GET to #{base_url}#{endpoint}, headers: #{headers.merge(authorization_header)}" if configuration.debug?
95
84
 
96
- response =
97
- if query
98
- self.get(endpoint, query: query, headers: headers.merge(authorization_header))
99
- else
100
- self.get(endpoint, headers: headers.merge(authorization_header))
101
- end
85
+ if query
86
+ HTTParty.get("#{base_url}#{endpoint}", query: query, headers: headers.merge(authorization_header), format: :json)
87
+ else
88
+ HTTParty.get("#{base_url}#{endpoint}", headers: headers.merge(authorization_header), format: :json)
89
+ end
102
90
  end
103
91
 
104
92
  def self.authorization_header
@@ -110,17 +98,6 @@ module Nova
110
98
  Nova::API.configuration
111
99
  end
112
100
  def_delegator self, :configuration
113
-
114
- def self.set_base_uri
115
- if configuration.debug?
116
- debug_output $stdout
117
-
118
- Kernel.p "[NOVA-API] Changing base URI from #{base_uri} to #{base_url}"
119
- end
120
-
121
- default_options[:base_uri] = base_url
122
- end
123
- def_delegator self, :set_base_uri
124
101
  end
125
102
  end
126
103
  end
@@ -10,9 +10,52 @@ module Nova
10
10
  attribute :number, Dry::Types['coercible.integer']
11
11
  attribute :value, Dry::Types['coercible.float']
12
12
 
13
+ class WriteOffInstallment < Nova::API::Base
14
+ ALLOWED_ATTRIBUTES = [:addition, :attachments, :date, :discount, :extra_installment, :write_offs]
15
+
16
+ attribute? :id, Dry::Types['coercible.integer'].optional
17
+ attribute? :addition, Dry::Types['coercible.float'].optional
18
+ attribute? :attachments, Dry::Types['strict.array'].of(Dry::Types['coercible.string']).optional
19
+ attribute :date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
20
+ attribute? :discount, Dry::Types['coercible.float'].optional
21
+ attribute? :extra_installment do
22
+ attribute :due_date, Dry::Types['coercible.string'].constrained(format: DATE_REGEX)
23
+ attribute :value, Dry::Types['coercible.float']
24
+ end
25
+ attribute :write_offs, Dry::Types['strict.array'] do
26
+ attribute? :card_tax_id, Dry::Types['coercible.integer'].optional
27
+ attribute :current_asset_id, Dry::Types['coercible.integer']
28
+ attribute? :document_number, Dry::Types['coercible.string']
29
+ attribute :document_type, Dry::Types['coercible.integer']
30
+ attribute :value, Dry::Types['coercible.float']
31
+ end
32
+
33
+ def self.endpoint
34
+ Installment.endpoint
35
+ end
36
+
37
+ def write_off
38
+ protect_operation_from_missing_value
39
+
40
+ do_post("#{self.class.endpoint}/#{id}/write_off", allowed_attributes)
41
+ end
42
+ end
43
+
13
44
  def self.endpoint
14
45
  '/api/installments'
15
46
  end
47
+
48
+ def self.write_off(id, parameters)
49
+ model = WriteOffInstallment.new(parameters.merge(id:))
50
+
51
+ model.write_off
52
+ end
53
+
54
+ def write_off(parameters)
55
+ model = WriteOffInstallment.new(parameters.merge(id:))
56
+
57
+ model.write_off
58
+ end
16
59
  end
17
60
  end
18
61
  end
@@ -10,6 +10,10 @@ module Nova
10
10
  do_get_search(endpoint, parameters.to_h)
11
11
  end
12
12
 
13
+ def self.find(id)
14
+ do_get("#{endpoint}/#{id}", nil, initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601))
15
+ end
16
+
13
17
  def self.create(parameters)
14
18
  model = new parameters
15
19
 
@@ -14,6 +14,10 @@ module Nova
14
14
  do_get_search(endpoint, parameters.to_h)
15
15
  end
16
16
 
17
+ def self.find(id)
18
+ do_get("#{endpoint}/#{id}", nil, initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601))
19
+ end
20
+
17
21
  def self.create(parameters)
18
22
  model = new parameters
19
23
 
@@ -22,9 +22,7 @@ module Nova
22
22
  errors ||= extract_error_from_response('errors', parsed_response)
23
23
  errors ||= []
24
24
 
25
- if object
26
- record = object.class.new(object.attributes.merge(parsed_response))
27
- end
25
+ record = object.class.new(object.attributes.merge(parsed_response)) if object
28
26
 
29
27
  new(success: success, errors: errors, record: record, status: status)
30
28
  end
@@ -46,7 +46,13 @@ module Nova
46
46
  end
47
47
 
48
48
  def permit_value(key, value)
49
- value.respond_to?(:allowed_attributes) ? value.allowed_attributes : value
49
+ if value.respond_to?(:allowed_attributes)
50
+ value.allowed_attributes
51
+ elsif value.respond_to?(:attributes)
52
+ value.attributes
53
+ else
54
+ value
55
+ end
50
56
  end
51
57
 
52
58
  def self.value_for_field(override_value, field)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nova
4
4
  module API
5
- VERSION = '1.4.6'
5
+ VERSION = '1.5.0'
6
6
  end
7
7
  end
data/lib/nova/api.rb CHANGED
@@ -98,6 +98,10 @@ module Nova
98
98
  Nova::API::Resource::FinancialAccount
99
99
  end
100
100
 
101
+ def installments
102
+ Nova::API::Resource::Installment
103
+ end
104
+
101
105
  def payables
102
106
  Nova::API::Resource::Payable
103
107
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nova-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coyô Software
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -211,7 +210,6 @@ metadata:
211
210
  homepage_uri: https://app.swaggerhub.com/apis-docs/coyosoftware/Nova.Money/v1
212
211
  source_code_uri: https://github.com/coyosoftware/nova-api
213
212
  changelog_uri: https://github.com/coyosoftware/nova-api/blob/master/CHANGELOG.md
214
- post_install_message:
215
213
  rdoc_options: []
216
214
  require_paths:
217
215
  - lib
@@ -226,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
224
  - !ruby/object:Gem::Version
227
225
  version: '0'
228
226
  requirements: []
229
- rubygems_version: 3.4.19
230
- signing_key:
227
+ rubygems_version: 3.7.1
231
228
  specification_version: 4
232
229
  summary: Nova.Money API gem
233
230
  test_files: []