bridge_bankin 0.1.0 → 0.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: dfe54b48509650b463422657a08f719b65ddbdd67f02c51acfb02cde720cf795
4
- data.tar.gz: 789e29bc5b5f95a3a9dac2954c17c95a5a5420cff9fffd45e46d4dde85bfa0ad
3
+ metadata.gz: 6ddf1d83e8ae1b1ced919dcc5858be9b8b331f25af05ff26824a462b36f6b240
4
+ data.tar.gz: 22c5bc8aa682d00956bc0f1bfe8c4c710f18626dfbc770ce01cee890603061d5
5
5
  SHA512:
6
- metadata.gz: 8808c5e9381f0b3c79cab3c93663561e1f4e8688c172b752a39e02885694b910f669a026822f134d2e9c741400e31438af592e2481b794fe044f9c312ca3d9b4
7
- data.tar.gz: 129b232bd2b76a61616deec2f430d1d3b59c3523f4cf802d36bf0ac142548124f40a648fb53f7f2b69e549cd629f6bfec196a478e5a6aa362432fcf94e310c3f
6
+ metadata.gz: b508b5d4c8d3572bd1db5f85282d9b6da7ca7c1a66b84a7acb5eecff2d94ec5d02791ac7421358085acd615aa65e8d65237a6d9ce603673121c0f3090c9705c8
7
+ data.tar.gz: fc7df99b3ea68557a473c27d5fd4f6404a3a2cab97cd4ff05cf613f759e8f843d94e9f0fc46213fd7030af231e3380bf11a9e4d06eb7e78dd8c282868c84540f
@@ -1,4 +1,4 @@
1
- name: Ruby
1
+ name: CI
2
2
 
3
3
  on:
4
4
  push:
@@ -16,9 +16,9 @@ jobs:
16
16
  - name: Set up Ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
19
- ruby-version: 2.7.2
19
+ ruby-version: 2.7
20
20
  - name: Run the default task
21
21
  run: |
22
- gem install bundler -v 2.2.1
22
+ gem install bundler
23
23
  bundle install
24
- bundle exec rake
24
+ bundle exec rspec
@@ -0,0 +1,44 @@
1
+ # .github/workflows/rubocop-analysis.yml
2
+ name: "RuboCop"
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - main
8
+ pull_request:
9
+ branches:
10
+ - "*"
11
+
12
+ jobs:
13
+ rubocop:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v2
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: 2.7
26
+
27
+ # This step is not necessary if you add the gem to your Gemfile
28
+ - name: Install Code Scanning integration
29
+ run: bundle add code-scanning-rubocop --skip-install
30
+
31
+ - name: Install dependencies
32
+ run: bundle install
33
+
34
+ - name: RuboCop run
35
+ run: |
36
+ bash -c "
37
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
38
+ [[ $? -ne 2 ]]
39
+ "
40
+
41
+ - name: Upload Sarif output
42
+ uses: github/codeql-action/upload-sarif@v1
43
+ with:
44
+ sarif_file: rubocop.sarif
data/.gitignore CHANGED
@@ -1,13 +1,10 @@
1
+ .env
2
+ .rspec_status
3
+ /_yardoc/
1
4
  /.bundle/
2
5
  /.yardoc
3
- /_yardoc/
4
6
  /coverage/
5
7
  /doc/
6
8
  /pkg/
7
9
  /spec/reports/
8
10
  /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- .env
@@ -17,9 +17,6 @@ Style/StringLiteralsInInterpolation:
17
17
  Layout/LineLength:
18
18
  Max: 120
19
19
 
20
- Style/Documentation:
21
- Enabled: false
22
-
23
20
  Metrics/BlockLength:
24
21
  Enabled: false
25
22
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bridge_bankin (0.1.0)
4
+ bridge_bankin (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Olivier Buffon
3
+ Copyright (c) 2020 Neatops
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,12 +1,19 @@
1
- # BridgeBankin
1
+ <p align="center">
2
+ <img width="500" src="https://user-images.githubusercontent.com/112219/103307983-5fe04500-49df-11eb-9618-1f9704b2f460.png">
3
+ </p>
2
4
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bridge_bankin`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ <br />
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ This gem is an **unofficial Ruby client** that consumes the [Bridge by Bankin’ API](https://bridgeapi.io/).
8
+
9
+ Thanks to a safe and automated access to bank data, Bridge powered by Bankin’ provides
10
+ competitive and smart solutions to build conversion-driver financial services.
11
+
12
+ You'll find more information about Bridge API in the [official documentations](https://docs.bridgeapi.io/).
6
13
 
7
14
  ## Installation
8
15
 
9
- Add this line to your application's Gemfile:
16
+ Add this line to your applications Gemfile:
10
17
 
11
18
  ```ruby
12
19
  gem 'bridge_bankin'
@@ -22,22 +29,185 @@ Or install it yourself as:
22
29
 
23
30
  ## Usage
24
31
 
25
- TODO: Write usage instructions here
32
+ ### Requirements
26
33
 
27
- ## Development
34
+ To begin using the API with this gem, you need to create an account to the dashboard on the [Bridge website](https://dashboard.bridgeapi.io/signup).
35
+ Then you’ll have to create a new `application` and generate the required API credentials: a `client_id` and `client_secret`.
36
+ You can find more information about this process by visiting the [Bridge API Dashboard documentation](https://docs.bridgeapi.io/docs/dashboard).
37
+
38
+ ### Getting started
39
+
40
+ One you have your valid API credential you can now create an initializer in your app like this:
41
+
42
+ ```ruby
43
+ BridgeBankin.configure do |config|
44
+ config.api_client_id = ENV["BRIDGE_API_CLIENT_ID"]
45
+ config.api_client_secret = ENV["BRIDGE_API_CLIENT_SECRET"]
46
+ end
47
+ ```
48
+
49
+ Feel free to replace those environment variables by whatever values that work for you.
50
+
51
+ Some resources are public (banks and categories) meaning that only provided the `client_id` and `client_secret` are required.
52
+ Here is an example on how you can use this gem to fetch the banks:
53
+
54
+ ```ruby
55
+ BridgeBankin::Bank.list
56
+ => [#<BridgeBankin::BridgeObject:0x00007fbb0727c620
57
+ @country_code="DE",
58
+ @parent_banks=
59
+ [#<BridgeBankin::BridgeObject:0x00007fbb0727c148
60
+ @banks=
61
+ [#<BridgeBankin::Bank:0x00007fbad702f6b8
62
+ @authentication_type="INTERNAL_CREDS",
63
+ @automatic_refresh=true,
64
+ @capabilities=["ais"],
65
+ @country_code="DE",
66
+ @deeplink_android=nil,
67
+ @deeplink_ios=nil,
68
+ @form=[#<BridgeBankin::BridgeObject:0x00007fbad702cf30 @isNum="0", @label="Email", @maxLength=nil, @type="USER">, #<BridgeBankin::BridgeObject:0x00007fbad702c648 @isNum="0", @label="Password", @maxLength=nil, @type="PWD">],
69
+ @id=457,
70
+ @logo_url="https://web.bankin.com/img/banks-logo/neo/04N26@2x.png",
71
+ @name="N26 (Number 26) DE",
72
+ @payment_enabled=false,
73
+ @primary_color=nil,
74
+ @secondary_color=nil,
75
+ @transfer_enabled=false>],
76
+ @display_order=0,
77
+ @is_highlighted=false,
78
+ @logo_url="https://web.bankin.com/img/banks-logo/neo/04N26@2x.png",
79
+ @name="N26 (Number 26) DE">,
80
+ ...]
81
+ ...]
82
+ ...]
83
+ ```
84
+
85
+ But the majority of the resources need a logged in user. Here is how to create one using the gem:
86
+
87
+ ```ruby
88
+ BridgeBankin::User.create(email: "john.doe@email.com", password: "password123!")
89
+ => #<BridgeBankin::User:0x00007fbb07c5e990 @email="john.doe@email.com", @uuid="f974389d-1442-48bb-bb5e-ac62d1a96984">
90
+ ```
91
+
92
+ Then you can generate an `access_token` for this user by using the `Authorization` class:
93
+
94
+ ```ruby
95
+ BridgeBankin::Authorization.generate_token(email: "john.doe@email.com", password: "password123!")
96
+ => #<BridgeBankin::Authorization:0x00007fbb07967f48 @access_token="58b0195d943f9a3e8433cda7dea48a70339eafc6-5fe7c375-873b-4b0d-bcff-4541c1e19488", @expires_at=2020-12-29 21:35:28.97 UTC>
97
+ ```
98
+
99
+ Since the majority of endpoints are private, you’ll need to pass a valid `access_token` each time you request them.
100
+ Here is how it works with the user we previously created:
28
101
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
+ ```ruby
103
+ BridgeBankin::Transaction.list(access_token: auth.access_token)
104
+ => [#<BridgeBankin::Transaction:0x00007fbb0002d948
105
+ @account=#<BridgeBankin::Account:0x00007fbb0002c250 @id=22271302>,
106
+ @amount=-676.0,
107
+ @category=#<BridgeBankin::Category:0x00007fbb0002c520 @id=79>,
108
+ @currency_code="EUR",
109
+ @date=#<Date: 2021-01-02 ((2459217j,0s,0n),+0s,2299161j)>,
110
+ @description="Achat De Titres",
111
+ @id=38000214608599,
112
+ @is_deleted=false,
113
+ @is_future=true,
114
+ @raw_description="ACHAT DE TITRES - 020121",
115
+ @show_client_side=true,
116
+ @updated_at=2020-12-29 19:40:50.942 UTC>,
117
+ #<BridgeBankin::Transaction:0x00007fbb00023da8
118
+ @account=#<BridgeBankin::Account:0x00007fbb000229f8 @id=22271298>,
119
+ @amount=170.0,
120
+ @category=#<BridgeBankin::Category:0x00007fbb00022c50 @id=289>,
121
+ @currency_code="EUR",
122
+ @date=#<Date: 2021-01-02 ((2459217j,0s,0n),+0s,2299161j)>,
123
+ @description="Economies",
124
+ @id=38000214608462,
125
+ @is_deleted=false,
126
+ @is_future=true,
127
+ @raw_description="Economies - 020121",
128
+ @show_client_side=true,
129
+ @updated_at=2020-12-29 19:40:49.564 UTC>,
130
+ ...
131
+ ]
132
+ ```
133
+
134
+ If you need more information on how the API works or which parameters you can use for a specific query, we really encourage you to consult the great [official guides](https://docs.bridgeapi.io/docs).
135
+
136
+ ### Parameters
137
+
138
+ ##### Mandatory parameters
139
+
140
+ In some case you'll need to specify some parameters to complete your request.
141
+ For instance, in order to retrieve a specific `user`, it requires you to pass the user's `UUID`:
142
+
143
+ ```ruby
144
+ BridgeBankin::User.find(uuid: "f974389d-1442-48bb-bb5e-ac62d1a96984")
145
+ => #<BridgeBankin::User:0x00007fbb07febf90 @email="john.doe@email.com", @uuid="f974389d-1442-48bb-bb5e-ac62d1a96984">
146
+ ```
147
+
148
+ Note that in some case, the API uses basic sequential `IDs` instead of `UUIDs`. In that case just replace `uuid` key by `id`:
149
+
150
+ ```ruby
151
+ BridgeBankin::Bank.find(id: 457)
152
+ => #<BridgeBankin::Bank:0x00007fbb07ec64d0
153
+ @authentication_type="INTERNAL_CREDS",
154
+ @automatic_refresh=true,
155
+ @capabilities=["ais"],
156
+ @country_code="DE",
157
+ @deeplink_android=nil,
158
+ @deeplink_ios=nil,
159
+ @form=[#<BridgeBankin::BridgeObject:0x00007fbb07ec5968 @isNum="0", @label="Email", @maxLength=nil, @type="USER">, #<BridgeBankin::BridgeObject:0x00007fbb07ec54b8 @isNum="0", @label="Password", @maxLength=nil, @type="PWD">],
160
+ @id=457,
161
+ @logo_url="https://web.bankin.com/img/banks-logo/neo/04N26@2x.png",
162
+ @name="N26 (Number 26) DE",
163
+ @payment_enabled=false,
164
+ @primary_color=nil,
165
+ @secondary_color=nil,
166
+ @transfer_enabled=false>
167
+ ```
168
+
169
+ ##### Optional parameters
30
170
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
171
+ The gem resources also allows you to pass any optional parameters supported by the API (see [Official Documentation](https://docs.bridgeapi.io/docs/overview)).
172
+ To do so, just pass them as `named parameters` in corresponding resource class method:
173
+
174
+ ```ruby
175
+ BridgeBankin::Bank.list(limit: 1)
176
+ => [#<BridgeBankin::BridgeObject:0x00007fbb07b4c228
177
+ @country_code="FR",
178
+ @parent_banks=
179
+ [#<BridgeBankin::BridgeObject:0x00007fbb07b4c070
180
+ @banks=
181
+ [#<BridgeBankin::Bank:0x00007fbb07b27d38
182
+ @authentication_type="INTERNAL_CREDS",
183
+ @automatic_refresh=true,
184
+ @capabilities=["ais"],
185
+ @country_code="FR",
186
+ @deeplink_android=nil,
187
+ @deeplink_ios=nil,
188
+ @form=[#<BridgeBankin::BridgeObject:0x00007fbb07b271a8 @isNum="1", @label="Identifiant", @maxLength=nil, @type="USER">, #<BridgeBankin::BridgeObject:0x00007fbb07b26cd0 @isNum="0", @label="Mot de passe", @maxLength=nil, @type="PWD">],
189
+ @id=486,
190
+ @logo_url="https://web.bankin.com/img/banks-logo/france/themis.png",
191
+ @name="Themis Banque",
192
+ @payment_enabled=false,
193
+ @primary_color=nil,
194
+ @secondary_color=nil,
195
+ @transfer_enabled=false>],
196
+ @display_order=0,
197
+ @is_highlighted=false,
198
+ @logo_url="https://web.bankin.com/img/banks-logo/france/themis.png",
199
+ @name="Themis Banque">]>]
200
+ ```
201
+
202
+ ## Development
203
+
204
+ If you need more detailed informations regarding the gem source code you can find more in the official [RubyDoc](https://rubydoc.info/github/neatops/bridge_bankin/main).
32
205
 
33
206
  ## Contributing
34
207
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bridge_bankin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/bridge_bankin/blob/master/CODE_OF_CONDUCT.md).
208
+ We're convinced this gem could be improved a lot or simply not cover every needs you have. That's why contributions of any kind is very encouraged.
209
+ Bug reports and pull requests are welcome on GitHub at https://github.com/neatops/bridge_bankin. This project is intended to be a safe, welcoming space for collaboration.
36
210
 
37
211
  ## License
38
212
 
39
213
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the BridgeBankin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bridge_bankin/blob/master/CODE_OF_CONDUCT.md).
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Olivier Buffon"]
9
9
  spec.email = ["olivier@buffon.dev"]
10
10
 
11
- spec.summary = "Unofficial client to consume Bridge by Bankin’ API"
11
+ spec.summary = "Unofficial Ruby client to consume Bridge by Bankin’ API"
12
12
 
13
13
  spec.description = "Thanks to a safe and automated access to bank data, Bridge powered by Bankin’ provides " \
14
14
  "competitive and smart solutions to build conversion-driver financial services."
@@ -15,5 +15,8 @@ require "bridge_bankin/object_types"
15
15
  # Resources
16
16
  require "bridge_bankin/resources"
17
17
 
18
+ #
19
+ # BridgeBankin main module
20
+ #
18
21
  module BridgeBankin
19
22
  end
@@ -1,12 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgeBankin
4
+ #
5
+ # Account resource
6
+ #
4
7
  class Account < BridgeObject
5
8
  RESOURCE_TYPE = "account"
6
9
 
7
10
  class << self
8
11
  include API::Resource
9
12
 
13
+ #
14
+ # List all logged in user accounts
15
+ #
16
+ # @param [String] access_token the access token provided during the user authentication
17
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
18
+ #
19
+ # @return [Array<Account>] the user accounts
20
+ #
10
21
  def list(access_token:, **params)
11
22
  protected_resource(access_token) do
12
23
  data = api_client.get("/v2/accounts", params)
@@ -14,6 +25,15 @@ module BridgeBankin
14
25
  end
15
26
  end
16
27
 
28
+ #
29
+ # Retrieve a single account for logged in user
30
+ #
31
+ # @param [Integer] id the id of the requested resource
32
+ # @param [String] access_token the access token provided during the user authentication
33
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
34
+ #
35
+ # @return [Account] the user accounts
36
+ #
17
37
  def find(id:, access_token:, **params)
18
38
  protected_resource(access_token) do
19
39
  data = api_client.get("/v2/accounts/#{id}", params)
@@ -8,6 +8,9 @@ require "bridge_bankin/api/error"
8
8
 
9
9
  module BridgeBankin
10
10
  module API
11
+ #
12
+ # Allows to request the Bridge API using Ruby native net/http library
13
+ #
11
14
  class Client
12
15
  HTTP_VERBS_MAP = {
13
16
  get: Net::HTTP::Get,
@@ -18,18 +21,56 @@ module BridgeBankin
18
21
 
19
22
  attr_accessor :access_token
20
23
 
24
+ #
25
+ # Handles a GET request
26
+ #
27
+ # @param [String] path the API endpoint PATH to query
28
+ # @param [Hash] params any params that might be required (or optional) to communicate with the API
29
+ #
30
+ # @return [Hash] the parsed API response
31
+ #
32
+ # @raise [API::Error] expectation if API responding with any error
33
+ #
21
34
  def get(path, **params)
22
35
  request :get, path, params
23
36
  end
24
37
 
38
+ #
39
+ # Handles a POST request
40
+ #
41
+ # @param (see #get)
42
+ #
43
+ # @return (see #get)
44
+ #
45
+ # @raise (see #get)
46
+ #
47
+
25
48
  def post(path, **params)
26
49
  request :post, path, params
27
50
  end
28
51
 
52
+ #
53
+ # Handles a PUT request
54
+ #
55
+ # @param (see #get)
56
+ #
57
+ # @return (see #get)
58
+ #
59
+ # @raise (see #get)
60
+ #
29
61
  def put(path, **params)
30
62
  request :put, path, params
31
63
  end
32
64
 
65
+ #
66
+ # Handles a DELETE request
67
+ #
68
+ # @param (see #get)
69
+ #
70
+ # @return (see #get)
71
+ #
72
+ # @raise (see #get)
73
+ #
33
74
  def delete(path, **params)
34
75
  request :delete, path, params
35
76
  end
@@ -48,9 +89,14 @@ module BridgeBankin
48
89
  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
49
90
  api_response = http.request(yield)
50
91
 
51
- return parse_response_body(api_response.body) if %w[200 201].include?(api_response.code)
52
-
53
- handle_error(api_response)
92
+ case api_response.code
93
+ when "200", "201"
94
+ parse_response_body(api_response.body)
95
+ when "204"
96
+ {}
97
+ else
98
+ handle_error(api_response)
99
+ end
54
100
  end
55
101
  end
56
102