belvo 0.4.1 → 0.6.3

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: aa4fbcb0144298783943d06abf59f004483704a3677efc1ab61bfdf0e7c2d1c6
4
- data.tar.gz: 56df1994b401363be388f902af16b4ddd7100306ae59a922895910d5a3160fa3
3
+ metadata.gz: b549a9348810743f778ef07fb248f62c4aba55dbc95635c8696f9db4d0cf6f81
4
+ data.tar.gz: 817209595c82f407f57ddc8e8f7e22ecd356f83537245d2d8e4ac880095924c1
5
5
  SHA512:
6
- metadata.gz: c92cf94deeae258a916c89ae61f8dfdd2436fb22c8f9d14ff55ee8b34ad7197d07b8d3fb13fe7fc34f105182b25d8232b78f7d759f3a4dbd2b9737767066b182
7
- data.tar.gz: caccc705af819123b0a613e988a6cf55094b45e3830b7afb925e721dd9c9787ef51626c596402bbd66d1f030ccc60fd6fe4b4b65dbea034d62478c37d29b66df
6
+ metadata.gz: a4b73cdfdb9881f883bf7a916295558ef84adcaf9cce3dd6179cf2275494b8d0f3e87a31319493112a50ce474fa6358de4a759d52437bdb4fdcbf26edeefa3b9
7
+ data.tar.gz: ec2c9e7bbb340a53d6424c1f37c4e81d5b4dbc3b526903ef2d1b0c481f4887f9f7363e361e764cb6a5b03dd40c1290ef8b6416c43ebe06b32d91415b2a5dfd8d
@@ -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.4.1)
4
+ belvo (0.6.3)
5
5
  faraday
6
6
  faraday_middleware
7
7
  typhoeus
@@ -11,48 +11,48 @@ GEM
11
11
  specs:
12
12
  addressable (2.7.0)
13
13
  public_suffix (>= 2.0.2, < 5.0)
14
- ast (2.4.0)
14
+ ast (2.4.1)
15
15
  coveralls (0.8.23)
16
16
  json (>= 1.8, < 3)
17
17
  simplecov (~> 0.16.1)
18
18
  term-ansicolor (~> 1.3)
19
19
  thor (>= 0.19.4, < 2.0)
20
20
  tins (~> 1.6)
21
- crack (0.4.3)
22
- safe_yaml (~> 1.0.0)
23
- diff-lcs (1.3)
21
+ crack (0.4.4)
22
+ diff-lcs (1.4.4)
24
23
  docile (1.3.2)
25
24
  ethon (0.12.0)
26
25
  ffi (>= 1.3.0)
27
- faraday (1.0.1)
26
+ faraday (1.1.0)
28
27
  multipart-post (>= 1.2, < 3)
28
+ ruby2_keywords
29
29
  faraday_middleware (1.0.0)
30
30
  faraday (~> 1.0)
31
- ffi (1.12.2)
31
+ ffi (1.13.1)
32
32
  hashdiff (1.0.1)
33
33
  jaro_winkler (1.5.4)
34
- json (2.3.0)
34
+ json (2.3.1)
35
35
  multipart-post (2.1.1)
36
- parallel (1.19.1)
37
- parser (2.7.1.1)
38
- ast (~> 2.4.0)
39
- public_suffix (4.0.4)
36
+ parallel (1.20.0)
37
+ parser (2.7.2.0)
38
+ ast (~> 2.4.1)
39
+ public_suffix (4.0.6)
40
40
  rainbow (3.0.0)
41
41
  rake (12.3.3)
42
42
  rexml (3.2.4)
43
- rspec (3.9.0)
44
- rspec-core (~> 3.9.0)
45
- rspec-expectations (~> 3.9.0)
46
- rspec-mocks (~> 3.9.0)
47
- rspec-core (3.9.1)
48
- rspec-support (~> 3.9.1)
49
- rspec-expectations (3.9.1)
43
+ rspec (3.10.0)
44
+ rspec-core (~> 3.10.0)
45
+ rspec-expectations (~> 3.10.0)
46
+ rspec-mocks (~> 3.10.0)
47
+ rspec-core (3.10.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-expectations (3.10.0)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-mocks (3.9.1)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-mocks (3.10.0)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.9.0)
55
- rspec-support (3.9.2)
54
+ rspec-support (~> 3.10.0)
55
+ rspec-support (3.10.0)
56
56
  rubocop (0.81.0)
57
57
  jaro_winkler (~> 1.5.1)
58
58
  parallel (~> 1.10)
@@ -61,10 +61,10 @@ 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.41.0)
65
65
  rubocop (>= 0.68.1)
66
66
  ruby-progressbar (1.10.1)
67
- safe_yaml (1.0.5)
67
+ ruby2_keywords (0.0.2)
68
68
  simplecov (0.16.1)
69
69
  docile (~> 1.1)
70
70
  json (>= 1.8, < 3)
@@ -74,12 +74,12 @@ 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.26.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
- webmock (3.8.3)
82
+ webmock (3.9.5)
83
83
  addressable (>= 2.3.6)
84
84
  crack (>= 0.3.2)
85
85
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -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
@@ -86,5 +92,11 @@ module Belvo
86
92
  def institutions
87
93
  @institutions = Institution.new @session
88
94
  end
95
+
96
+ # Provides access to WidgetToken resource
97
+ # @return [WidgetToken]
98
+ def widget_token
99
+ @widget_token = WidgetToken.new @session
100
+ end
89
101
  end
90
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)
@@ -117,6 +120,19 @@ module Belvo
117
120
  response.body
118
121
  end
119
122
 
123
+ # Perform a POST request to an API endpoint
124
+ # @param path [String] API endpoint
125
+ # @param id [String] Resource UUID
126
+ # @param data [object] JSON parseable object
127
+ # @return [Hash] Response details
128
+ # @raise [RequestError] If response code is different than 2XX
129
+ def token(path, id, data)
130
+ resource_path = format('%<path>s%<id>s/token/', path: path, id: id)
131
+ response = @session.post(resource_path, data.to_json)
132
+ raise_for_status response
133
+ response.body
134
+ end
135
+
120
136
  # Perform a POST request to an API endpoint
121
137
  # @param path [String] API endpoint
122
138
  # @param data [object] JSON parseable object
@@ -7,13 +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
11
13
  # @!attribute username_type [rw] Type of the username provided
12
14
  class LinkOptions < Faraday::Options.new(
13
15
  :access_mode,
14
16
  :token,
17
+ :username2,
18
+ :password2,
15
19
  :encryption_key,
16
- :username_type
20
+ :username_type,
21
+ :certificate,
22
+ :private_key
17
23
  )
18
24
  end
19
25
 
@@ -84,6 +90,16 @@ module Belvo
84
90
  )
85
91
  end
86
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
+
87
103
  # @!class InvoiceOptions < Faraday::Options
88
104
  # Contains configurable properties of an Invoice
89
105
  # @!attribute save_data [rw] Should data be persisted or not.
@@ -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,19 +84,16 @@ 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
- access_mode: options.access_mode || AccessMode::SINGLE,
99
- username_type: options.username_type
96
+ access_mode: options.access_mode
100
97
  }.merge(options)
101
98
  body = clean body: body
102
99
  @session.post(@endpoint, body)
@@ -109,17 +106,34 @@ module Belvo
109
106
  # @param options [LinkOptions] Configurable properties
110
107
  # @return [Hash] link details
111
108
  # @raise [RequestError] If response code is different than 2XX
112
- def update(id:, password:, password2: nil, options: nil)
109
+ def update(id:, password: nil, password2: nil, options: nil)
113
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)
114
113
  body = {
115
114
  password: password,
116
115
  password2: password2,
117
116
  token: options.token,
118
- 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
119
121
  }.merge(options)
120
122
  body = clean body: body
121
123
  @session.put(@endpoint, id, body)
122
124
  end
125
+
126
+ # Allows to create a token with client-specified scope and short TTL.
127
+ # @param id [String] Link UUID
128
+ # @param scopes [String] Configurable scopes eg: "read_links,write_links"
129
+ # @return [Hash] with a "refresh" and "access" token
130
+ # @raise [RequestError] If response code is different than 2XX
131
+ def token(id:, scopes:)
132
+ body = {
133
+ scopes: scopes
134
+ }
135
+ @session.token(@endpoint, id, body)
136
+ end
123
137
  end
124
138
 
125
139
  # An Account is the representation of a bank account inside a financial
@@ -267,6 +281,30 @@ module Belvo
267
281
  end
268
282
  end
269
283
 
284
+ # A Income contains a resume of monthly Transactions inside an Account.
285
+ class Income < Resource
286
+ def initialize(session)
287
+ super(session)
288
+ @endpoint = 'incomes/'
289
+ end
290
+
291
+ # Retrieve incomes information from a specific banking link.
292
+ # @param link [String] Link UUID
293
+ # @param options [IncomesOptions] Configurable properties
294
+ # @return [Hash] created incomes details
295
+ # @raise [RequestError] If response code is different than 2XX
296
+ def retrieve(link:, options: nil)
297
+ options = IncomeOptions.from(options)
298
+ body = {
299
+ link: link,
300
+ encryption_key: options.encryption_key,
301
+ save_data: options.save_data || true
302
+ }.merge(options)
303
+ body = clean body: body
304
+ @session.post(@endpoint, body)
305
+ end
306
+ end
307
+
270
308
  # An Invoice is the representation of an electronic invoice, that can be
271
309
  # received or sent, by a business or an individual and has been uploaded
272
310
  # to the fiscal institution website
@@ -373,4 +411,23 @@ module Belvo
373
411
  @endpoint = 'institutions/'
374
412
  end
375
413
  end
414
+
415
+ # A WidgetToken is a limited scope with short time to live token, that
416
+ # contains access and refresh keys to allow you embedding Belvo's Connect
417
+ # Widget into your app.
418
+ class WidgetToken < Resource
419
+ def initialize(session)
420
+ super(session)
421
+ @endpoint = 'token/'
422
+ end
423
+
424
+ def create
425
+ body = {
426
+ id: @session.key_id,
427
+ password: @session.key_password,
428
+ scopes: 'read_institutions,write_links,read_links,delete_links'
429
+ }
430
+ @session.post(@endpoint, body)
431
+ end
432
+ end
376
433
  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.4.1'
5
+ VERSION = '0.6.3'
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.4.1
4
+ version: 0.6.3
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-28 00:00:00.000000000 Z
11
+ date: 2020-11-09 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,8 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
192
193
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.7.6
194
+ rubygems_version: 3.0.8
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: The Ruby gem for the Belvo API