belvo 0.3.1 → 0.6.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: 50dc56e84a0e3da9460063b4d5589044ad4d88d29f8182ac21d106953e169d55
4
- data.tar.gz: 50d11079afd1b518d03e30b75d5b1dc5a44e725d7c449cf0036ecc36294a404e
3
+ metadata.gz: 8746f7636ac5bd7c67d0041ec84aa9240d9477687d98f826c28ea22135beb9c7
4
+ data.tar.gz: 91849cb78edce6d00eb636c29334b6eb4c958cf4e089ce734e5bda2f74fe3f54
5
5
  SHA512:
6
- metadata.gz: '01414806db87f0512b9c8fe0ff9c611e2e248edb18c24a368173b35b439da0a7fa10b29e25d8e5c86048e4b67936e1d2359b886d94cb2a55ffb558bcc05f1cb0'
7
- data.tar.gz: 97053b093f9ac116decbad414b859da65de6b3ee2d18a53dfca5bd896db2a302be3c15f8d3c2823d144d7078ab14f92d09775cc16e1249d24e2113c3cf081c42
6
+ metadata.gz: 7e9f1c00f82387e356be66ce824cf97b0eb11472e8eb738e5e5db759317e957b9908238187f199b74844587fac9db3f4f4854c7eaf855b58cbf46ee1a395c886
7
+ data.tar.gz: 4d88c38fca8ca0e206844f7e0bedd33b323e6fba76f14cc30aa1adee405d252978cd373282952dacb581aede77af9b6db8046078e90c054545b6af88e179bbed
@@ -1,4 +1,3 @@
1
- ---
2
1
  language: ruby
3
2
  cache: bundler
4
3
  rvm:
@@ -7,3 +6,12 @@ before_install: gem install bundler -v 2.1.4
7
6
  script:
8
7
  - bundle exec rubocop
9
8
  - bundle exec rspec spec
9
+ deploy:
10
+ provider: rubygems
11
+ api_key:
12
+ secure: nsKurIEds1W6zwyj0mDmYx77amlDJOycegZV9o+OrBOzRRcpT+O3oFHGouMzAQyIbdUtmWyXp9uJHBEz7Q6Zc5fy6iG05sGO7tFoJMlKiPE5piiOTM5y6qt1GjZ1MYIU0rpnsp9QDsVUR1ATGpoD9O/zzn/lOPbxp2FoWHqWra84D/1jvVXPTqslLgup+GDsxseiAfwTMoTy65TXodISkvoYtlPL3EBV4/XQVBjVGGtM5mdjDJg+YA4yVA2NwCCjhFcj88fRxBmqWRnG/pzmX3nyRlMGjtUBm8OpLSR1NiXXqgzYUAVMD8/8VL/h3OsBqvwqgjZKMO6rXqNKFJQAxYUqvJaLcHP8D05dxWlumqwxlHzscKWLjAe7JbVo2DiAMvMTR8NTJOI7LOraU10iFHtmwAVnyBOaSJUVJuFgAoybq9tqYoZ/uZ7shCuWVNUIWIQM7HN9v99tfvemXMB+2RIN565bzBWSorn5MvXsApvqCLLDFuRnt7urR+0ZyT4dKXgvWRhnNOQgiMwEE/8+Y66nKVB7iNxFDw6LtittyoOZ0HvbHQDtqXOkzT/yaq2Ff2zwuUNYrCHqcdnxg5TBOYg5ndurcFxAc77ZlNSvidEC9tgXHA1m+r0Vq+ZCWOiyyohX33ZfA/UsAIStKr7a6ZLZZywuiqXasg1O9XoRB74=
13
+ gem: belvo
14
+ on:
15
+ tags: true
16
+ repo: belvo-finance/belvo-ruby
17
+ skip_cleanup: 'true'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- belvo (0.3.1)
4
+ belvo (0.6.1)
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)
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'belvo'
7
7
  spec.version = Belvo::VERSION
8
8
  spec.authors = ['Belvo Finance S.L.']
9
- spec.email = ['hello@belvo.co']
9
+ spec.email = ['sdks@belvo.co']
10
10
  spec.license = 'MIT'
11
11
  spec.summary = 'The Ruby gem for the Belvo API'
12
12
  spec.description = %(Belvo is the leading Open Banking API platform in Latin
@@ -63,6 +63,12 @@ module Belvo
63
63
  @statements = Statement.new @session
64
64
  end
65
65
 
66
+ # Provides access to Incomes resource
67
+ # @return [Income]
68
+ def incomes
69
+ @incomes = Income.new @session
70
+ end
71
+
66
72
  # Provides access to Invoices resource
67
73
  # @return [Invoice]
68
74
  def invoices
@@ -75,10 +81,22 @@ module Belvo
75
81
  @tax_returns = TaxReturn.new @session
76
82
  end
77
83
 
84
+ # Provides access to TaxStatus resource
85
+ # @return [TaxStatus]
86
+ def tax_status
87
+ @tax_status = TaxStatus.new @session
88
+ end
89
+
78
90
  # Provides access to Instituions resource
79
91
  # @return [Institution]
80
92
  def institutions
81
93
  @institutions = Institution.new @session
82
94
  end
95
+
96
+ # Provides access to WidgetToken resource
97
+ # @return [WidgetToken]
98
+ def widget_token
99
+ @widget_token = WidgetToken.new @session
100
+ end
83
101
  end
84
102
  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)
@@ -7,11 +7,19 @@ module Belvo
7
7
  # Contains the configurable properties for a Link
8
8
  # @!attribute access_mode [rw] Link access mode (SINGLE or RECURRENT)
9
9
  # @!attribute token [rw] OTP token required by the institution
10
+ # @!attribute username2 [rw] End-user secondary username, if any
11
+ # @!attribute password2 [rw] End-user secondary password, if any
10
12
  # @!attribute encryption_key [rw] Custom encryption key
13
+ # @!attribute username_type [rw] Type of the username provided
11
14
  class LinkOptions < Faraday::Options.new(
12
15
  :access_mode,
13
16
  :token,
14
- :encryption_key
17
+ :username2,
18
+ :password2,
19
+ :encryption_key,
20
+ :username_type,
21
+ :certificate,
22
+ :private_key
15
23
  )
16
24
  end
17
25
 
@@ -82,6 +90,16 @@ module Belvo
82
90
  )
83
91
  end
84
92
 
93
+ # @!class IncomeOptions < Faraday::Options
94
+ # Contains configurable properties of an Income
95
+ # @!attribute save_data [rw] Should data be persisted or not.
96
+ # @!attribute encryption_key [rw] Custom encryption key
97
+ class IncomeOptions < Faraday::Options.new(
98
+ :encryption_key,
99
+ :save_data
100
+ )
101
+ end
102
+
85
103
  # @!class InvoiceOptions < Faraday::Options
86
104
  # Contains configurable properties of an Invoice
87
105
  # @!attribute save_data [rw] Should data be persisted or not.
@@ -111,4 +129,19 @@ module Belvo
111
129
  :attach_pdf
112
130
  )
113
131
  end
132
+
133
+ # @!class TaxStatusOptions < Faraday::Options
134
+ # Contains configurable properties of a TaxStatus
135
+ # @!attribute save_data [rw] Should data be persisted or not.
136
+ # @!attribute token [rw] OTP token required by the institution
137
+ # @!attribute encryption_key [rw] Custom encryption key
138
+ # @!attribute attach_pdf [rw] Should the PDF file be included in the
139
+ # response or not.
140
+ class TaxStatusOptions < Faraday::Options.new(
141
+ :token,
142
+ :encryption_key,
143
+ :save_data,
144
+ :attach_pdf
145
+ )
146
+ end
114
147
  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
@@ -76,7 +77,6 @@ module Belvo
76
77
  # @param institution [String] Institution name
77
78
  # @param username [String] End-user username
78
79
  # @param password [String] End-user password
79
- # @param password2 [String, nil] End-user secondary password, if any
80
80
  # @param options [LinkOptions] Configurable properties
81
81
  # @return [Hash] created link details
82
82
  # @raise [RequestError] If response code is different than 2XX
@@ -84,17 +84,15 @@ module Belvo
84
84
  institution:,
85
85
  username:,
86
86
  password:,
87
- password2: nil,
88
87
  options: nil
89
88
  )
90
89
  options = LinkOptions.from(options)
90
+ options.certificate = Utils.read_file_to_b64(options.certificate)
91
+ options.private_key = Utils.read_file_to_b64(options.private_key)
91
92
  body = {
92
93
  institution: institution,
93
94
  username: username,
94
95
  password: password,
95
- password2: password2,
96
- token: options.token,
97
- encryption_key: options.encryption_key,
98
96
  access_mode: options.access_mode || AccessMode::SINGLE
99
97
  }.merge(options)
100
98
  body = clean body: body
@@ -108,13 +106,18 @@ module Belvo
108
106
  # @param options [LinkOptions] Configurable properties
109
107
  # @return [Hash] link details
110
108
  # @raise [RequestError] If response code is different than 2XX
111
- def update(id:, password:, password2: nil, options: nil)
109
+ def update(id:, password: nil, password2: nil, options: nil)
112
110
  options = LinkOptions.from(options)
111
+ options.certificate = Utils.read_file_to_b64(options.certificate)
112
+ options.private_key = Utils.read_file_to_b64(options.private_key)
113
113
  body = {
114
114
  password: password,
115
115
  password2: password2,
116
116
  token: options.token,
117
- encryption_key: options.encryption_key
117
+ encryption_key: options.encryption_key,
118
+ username_type: options.username_type,
119
+ certificate: options.certificate,
120
+ private_key: options.private_key
118
121
  }.merge(options)
119
122
  body = clean body: body
120
123
  @session.put(@endpoint, id, body)
@@ -132,7 +135,7 @@ module Belvo
132
135
  # Retrieve accounts from an existing link
133
136
  # @param link [String] Link UUID
134
137
  # @param options [AccountOptions] Configurable properties
135
- # @return [Hash] created link details
138
+ # @return [Hash] created accounts details
136
139
  # @raise [RequestError] If response code is different than 2XX
137
140
  def retrieve(link:, options: nil)
138
141
  options = AccountOptions.from(options)
@@ -159,7 +162,7 @@ module Belvo
159
162
  # @param link [String] Link UUID
160
163
  # @param date_from [String] Date string (YYYY-MM-DD)
161
164
  # @param options [TransactionOptions] Configurable properties
162
- # @return [Hash] created link details
165
+ # @return [Hash] created transactions details
163
166
  # @raise [RequestError] If response code is different than 2XX
164
167
  def retrieve(link:, date_from:, options: nil)
165
168
  options = TransactionOptions.from(options)
@@ -189,7 +192,7 @@ module Belvo
189
192
  # Retrieve owners from an existing link
190
193
  # @param link [String] Link UUID
191
194
  # @param options [OwnerOptions] Configurable properties
192
- # @return [Hash] created link details
195
+ # @return [Hash] created owners details
193
196
  # @raise [RequestError] If response code is different than 2XX
194
197
  def retrieve(link:, options: nil)
195
198
  options = OwnerOptions.from(options)
@@ -216,7 +219,7 @@ module Belvo
216
219
  # @param link [String] Link UUID
217
220
  # @param date_from [String] Date string (YYYY-MM-DD)
218
221
  # @param options [BalanceOptions] Configurable properties
219
- # @return [Hash] created link details
222
+ # @return [Hash] created balances details
220
223
  # @raise [RequestError] If response code is different than 2XX
221
224
  def retrieve(link:, date_from:, options: nil)
222
225
  options = BalanceOptions.from(options)
@@ -247,7 +250,7 @@ module Belvo
247
250
  # @param year [Integer]
248
251
  # @param month [Integer]
249
252
  # @param options [StatementOptions] Configurable properties
250
- # @return [Hash] created link details
253
+ # @return [Hash] created statement details
251
254
  # @raise [RequestError] If response code is different than 2XX
252
255
  def retrieve(link:, account:, year:, month:, options: nil)
253
256
  options = StatementOptions.from(options)
@@ -266,6 +269,30 @@ module Belvo
266
269
  end
267
270
  end
268
271
 
272
+ # A Income contains a resume of monthly Transactions inside an Account.
273
+ class Income < Resource
274
+ def initialize(session)
275
+ super(session)
276
+ @endpoint = 'incomes/'
277
+ end
278
+
279
+ # Retrieve incomes information from a specific banking link.
280
+ # @param link [String] Link UUID
281
+ # @param options [IncomesOptions] Configurable properties
282
+ # @return [Hash] created incomes details
283
+ # @raise [RequestError] If response code is different than 2XX
284
+ def retrieve(link:, options: nil)
285
+ options = IncomeOptions.from(options)
286
+ body = {
287
+ link: link,
288
+ encryption_key: options.encryption_key,
289
+ save_data: options.save_data || true
290
+ }.merge(options)
291
+ body = clean body: body
292
+ @session.post(@endpoint, body)
293
+ end
294
+ end
295
+
269
296
  # An Invoice is the representation of an electronic invoice, that can be
270
297
  # received or sent, by a business or an individual and has been uploaded
271
298
  # to the fiscal institution website
@@ -279,7 +306,7 @@ module Belvo
279
306
  # @param date_from [String] Date string (YYYY-MM-DD)
280
307
  # @param date_to [String] Date string (YYYY-MM-DD)
281
308
  # @param options [InvoiceOptions] Configurable properties
282
- # @return [Hash] created link details
309
+ # @return [Hash] created invoices details
283
310
  # @raise [RequestError] If response code is different than 2XX
284
311
  def retrieve(link:, date_from:, date_to:, type:, options: nil)
285
312
  options = InvoiceOptions.from(options)
@@ -311,7 +338,7 @@ module Belvo
311
338
  # @param year_from [Integer]
312
339
  # @param year_to [Integer]
313
340
  # @param options [TaxReturnOptions] Configurable properties
314
- # @return [Hash] created link details
341
+ # @return [Hash] created tax returns details
315
342
  # @raise [RequestError] If response code is different than 2XX
316
343
  def retrieve(link:, year_from:, year_to:, options: nil)
317
344
  options = TaxReturnOptions.from(options)
@@ -333,6 +360,37 @@ module Belvo
333
360
  end
334
361
  end
335
362
 
363
+ # A Tax status is the representation of the tax situation of a person or a
364
+ # business to the tax authority in the country.
365
+ class TaxStatus < Resource
366
+ def initialize(session)
367
+ super(session)
368
+ @endpoint = 'tax-status/'
369
+ end
370
+
371
+ # Retrieve tax status information from a specific fiscal link.
372
+ # @param link [String] Link UUID
373
+ # @param options [TaxStatusOptions] Configurable properties
374
+ # @return [Hash] created tax status details
375
+ # @raise [RequestError] If response code is different than 2XX
376
+ def retrieve(link:, options: nil)
377
+ options = TaxStatusOptions.from(options)
378
+ body = {
379
+ link: link,
380
+ token: options.token,
381
+ encryption_key: options.encryption_key,
382
+ save_data: options.save_data || true,
383
+ attach_pdf: options.attach_pdf
384
+ }.merge(options)
385
+ body = clean body: body
386
+ @session.post(@endpoint, body)
387
+ end
388
+
389
+ def resume(_session_id, _token, _link: nil)
390
+ raise NotImplementedError 'TaxReturn does not support resuming a session.'
391
+ end
392
+ end
393
+
336
394
  # An Institution is an entity that Belvo can access information from. It can
337
395
  # be a bank or fiscal type of institutions such as the SAT in Mexico.
338
396
  class Institution < Resource
@@ -341,4 +399,23 @@ module Belvo
341
399
  @endpoint = 'institutions/'
342
400
  end
343
401
  end
402
+
403
+ # A WidgetToken is a limited scope with short time to live token, that
404
+ # contains access and refresh keys to allow you embedding Belvo's Connect
405
+ # Widget into your app.
406
+ class WidgetToken < Resource
407
+ def initialize(session)
408
+ super(session)
409
+ @endpoint = 'token/'
410
+ end
411
+
412
+ def create
413
+ body = {
414
+ id: @session.key_id,
415
+ password: @session.key_password,
416
+ scopes: 'read_institutions,write_links,read_links,delete_links'
417
+ }
418
+ @session.post(@endpoint, body)
419
+ end
420
+ end
344
421
  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.1'
5
+ VERSION = '0.6.1'
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.1
4
+ version: 0.6.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: 2020-04-09 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -141,7 +141,7 @@ description: |-
141
141
  America and the easiest way for users to connect their
142
142
  account to an app
143
143
  email:
144
- - hello@belvo.co
144
+ - sdks@belvo.co
145
145
  executables: []
146
146
  extensions: []
147
147
  extra_rdoc_files: []
@@ -167,6 +167,7 @@ files:
167
167
  - lib/belvo/http.rb
168
168
  - lib/belvo/options.rb
169
169
  - lib/belvo/resources.rb
170
+ - lib/belvo/utils.rb
170
171
  - lib/belvo/version.rb
171
172
  homepage: https://github.com/belvo-finance/belvo-ruby
172
173
  licenses:
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
192
193
  requirements: []
193
- rubygems_version: 3.0.6
194
+ rubygems_version: 3.0.8
194
195
  signing_key:
195
196
  specification_version: 4
196
197
  summary: The Ruby gem for the Belvo API