belvo 0.19.3 → 1.1.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: 455f08aad36bb45f904a6c06fd63b46a91f320d20add273c8362e64d61d9e2a9
4
- data.tar.gz: 674222f146ca510d11aee096a80c92b6b492ac37c1b56d9995d8524fc326c066
3
+ metadata.gz: 77535d19fd4a624ef494fa4c6354fc427bbfa388122398bace8dbe011207a006
4
+ data.tar.gz: e7655524ec6125db8fadb1f1b7fbee29e82685a4ead7edfecaec56a618f09bda
5
5
  SHA512:
6
- metadata.gz: 1020a9ca2b693f828453c35b960909a287948c441846873ad046d6dd74007f95682d929f1bca7c030bee692ffece52fa9d9a7d83e5e8b71dc353f23736eadda2
7
- data.tar.gz: eb1609e92f2b796b7a57aefdd9ef6dc64b89400efebc9f250bde379ffe4ee4dee59ed4c1fe9d8bbb22d92e6a8a6e79d0ed35a85107a878bddd08e2d00616b221
6
+ metadata.gz: 6366c18991ba3ff5b24efbfde467560a05d52d1392f349cf8a38c0515a59bba430fa2456e0fbcf35fdc89a0a28cdd43756371e5bc0dcc106afc6e03e3f845bac
7
+ data.tar.gz: 2ea9b99bd9dba5890256ca1c3404943d08b606187f8ecf6453f133d047955fca96691224b98d816699144bb6110353902b71e3543934e858d1834c76762630db
@@ -0,0 +1,26 @@
1
+ name: Build & deploy Ruby SDK documentation
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ name: Update gh-pages with docs
10
+ steps:
11
+ - name: Checkout Belvo Ruby SDK repo
12
+ uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: "2.7"
17
+ - name: Install required gem dependencies
18
+ run: gem install yard --no-document
19
+ - name: Build RUBY SDK docs with YARD
20
+ run: yardoc --output-dir docs
21
+ - name: Deploy docs to gh-pages branch
22
+ uses: peaceiris/actions-gh-pages@v3
23
+ with:
24
+ github_token: ${{ secrets.GITHUB_TOKEN }}
25
+ publish_dir: ./docs
26
+ publish_branch: gh-pages
data/.rubocop.yml CHANGED
@@ -25,3 +25,6 @@ Style/HashTransformKeys:
25
25
 
26
26
  Style/HashTransformValues:
27
27
  Enabled: true
28
+
29
+ RSpec/MultipleExpectations:
30
+ Max: 2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belvo (0.19.3)
4
+ belvo (1.1.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
  typhoeus
@@ -11,8 +11,8 @@ GEM
11
11
  specs:
12
12
  addressable (2.8.0)
13
13
  public_suffix (>= 2.0.2, < 5.0)
14
- ast (2.4.1)
15
- claide (1.0.3)
14
+ ast (2.4.2)
15
+ claide (1.1.0)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
@@ -20,12 +20,13 @@ GEM
20
20
  colored2 (3.1.2)
21
21
  cork (0.3.0)
22
22
  colored2 (~> 3.1)
23
- coveralls_reborn (0.23.0)
23
+ coveralls_reborn (0.24.0)
24
24
  simplecov (>= 0.18.1, < 0.22.0)
25
25
  term-ansicolor (~> 1.6)
26
26
  thor (>= 0.20.3, < 2.0)
27
27
  tins (~> 1.16)
28
- crack (0.4.4)
28
+ crack (0.4.5)
29
+ rexml
29
30
  danger (8.2.1)
30
31
  claide (~> 1.0)
31
32
  claide-plugins (>= 0.9.2)
@@ -39,54 +40,74 @@ GEM
39
40
  no_proxy_fix
40
41
  octokit (~> 4.7)
41
42
  terminal-table (~> 1)
42
- diff-lcs (1.4.4)
43
+ diff-lcs (1.5.0)
43
44
  docile (1.4.0)
44
- ethon (0.14.0)
45
+ ethon (0.15.0)
45
46
  ffi (>= 1.15.0)
46
- faraday (1.1.0)
47
- multipart-post (>= 1.2, < 3)
48
- ruby2_keywords
47
+ faraday (1.10.0)
48
+ faraday-em_http (~> 1.0)
49
+ faraday-em_synchrony (~> 1.0)
50
+ faraday-excon (~> 1.1)
51
+ faraday-httpclient (~> 1.0)
52
+ faraday-multipart (~> 1.0)
53
+ faraday-net_http (~> 1.0)
54
+ faraday-net_http_persistent (~> 1.0)
55
+ faraday-patron (~> 1.0)
56
+ faraday-rack (~> 1.0)
57
+ faraday-retry (~> 1.0)
58
+ ruby2_keywords (>= 0.0.4)
59
+ faraday-em_http (1.0.0)
60
+ faraday-em_synchrony (1.0.0)
61
+ faraday-excon (1.1.0)
49
62
  faraday-http-cache (2.2.0)
50
63
  faraday (>= 0.8)
51
- faraday_middleware (1.1.0)
64
+ faraday-httpclient (1.0.1)
65
+ faraday-multipart (1.0.3)
66
+ multipart-post (>= 1.2, < 3)
67
+ faraday-net_http (1.0.1)
68
+ faraday-net_http_persistent (1.2.0)
69
+ faraday-patron (1.0.0)
70
+ faraday-rack (1.0.0)
71
+ faraday-retry (1.0.3)
72
+ faraday_middleware (1.2.0)
52
73
  faraday (~> 1.0)
53
- ffi (1.15.3)
54
- git (1.8.1)
74
+ ffi (1.15.5)
75
+ git (1.11.0)
55
76
  rchardet (~> 1.8)
56
77
  hashdiff (1.0.1)
57
78
  jaro_winkler (1.5.4)
58
- kramdown (2.3.1)
79
+ kramdown (2.4.0)
59
80
  rexml
60
81
  kramdown-parser-gfm (1.1.0)
61
82
  kramdown (~> 2.0)
62
83
  multipart-post (2.1.1)
63
84
  nap (1.1.0)
64
85
  no_proxy_fix (0.1.2)
65
- octokit (4.21.0)
86
+ octokit (4.22.0)
66
87
  faraday (>= 0.9)
67
88
  sawyer (~> 0.8.0, >= 0.5.3)
68
89
  open4 (1.3.4)
69
- parallel (1.20.0)
70
- parser (2.7.2.0)
90
+ parallel (1.22.1)
91
+ parser (3.1.2.0)
71
92
  ast (~> 2.4.1)
72
- public_suffix (4.0.6)
73
- rainbow (3.0.0)
93
+ public_suffix (4.0.7)
94
+ rainbow (3.1.1)
74
95
  rake (12.3.3)
75
96
  rchardet (1.8.0)
76
97
  rexml (3.2.5)
77
- rspec (3.10.0)
78
- rspec-core (~> 3.10.0)
79
- rspec-expectations (~> 3.10.0)
80
- rspec-mocks (~> 3.10.0)
81
- rspec-core (3.10.0)
82
- rspec-support (~> 3.10.0)
83
- rspec-expectations (3.10.0)
98
+ rspec (3.11.0)
99
+ rspec-core (~> 3.11.0)
100
+ rspec-expectations (~> 3.11.0)
101
+ rspec-mocks (~> 3.11.0)
102
+ rspec-core (3.11.0)
103
+ rspec-support (~> 3.11.0)
104
+ rspec-expectations (3.11.0)
84
105
  diff-lcs (>= 1.2.0, < 2.0)
85
- rspec-support (~> 3.10.0)
86
- rspec-mocks (3.10.0)
106
+ rspec-support (~> 3.11.0)
107
+ rspec-mocks (3.11.1)
87
108
  diff-lcs (>= 1.2.0, < 2.0)
88
- rspec-support (~> 3.10.0)
89
- rspec-support (3.10.0)
109
+ rspec-support (~> 3.11.0)
110
+ rspec-support (3.11.0)
90
111
  rubocop (0.81.0)
91
112
  jaro_winkler (~> 1.5.1)
92
113
  parallel (~> 1.10)
@@ -97,8 +118,8 @@ GEM
97
118
  unicode-display_width (>= 1.4.0, < 2.0)
98
119
  rubocop-rspec (1.41.0)
99
120
  rubocop (>= 0.68.1)
100
- ruby-progressbar (1.10.1)
101
- ruby2_keywords (0.0.2)
121
+ ruby-progressbar (1.11.0)
122
+ ruby2_keywords (0.0.5)
102
123
  sawyer (0.8.2)
103
124
  addressable (>= 2.3.5)
104
125
  faraday (> 0.8, < 2.0)
@@ -107,20 +128,20 @@ GEM
107
128
  simplecov-html (~> 0.11)
108
129
  simplecov_json_formatter (~> 0.1)
109
130
  simplecov-html (0.12.3)
110
- simplecov_json_formatter (0.1.3)
131
+ simplecov_json_formatter (0.1.4)
111
132
  sync (0.5.0)
112
133
  term-ansicolor (1.7.1)
113
134
  tins (~> 1.0)
114
135
  terminal-table (1.8.0)
115
136
  unicode-display_width (~> 1.1, >= 1.1.1)
116
- thor (1.1.0)
117
- tins (1.29.1)
137
+ thor (1.2.1)
138
+ tins (1.31.0)
118
139
  sync
119
140
  typhoeus (1.4.0)
120
141
  ethon (>= 0.9.0)
121
- unicode-display_width (1.7.0)
122
- webmock (3.9.5)
123
- addressable (>= 2.3.6)
142
+ unicode-display_width (1.8.0)
143
+ webmock (3.14.0)
144
+ addressable (>= 2.8.0)
124
145
  crack (>= 0.3.2)
125
146
  hashdiff (>= 0.4.0, < 2.0.0)
126
147
 
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
@@ -51,7 +51,7 @@ module Belvo
51
51
  # @return [Boolean] True if credentials are valid to authenticate
52
52
  # to Belvo API else False.
53
53
  def authenticate
54
- @session.basic_auth(@key_id, @key_password)
54
+ @session.request(:basic_auth, @key_id, @key_password)
55
55
  response = @session.get('api/')
56
56
  response.success?
57
57
  end
@@ -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.
@@ -25,12 +25,11 @@ module Belvo
25
25
 
26
26
  # List all results
27
27
  # @param params [Hash] Extra parameters sent as query strings.
28
- # @return [Array]
28
+ # @return [Array] List of results when no block is passed.
29
+ # @yield [Hash] Each result to be processed individually.
29
30
  # @raise [RequestError] If response code is different than 2XX
30
31
  def list(params: nil)
31
- results = []
32
- @session.list(@endpoint, params: params) { |item| results.push item }
33
- results
32
+ @session.list(@endpoint, params: params)
34
33
  end
35
34
 
36
35
  # Show specific resource details
@@ -473,6 +472,48 @@ module Belvo
473
472
  end
474
473
  end
475
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
+
476
517
  # A Tax status is the representation of the tax situation of a person or a
477
518
  # business to the tax authority in the country.
478
519
  class TaxStatus < Resource
@@ -499,7 +540,8 @@ module Belvo
499
540
  end
500
541
 
501
542
  def resume(_session_id, _token, _link: nil)
502
- raise NotImplementedError 'TaxReturn does not support resuming a session.'
543
+ raise NotImplementedError \
544
+ 'TaxRetentions does not support resuming a session.'
503
545
  end
504
546
  end
505
547
 
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.19.3'
5
+ VERSION = '1.1.0'
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.19.3
4
+ version: 1.1.0
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-01-11 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -152,6 +152,7 @@ files:
152
152
  - ".github/ISSUE_TEMPLATE/feature_request.md"
153
153
  - ".github/pull_request_template.md"
154
154
  - ".github/workflows/danger-pr-reviews.yml"
155
+ - ".github/workflows/generate-docs.yml"
155
156
  - ".gitignore"
156
157
  - ".rspec"
157
158
  - ".rubocop.yml"
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
195
  - !ruby/object:Gem::Version
195
196
  version: '0'
196
197
  requirements: []
197
- rubygems_version: 3.2.32
198
+ rubygems_version: 3.3.11
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: The Ruby gem for the Belvo API