belvo 0.20.0 → 1.1.1

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: 05a03ab57113f17e822b4f48dd813edf5206bacfb79a757332fce693a60db786
4
- data.tar.gz: 2676ef16eabab4fcbd553ec28cf7378539eb468387954a2754b62d1c6642fe6e
3
+ metadata.gz: 92940ff5820a09ee1a7cd694581a1111f6161fe15ba34481c80b4f36c5dd4bfd
4
+ data.tar.gz: 6c34e09989c39e0f7e45d569ba359f4e02064b49bede2c8a40c6c4f3fbe71e52
5
5
  SHA512:
6
- metadata.gz: 522bc53deacef6bc63010a44d837acc100560bd9cb5a3721eea94cde3b37abb3090c385c9c0c2d411ebfd39fe9c1c88fc905ba03dc6bf70cb2ed58899af0f1c8
7
- data.tar.gz: 4bcee96d178f49fc23bac577725560f279f21e8a96670694b5d0f2918871e0ea5e332ba09b421769e24740217402e45c55f6e2bdfaaeda0c04caba00d0d92411
6
+ metadata.gz: 7dff5481b7fb7e757527821765e8d6da859b1ba4c737288eba95171363f6dfdb8763600e932271a72bbaa9da663f94d41889cb1d59e6aa60aef299103ed0f1c5
7
+ data.tar.gz: c902eecfffea0a1beaeb4fa968b19aa26b57b5fc319cfc73280401952a3c4abd25870a0ec3707e02c4bf39f127b449c8c663d466bfe3f67699f9269d162019e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belvo (0.20.0)
4
+ belvo (1.1.1)
5
5
  faraday
6
6
  faraday_middleware
7
7
  typhoeus
data/README.md CHANGED
@@ -53,7 +53,9 @@ begin
53
53
 
54
54
  belvo.accounts.retrieve(link: link_id)
55
55
 
56
- puts belvo.accounts.list
56
+ belvo.accounts.list.each do |item|
57
+ puts item
58
+ end
57
59
  rescue Belvo::RequestError => e
58
60
  puts e.status_code
59
61
  puts e.detail
@@ -79,17 +81,31 @@ begin
79
81
  username: 'janedoe',
80
82
  password: 'super-secret',
81
83
  options: { access_mode: Belvo::Link::AccessMode::SINGLE }
82
- )
84
+ )
83
85
 
84
86
  belvo.accounts.retrieve(link: new_link['id'])
85
87
 
86
- puts belvo.accounts.list
88
+ belvo.accounts.list.each do |item|
89
+ puts item
90
+ end
87
91
  rescue Belvo::RequestError => e
88
92
  puts e.status_code
89
93
  puts e.detail
90
94
  end
91
95
  ```
92
96
 
97
+ ## Pagination
98
+
99
+ All `list` methods only return the first page of results. If you want to iterate by all pages, you will need to specify the `page` as a parameter:
100
+
101
+ ```ruby
102
+ #`api/transactions`
103
+ ...
104
+ belvo.transactions.list(params: {page: "2"})
105
+ ...
106
+ ```
107
+ When the result of your call is `nil`, this indicates that there are no more pages to iterate over.
108
+
93
109
  **Note:** If you create a `Link` without specifying [access_mode](https://docs.belvo.com/#operation/RegisterLink), the SDK will respect the default value from the API.
94
110
 
95
111
  ## Development
data/lib/belvo/http.rb CHANGED
@@ -91,16 +91,8 @@ module Belvo
91
91
  # @raise [RequestError] If response code is different than 2XX
92
92
  def list(path, params: nil)
93
93
  params = {} if params.nil?
94
- loop do
95
- response = get(path, params: params)
96
- response.body['results'].each do |item|
97
- yield item if block_given?
98
- end
99
-
100
- break unless response.body['next']
101
-
102
- params = Faraday::Utils.parse_query URI(response.body['next']).query
103
- end
94
+ response = get(path, params: params)
95
+ response.body['results']
104
96
  end
105
97
 
106
98
  # Show specific resource details
data/lib/belvo/options.rb CHANGED
@@ -152,9 +152,28 @@ module Belvo
152
152
  )
153
153
  end
154
154
 
155
+ # @!class TaxRetentionsOptions < Faraday::Options
156
+ # Contains configurable properties of a tax retention
157
+ # @!attribute save_data [rw] Indicates whether or not to persist the
158
+ # data in Belvo. By default, this is set to `true` and we return a
159
+ # 201 Created response. When set to `false`, the data won't be persisted
160
+ # and we return a 200 OK response.
161
+ # @!attribute attach_xml [rw] When set to `true`, you will receive the XML
162
+ # tax retention in the response.
163
+ class TaxRetentionsOptions < Faraday::Options.new(
164
+ :save_data,
165
+ :attach_xml,
166
+ :date_from,
167
+ :date_to
168
+ )
169
+ end
170
+
155
171
  # @!class TaxStatusOptions < Faraday::Options
156
172
  # Contains configurable properties of a TaxStatus
157
- # @!attribute save_data [rw] Should data be persisted or not.
173
+ # @!attribute save_data [rw] Indicates whether or not to persist the data
174
+ # in Belvo. By default, this is set to `true` and we return a 201 Created
175
+ # response. When set to `false`, the data won't be persisted and we return
176
+ # a 200 OK response.
158
177
  # @!attribute token [rw] OTP token required by the institution
159
178
  # @!attribute attach_pdf [rw] Should the PDF file be included in the
160
179
  # response or not.
@@ -29,11 +29,7 @@ module Belvo
29
29
  # @yield [Hash] Each result to be processed individually.
30
30
  # @raise [RequestError] If response code is different than 2XX
31
31
  def list(params: nil)
32
- results = block_given? ? nil : []
33
- @session.list(@endpoint, params: params) do |item|
34
- results.nil? ? yield(item) : results.push(item)
35
- end
36
- results
32
+ @session.list(@endpoint, params: params)
37
33
  end
38
34
 
39
35
  # Show specific resource details
@@ -476,6 +472,48 @@ module Belvo
476
472
  end
477
473
  end
478
474
 
475
+ # A tax retention is the amount of money that the payer must deduct from the
476
+ # total amount of a purchase invoice, according to the regulations of the
477
+ # fiscal institution.
478
+ class TaxRetentions < Resource
479
+ def initialize(session)
480
+ super(session)
481
+ @endpoint = 'api/tax-retentions/'
482
+ end
483
+
484
+ class TaxRetentionsType
485
+ INFLOW = 'inflow'
486
+ OUTFLOW = 'outflow'
487
+ end
488
+
489
+ # Retrieve tax retentions from a specific fiscal link.
490
+ # @param link [String] The `link.id` that you want to get information
491
+ # for (UUID).
492
+ # @param type [TaxRetentionsType] The type of tax retention in relation to
493
+ # the invoice (from the perspective of the Link owner). `OUTFLOW` relates
494
+ # to a tax retention for a sent invoice. `INFLOW` relates to a tax
495
+ # retention for a received invoice. (inflow or outflow)
496
+ # @param options [TaxRetentionsOptions] Configurable properties
497
+ def retrieve(link:, type:, options: nil)
498
+ options = TaxRetentionsOptions.from(options)
499
+ body = {
500
+ link: link,
501
+ date_from: options.date_from,
502
+ date_to: options.date_to,
503
+ save_data: options.save_data,
504
+ attach_xml: options.attach_xml,
505
+ type: type
506
+ }.merge(options)
507
+ body = clean body: body
508
+ @session.post(@endpoint, body)
509
+ end
510
+
511
+ def resume(_session_id, _token, _link: nil)
512
+ raise NotImplementedError \
513
+ 'TaxRetentions does not support resuming a session'
514
+ end
515
+ end
516
+
479
517
  # A Tax status is the representation of the tax situation of a person or a
480
518
  # business to the tax authority in the country.
481
519
  class TaxStatus < Resource
@@ -502,7 +540,8 @@ module Belvo
502
540
  end
503
541
 
504
542
  def resume(_session_id, _token, _link: nil)
505
- raise NotImplementedError 'TaxReturn does not support resuming a session.'
543
+ raise NotImplementedError \
544
+ 'TaxRetentions does not support resuming a session.'
506
545
  end
507
546
  end
508
547
 
data/lib/belvo/utils.rb CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  require 'base64'
4
4
 
5
- # Class with helper functions
6
- class Utils
7
- def self.read_file_to_b64(path)
8
- return if path.nil? || !File.file?(path)
5
+ module Belvo
6
+ # Class with helper functions
7
+ class Utils
8
+ def self.read_file_to_b64(path)
9
+ return if path.nil? || !File.file?(path)
9
10
 
10
- data = File.open(path).read
11
- Base64.encode64(data)
11
+ data = File.open(path).read
12
+ Base64.encode64(data)
13
+ end
12
14
  end
13
15
  end
14
16
 
data/lib/belvo/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Belvo
4
4
  # belvo-ruby current version
5
- VERSION = '0.20.0'
5
+ VERSION = '1.1.1'
6
6
  end
data/lib/belvo.rb CHANGED
@@ -110,7 +110,13 @@ module Belvo
110
110
  @tax_status = TaxStatus.new @session
111
111
  end
112
112
 
113
- # Provides access to Instituions resource
113
+ # Provides access to the TaxRetentions resource
114
+ # @return [TaxRetentions]
115
+ def tax_retentions
116
+ @tax_retentions = TaxRetentions.new @session
117
+ end
118
+
119
+ # Provides access to the Institutions resource
114
120
  # @return [Institution]
115
121
  def institutions
116
122
  @institutions = Institution.new @session
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belvo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Belvo Finance S.L.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-06 00:00:00.000000000 Z
11
+ date: 2022-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday