belvo 0.3.0 → 0.6.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: 759f6f987ab53c7befec57c77cdfb6382c828afe83ca304dcfc7ca06f6f816c8
4
- data.tar.gz: 6d600dbc5a78cec15a6008a24004ca333b645fb2b671f3e78deb94ec12a54fa0
3
+ metadata.gz: 5c1dcb245d74ddc040cd5e0f820ff9ecefa761e0135ee16fe5b08a6bf89dae26
4
+ data.tar.gz: d2a243cd3f86fd7bb295a8fd85dab1e7226aa95f60ee5d8c30a5b3905dcd9918
5
5
  SHA512:
6
- metadata.gz: d1bcdaf03338f5044a3197b21c1cbfd1290143833f4062162ca40c9428053a89625ba2e4b8829ca9cde2bc8525d4b9329cb91ad81f7d81a410c68149983df7ca
7
- data.tar.gz: c27cc39ba3bf8c70068254ea9e48dd29dd19850b0f11d411520a512ab3f72b5c1b57b3fb2d67c8717062783c7282a31d86972c8da00fcded05c7fd71530047f6
6
+ metadata.gz: 96a5bafd4609f9502bb7d228b7fab60064560d35b10b78250c525981e797b2d052cce96e89ce3aa5edfd017a6fbafde24a44c6f96a8f63b392f27ec3c0b599d7
7
+ data.tar.gz: ac7a333d2ef31d24d9563dd63eabbfb9cc187140df38b6c0044d641a748d2d6326690d0222152e66810464371c43dcf92310677bbf32662c603e555558701a18
@@ -0,0 +1,6 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ checks:
5
+ Rubocop/Style/MutableConstant:
6
+ enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belvo (0.3.0)
4
+ belvo (0.6.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
  typhoeus
@@ -34,9 +34,9 @@ GEM
34
34
  json (2.3.0)
35
35
  multipart-post (2.1.1)
36
36
  parallel (1.19.1)
37
- parser (2.7.1.0)
37
+ parser (2.7.1.2)
38
38
  ast (~> 2.4.0)
39
- public_suffix (4.0.4)
39
+ public_suffix (4.0.5)
40
40
  rainbow (3.0.0)
41
41
  rake (12.3.3)
42
42
  rexml (3.2.4)
@@ -44,15 +44,15 @@ GEM
44
44
  rspec-core (~> 3.9.0)
45
45
  rspec-expectations (~> 3.9.0)
46
46
  rspec-mocks (~> 3.9.0)
47
- rspec-core (3.9.1)
48
- rspec-support (~> 3.9.1)
49
- rspec-expectations (3.9.1)
47
+ rspec-core (3.9.2)
48
+ rspec-support (~> 3.9.3)
49
+ rspec-expectations (3.9.2)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.9.0)
52
52
  rspec-mocks (3.9.1)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
54
  rspec-support (~> 3.9.0)
55
- rspec-support (3.9.2)
55
+ rspec-support (3.9.3)
56
56
  rubocop (0.81.0)
57
57
  jaro_winkler (~> 1.5.1)
58
58
  parallel (~> 1.10)
@@ -61,7 +61,7 @@ GEM
61
61
  rexml
62
62
  ruby-progressbar (~> 1.7)
63
63
  unicode-display_width (>= 1.4.0, < 2.0)
64
- rubocop-rspec (1.38.1)
64
+ rubocop-rspec (1.39.0)
65
65
  rubocop (>= 0.68.1)
66
66
  ruby-progressbar (1.10.1)
67
67
  safe_yaml (1.0.5)
@@ -74,9 +74,9 @@ GEM
74
74
  term-ansicolor (1.7.1)
75
75
  tins (~> 1.0)
76
76
  thor (1.0.1)
77
- tins (1.24.1)
77
+ tins (1.25.0)
78
78
  sync
79
- typhoeus (1.3.1)
79
+ typhoeus (1.4.0)
80
80
  ethon (>= 0.9.0)
81
81
  unicode-display_width (1.7.0)
82
82
  webmock (3.8.3)
@@ -75,10 +75,22 @@ module Belvo
75
75
  @tax_returns = TaxReturn.new @session
76
76
  end
77
77
 
78
+ # Provides access to TaxStatus resource
79
+ # @return [TaxStatus]
80
+ def tax_status
81
+ @tax_status = TaxStatus.new @session
82
+ end
83
+
78
84
  # Provides access to Instituions resource
79
85
  # @return [Institution]
80
86
  def institutions
81
87
  @institutions = Institution.new @session
82
88
  end
89
+
90
+ # Provides access to WidgetToken resource
91
+ # @return [WidgetToken]
92
+ def widget_token
93
+ @widget_token = WidgetToken.new @session
94
+ end
83
95
  end
84
96
  end
@@ -11,6 +11,9 @@ require 'belvo/exceptions'
11
11
  module Belvo
12
12
  # Describes a Belvo API session
13
13
  class APISession
14
+ attr_reader :key_id
15
+ attr_reader :key_password
16
+
14
17
  # @param url [String] Belvo API host url
15
18
  # @return [Faraday::Connection]
16
19
  def initialize(url)
@@ -8,10 +8,14 @@ module Belvo
8
8
  # @!attribute access_mode [rw] Link access mode (SINGLE or RECURRENT)
9
9
  # @!attribute token [rw] OTP token required by the institution
10
10
  # @!attribute encryption_key [rw] Custom encryption key
11
+ # @!attribute username_type [rw] Type of the username provided
11
12
  class LinkOptions < Faraday::Options.new(
12
13
  :access_mode,
13
14
  :token,
14
- :encryption_key
15
+ :encryption_key,
16
+ :username_type,
17
+ :certificate,
18
+ :private_key
15
19
  )
16
20
  end
17
21
 
@@ -111,4 +115,19 @@ module Belvo
111
115
  :attach_pdf
112
116
  )
113
117
  end
118
+
119
+ # @!class TaxStatusOptions < Faraday::Options
120
+ # Contains configurable properties of a TaxStatus
121
+ # @!attribute save_data [rw] Should data be persisted or not.
122
+ # @!attribute token [rw] OTP token required by the institution
123
+ # @!attribute encryption_key [rw] Custom encryption key
124
+ # @!attribute attach_pdf [rw] Should the PDF file be included in the
125
+ # response or not.
126
+ class TaxStatusOptions < Faraday::Options.new(
127
+ :token,
128
+ :encryption_key,
129
+ :save_data,
130
+ :attach_pdf
131
+ )
132
+ end
114
133
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'date'
4
4
  require 'belvo/options'
5
+ require 'belvo/utils'
5
6
 
6
7
  module Belvo
7
8
  # Represents a consumable REST resource from Belvo API
@@ -23,11 +24,12 @@ module Belvo
23
24
  end
24
25
 
25
26
  # List all results
27
+ # @param params [Hash] Extra parameters sent as query strings.
26
28
  # @return [Array]
27
29
  # @raise [RequestError] If response code is different than 2XX
28
- def list
30
+ def list(params: nil)
29
31
  results = []
30
- @session.list(@endpoint) { |item| results.push item }
32
+ @session.list(@endpoint, params: params) { |item| results.push item }
31
33
  results
32
34
  end
33
35
 
@@ -87,6 +89,8 @@ module Belvo
87
89
  options: nil
88
90
  )
89
91
  options = LinkOptions.from(options)
92
+ options.certificate = Utils.read_file_to_b64(options.certificate)
93
+ options.private_key = Utils.read_file_to_b64(options.private_key)
90
94
  body = {
91
95
  institution: institution,
92
96
  username: username,
@@ -94,7 +98,10 @@ module Belvo
94
98
  password2: password2,
95
99
  token: options.token,
96
100
  encryption_key: options.encryption_key,
97
- access_mode: options.access_mode || AccessMode::SINGLE
101
+ access_mode: options.access_mode || AccessMode::SINGLE,
102
+ username_type: options.username_type,
103
+ certificate: options.certificate,
104
+ private_key: options.private_key
98
105
  }.merge(options)
99
106
  body = clean body: body
100
107
  @session.post(@endpoint, body)
@@ -107,13 +114,18 @@ module Belvo
107
114
  # @param options [LinkOptions] Configurable properties
108
115
  # @return [Hash] link details
109
116
  # @raise [RequestError] If response code is different than 2XX
110
- def update(id:, password:, password2: nil, options: nil)
117
+ def update(id:, password: nil, password2: nil, options: nil)
111
118
  options = LinkOptions.from(options)
119
+ options.certificate = Utils.read_file_to_b64(options.certificate)
120
+ options.private_key = Utils.read_file_to_b64(options.private_key)
112
121
  body = {
113
122
  password: password,
114
123
  password2: password2,
115
124
  token: options.token,
116
- encryption_key: options.encryption_key
125
+ encryption_key: options.encryption_key,
126
+ username_type: options.username_type,
127
+ certificate: options.certificate,
128
+ private_key: options.private_key
117
129
  }.merge(options)
118
130
  body = clean body: body
119
131
  @session.put(@endpoint, id, body)
@@ -131,7 +143,7 @@ module Belvo
131
143
  # Retrieve accounts from an existing link
132
144
  # @param link [String] Link UUID
133
145
  # @param options [AccountOptions] Configurable properties
134
- # @return [Hash] created link details
146
+ # @return [Hash] created accounts details
135
147
  # @raise [RequestError] If response code is different than 2XX
136
148
  def retrieve(link:, options: nil)
137
149
  options = AccountOptions.from(options)
@@ -158,7 +170,7 @@ module Belvo
158
170
  # @param link [String] Link UUID
159
171
  # @param date_from [String] Date string (YYYY-MM-DD)
160
172
  # @param options [TransactionOptions] Configurable properties
161
- # @return [Hash] created link details
173
+ # @return [Hash] created transactions details
162
174
  # @raise [RequestError] If response code is different than 2XX
163
175
  def retrieve(link:, date_from:, options: nil)
164
176
  options = TransactionOptions.from(options)
@@ -188,7 +200,7 @@ module Belvo
188
200
  # Retrieve owners from an existing link
189
201
  # @param link [String] Link UUID
190
202
  # @param options [OwnerOptions] Configurable properties
191
- # @return [Hash] created link details
203
+ # @return [Hash] created owners details
192
204
  # @raise [RequestError] If response code is different than 2XX
193
205
  def retrieve(link:, options: nil)
194
206
  options = OwnerOptions.from(options)
@@ -215,7 +227,7 @@ module Belvo
215
227
  # @param link [String] Link UUID
216
228
  # @param date_from [String] Date string (YYYY-MM-DD)
217
229
  # @param options [BalanceOptions] Configurable properties
218
- # @return [Hash] created link details
230
+ # @return [Hash] created balances details
219
231
  # @raise [RequestError] If response code is different than 2XX
220
232
  def retrieve(link:, date_from:, options: nil)
221
233
  options = BalanceOptions.from(options)
@@ -246,7 +258,7 @@ module Belvo
246
258
  # @param year [Integer]
247
259
  # @param month [Integer]
248
260
  # @param options [StatementOptions] Configurable properties
249
- # @return [Hash] created link details
261
+ # @return [Hash] created statement details
250
262
  # @raise [RequestError] If response code is different than 2XX
251
263
  def retrieve(link:, account:, year:, month:, options: nil)
252
264
  options = StatementOptions.from(options)
@@ -278,7 +290,7 @@ module Belvo
278
290
  # @param date_from [String] Date string (YYYY-MM-DD)
279
291
  # @param date_to [String] Date string (YYYY-MM-DD)
280
292
  # @param options [InvoiceOptions] Configurable properties
281
- # @return [Hash] created link details
293
+ # @return [Hash] created invoices details
282
294
  # @raise [RequestError] If response code is different than 2XX
283
295
  def retrieve(link:, date_from:, date_to:, type:, options: nil)
284
296
  options = InvoiceOptions.from(options)
@@ -310,7 +322,7 @@ module Belvo
310
322
  # @param year_from [Integer]
311
323
  # @param year_to [Integer]
312
324
  # @param options [TaxReturnOptions] Configurable properties
313
- # @return [Hash] created link details
325
+ # @return [Hash] created tax returns details
314
326
  # @raise [RequestError] If response code is different than 2XX
315
327
  def retrieve(link:, year_from:, year_to:, options: nil)
316
328
  options = TaxReturnOptions.from(options)
@@ -332,6 +344,37 @@ module Belvo
332
344
  end
333
345
  end
334
346
 
347
+ # A Tax status is the representation of the tax situation of a person or a
348
+ # business to the tax authority in the country.
349
+ class TaxStatus < Resource
350
+ def initialize(session)
351
+ super(session)
352
+ @endpoint = 'tax-status/'
353
+ end
354
+
355
+ # Retrieve tax status information from a specific fiscal link.
356
+ # @param link [String] Link UUID
357
+ # @param options [TaxStatusOptions] Configurable properties
358
+ # @return [Hash] created tax status details
359
+ # @raise [RequestError] If response code is different than 2XX
360
+ def retrieve(link:, options: nil)
361
+ options = TaxStatusOptions.from(options)
362
+ body = {
363
+ link: link,
364
+ token: options.token,
365
+ encryption_key: options.encryption_key,
366
+ save_data: options.save_data || true,
367
+ attach_pdf: options.attach_pdf
368
+ }.merge(options)
369
+ body = clean body: body
370
+ @session.post(@endpoint, body)
371
+ end
372
+
373
+ def resume(_session_id, _token, _link: nil)
374
+ raise NotImplementedError 'TaxReturn does not support resuming a session.'
375
+ end
376
+ end
377
+
335
378
  # An Institution is an entity that Belvo can access information from. It can
336
379
  # be a bank or fiscal type of institutions such as the SAT in Mexico.
337
380
  class Institution < Resource
@@ -340,4 +383,23 @@ module Belvo
340
383
  @endpoint = 'institutions/'
341
384
  end
342
385
  end
386
+
387
+ # A WidgetToken is a limited scope with short time to live token, that
388
+ # contains access and refresh keys to allow you embedding Belvo's Connect
389
+ # Widget into your app.
390
+ class WidgetToken < Resource
391
+ def initialize(session)
392
+ super(session)
393
+ @endpoint = 'token/'
394
+ end
395
+
396
+ def create
397
+ body = {
398
+ id: @session.key_id,
399
+ password: @session.key_password,
400
+ scopes: 'read_institutions,write_links,read_links,delete_links'
401
+ }
402
+ @session.post(@endpoint, body)
403
+ end
404
+ end
343
405
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'base64'
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)
9
+
10
+ data = File.open(path).read
11
+ Base64.encode64(data)
12
+ end
13
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Belvo
4
4
  # belvo-ruby current version
5
- VERSION = '0.3.0'
5
+ VERSION = '0.6.0'
6
6
  end
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.3.0
4
+ version: 0.6.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: 2020-04-09 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -146,6 +146,7 @@ executables: []
146
146
  extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
+ - ".codeclimate.yml"
149
150
  - ".github/ISSUE_TEMPLATE/feature_request.md"
150
151
  - ".github/pull_request_template.md"
151
152
  - ".gitignore"
@@ -166,6 +167,7 @@ files:
166
167
  - lib/belvo/http.rb
167
168
  - lib/belvo/options.rb
168
169
  - lib/belvo/resources.rb
170
+ - lib/belvo/utils.rb
169
171
  - lib/belvo/version.rb
170
172
  homepage: https://github.com/belvo-finance/belvo-ruby
171
173
  licenses:
@@ -189,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
191
  - !ruby/object:Gem::Version
190
192
  version: '0'
191
193
  requirements: []
192
- rubygems_version: 3.0.6
194
+ rubygems_version: 3.1.2
193
195
  signing_key:
194
196
  specification_version: 4
195
197
  summary: The Ruby gem for the Belvo API