nordigen-ruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a0a198d2708a354e0cb9c3a4dc0a5b3c86a48558a3cbc7fdd194a5e6f51c339
4
+ data.tar.gz: cb7f41ae35dac9c280cccde6a0e9d3881d3903569254c3a14e2e19ab93885f88
5
+ SHA512:
6
+ metadata.gz: 5fff49c6c59a8b05e8777a84e9b1423a36936b73762f39e02a101b363ad3c7e69a4b14caeb6e6cbcfcac4f1bd69161ddc7f2d06f5b69291dbdb4613f04cad9fa
7
+ data.tar.gz: ae06748d1a8369a1e6dc5e0a61a3a36218044408734450dbac06173feb5125cece179624725ce47d519493933605e4aa832a748fdd9b514a19d2432606c2ae95
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## [1.0.0] - 2022-01-13
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in nordigen.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "faraday", "~> 1.8.0"
10
+ gem "faraday_middleware", "~> 1.2.0"
11
+ gem "test-unit", "~> 3.5.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nordigen-ruby (1.0.0)
5
+ dotenv (~> 2.7.6)
6
+ faraday (~> 1.8.0)
7
+ faraday_middleware (~> 1.2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ dotenv (2.7.6)
13
+ faraday (1.8.0)
14
+ faraday-em_http (~> 1.0)
15
+ faraday-em_synchrony (~> 1.0)
16
+ faraday-excon (~> 1.1)
17
+ faraday-httpclient (~> 1.0.1)
18
+ faraday-net_http (~> 1.0)
19
+ faraday-net_http_persistent (~> 1.1)
20
+ faraday-patron (~> 1.0)
21
+ faraday-rack (~> 1.0)
22
+ multipart-post (>= 1.2, < 3)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-em_http (1.0.0)
25
+ faraday-em_synchrony (1.0.0)
26
+ faraday-excon (1.1.0)
27
+ faraday-httpclient (1.0.1)
28
+ faraday-net_http (1.0.1)
29
+ faraday-net_http_persistent (1.2.0)
30
+ faraday-patron (1.0.0)
31
+ faraday-rack (1.0.0)
32
+ faraday_middleware (1.2.0)
33
+ faraday (~> 1.0)
34
+ multipart-post (2.1.1)
35
+ power_assert (2.0.1)
36
+ rake (13.0.6)
37
+ ruby2_keywords (0.0.5)
38
+ test-unit (3.5.3)
39
+ power_assert
40
+
41
+ PLATFORMS
42
+ x86_64-linux
43
+
44
+ DEPENDENCIES
45
+ dotenv (~> 2.7.6)
46
+ faraday (~> 1.8.0)
47
+ faraday_middleware (~> 1.2.0)
48
+ nordigen-ruby!
49
+ rake (~> 13.0)
50
+ test-unit (~> 3.5.3)
51
+
52
+ BUNDLED WITH
53
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Nordigen Solutions SIA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Nordigen Ruby Library
2
+
3
+ This is official Ruby client library for [Nordigen](https://nordigen.com/en).
4
+
5
+ For a full list of endpoints and arguments, see the [docs](https://nordigen.com/en/account_information_documenation/api-documention/overview/).
6
+
7
+ Before starting to use API you will need to create a new secret and get your `SECRET_ID` and `SECRET_KEY` from the [Nordigen's Open Banking Portal](https://ob.nordigen.com/user-secrets/).
8
+
9
+ ## Requirements
10
+
11
+ * Ruby 2.6+
12
+
13
+
14
+ ## Installation
15
+
16
+
17
+ Install library
18
+
19
+ ```
20
+ gem install nordigen-ruby
21
+ ```
22
+
23
+ ## Example application
24
+
25
+ Example code can be found in `main.rb` file and Ruby on Rails example application can be found in `example` directory
26
+
27
+ ## Quickstart
28
+
29
+
30
+ ```ruby
31
+ require 'securerandom'
32
+ require 'nordigen-ruby'
33
+
34
+ # Get secret_id and secret_key from ob.nordigen.com portal and pass to NordigenClient or load from .env file
35
+ client = Nordigen::NordigenClient.new(
36
+ secret_id: "SECRET_ID",
37
+ secret_key: "SECRET_KEY"
38
+ )
39
+
40
+ # Generate new access token. Token is valid for 24 hours
41
+ token_data = client.generate_token()
42
+
43
+ # Use existing token
44
+ client.set_token("YOUR_TOKEN")
45
+
46
+ # Get access and refresh token
47
+ # Note: access_token is automatically injected to other requests after you successfully obtain it
48
+ access_token = token_data.access
49
+ refresh_token = token_data.refresh
50
+
51
+ # Exchange refresh token. Refresh token is valid for 30 days
52
+ refresh_token = client.exchange_token(refresh_token)
53
+
54
+ # Get all institution by providing country code in ISO 3166 format
55
+ institutions = client.institution.get_institutions("LV")
56
+
57
+ # Institution id can be gathered from get_institutions response.
58
+ # Example Revolut ID
59
+ id = "REVOLUT_REVOGB21"
60
+
61
+ # Initialize bank authorization session
62
+ # Returns requisition_id and link to initiate authorization with a bank
63
+ init = client.init_session(
64
+ # redirect url after successful authentication
65
+ redirect_url: "https://nordigen.com",
66
+ # institution id
67
+ institution_id: id,
68
+ # a unique user ID of someone who's using your services, usually it's a UUID
69
+ reference_id: SecureRandom.uuid
70
+ )
71
+
72
+ link = init.link # bank authorization link
73
+ puts init.link
74
+ requisition_id = init.requisition_id # requisition id that is needed to get an account_id
75
+ ```
76
+
77
+ After successful authorization with a bank you can fetch your data (details, balances, transactions)
78
+
79
+
80
+ ## Fetching account metadata, balances, details and transactions
81
+
82
+ ```ruby
83
+
84
+ # Get account id after you have completed authorization with a bank.
85
+ accounts = client.requisition.get_requisition_by_id(requisition_id)
86
+ # Get account id from list
87
+ account_id = accounts.accounts[0]
88
+
89
+ # Instantiate account object
90
+ account = client.account_api(account_id)
91
+
92
+ # Fetch account metadata
93
+ meta_data = account.get_metadata()
94
+ # Fetch details
95
+ details = account.get_details()
96
+ # Fetch balances
97
+ balances = account.get_balances()
98
+ # Fetch transactions
99
+ transactions = account.get_transactions()
100
+ ```
101
+
102
+ ## Support
103
+
104
+ For any inquiries please contact support at [support@nordigen.com](support@nordigen.com) or create an issue in repository.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "nordigen-ruby"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,103 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ require "nordigen_ruby/api/institutions"
5
+ require "nordigen_ruby/api/agreements"
6
+ require "nordigen_ruby/api/requisitions"
7
+ require "nordigen_ruby/api/account"
8
+
9
+ module Nordigen
10
+ class NordigenClient
11
+
12
+ BASE_URL = "https://ob.nordigen.com/api/v2/"
13
+
14
+ @@headers = {
15
+ "accept" => "application/json",
16
+ "Content-Type" => "application/json",
17
+ "User-Agent" => "Nordigen-Ruby-v2"
18
+ }
19
+
20
+ attr_reader :secret_id, :secret_key, :institution, :agreement, :requisition
21
+
22
+ def initialize(secret_id:, secret_key:)
23
+ @secret_id = secret_id
24
+ @secret_key = secret_key
25
+ @institution = InstitutionsApi.new(client=self)
26
+ @agreement = AgreementsApi.new(client=self)
27
+ @requisition = RequisitionsApi.new(client=self)
28
+ end
29
+
30
+ def request
31
+ # HTTP client request
32
+ @request ||= Faraday.new do |conn|
33
+ conn.url_prefix = BASE_URL
34
+ conn.headers = @@headers
35
+ conn.request :json
36
+ conn.response :json, parser_options: { object_class: OpenStruct }
37
+ end
38
+ end
39
+
40
+ def set_token(access_token)
41
+ # Use existing token
42
+ @@headers["Authorization"] = "Bearer #{access_token}"
43
+ end
44
+
45
+ def get_token
46
+ # Get token
47
+ return request.headers["Authorization"]
48
+ end
49
+
50
+ def generate_token
51
+ # Generate new access & refresh token
52
+ payload = {
53
+ "secret_key": @secret_key,
54
+ "secret_id": @secret_id
55
+ }
56
+ response = self.request.post("token/new/", payload)
57
+ if !response.success?
58
+ raise Exception.new response.body
59
+ end
60
+
61
+ @@headers["Authorization"] = "Bearer #{response.body.access}"
62
+ request.headers = @@headers
63
+ return response.body
64
+ end
65
+
66
+ def exchange_token(refresh_token)
67
+ # Exchange refresh token for access token
68
+ payload = {"refresh": refresh_token}
69
+ response = self.request.post("token/refresh/", payload).body
70
+ @@headers["Authorization"] = "Bearer #{response.access}"
71
+ request.headers = @@headers
72
+ return response
73
+ end
74
+
75
+
76
+ def account(account_id)
77
+ # Create Account instance
78
+ return AccountApi.new(client: self, account_id: account_id)
79
+ end
80
+
81
+ def init_session(redirect_url:, institution_id:, reference_id:, max_historical_days: 90)
82
+ # Factory method that creates authorization in a specific institution
83
+ # and are responsible for the following steps:
84
+ # * Creates agreement
85
+ # * Creates requisiton
86
+
87
+ # Create agreement
88
+ new_agreement = @agreement.create_agreement(
89
+ institution_id: institution_id,
90
+ max_historical_days: max_historical_days
91
+ )
92
+ # Create requisition
93
+ new_requsition = @requisition.create_requisition(
94
+ redirect_url: redirect_url,
95
+ reference: reference_id,
96
+ institution_id: institution_id
97
+ )
98
+
99
+ return new_requsition
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,45 @@
1
+ module Nordigen
2
+ class AccountApi
3
+
4
+ ENDPOINT = "accounts/"
5
+ attr_reader :client, :account_id
6
+
7
+ def initialize(client:, account_id:)
8
+ @client = client
9
+ @account_id = account_id
10
+ end
11
+
12
+ def get(path = nil)
13
+ # Create Get request
14
+ url = "#{ENDPOINT}#{@account_id}/"
15
+
16
+ if path
17
+ url = "#{url}#{path}/"
18
+ end
19
+
20
+ return client.request.get(url).body
21
+ end
22
+
23
+ def get_metadata
24
+ # Access account metadata
25
+ return get()
26
+ end
27
+
28
+ def get_details
29
+ # Access account details
30
+ return get("details")
31
+ end
32
+
33
+
34
+ def get_balances
35
+ # Access account balances
36
+ return get("balances")
37
+ end
38
+
39
+ def get_transactions
40
+ # Access account transactions
41
+ return get("transactions")
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ module Nordigen
2
+ class AgreementsApi
3
+
4
+ ENDPOINT = "agreements/enduser/"
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ # Nordigen client initialization
9
+ @client = client
10
+ end
11
+
12
+ def create_agreement(institution_id:, max_historical_days: 90, access_valid_for_days: 90, access_scope: [
13
+ "balances",
14
+ "details",
15
+ "transactions"
16
+ ])
17
+ # Create enduser agreement
18
+ payload = {
19
+ "institution_id": institution_id,
20
+ "max_historical_days": max_historical_days,
21
+ "access_valid_for_days": access_valid_for_days,
22
+ "access_scope": access_scope,
23
+ };
24
+ return client.request.post(ENDPOINT, payload).body
25
+ end
26
+
27
+
28
+ def get_agreements(limit: 100, offset: 0)
29
+ # Get list of agreements
30
+ params = {limit: limit, offset: offset}
31
+ return client.request.get(ENDPOINT, params).body
32
+ end
33
+
34
+ def get_agreement_by_id(agreement_id)
35
+ # Get agreemenet by id
36
+ return client.request.get("#{ENDPOINT}#{agreement_id}/").body
37
+ end
38
+
39
+ def delete_agreement(agreement_id)
40
+ # Delete agreement by id
41
+ return client.request.delete("#{ENDPOINT}#{agreement_id}/").body
42
+ end
43
+
44
+ def accept_agreement(agreement_id:, ip:, user_agent:)
45
+ # Accept end user agreement
46
+ payload = {
47
+ 'user_agent': user_agent,
48
+ 'ip_address': ip
49
+ }
50
+ return client.request.put("#{ENDPOINT}#{agreement_id}/accept/").body
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,23 @@
1
+ module Nordigen
2
+ class InstitutionsApi
3
+
4
+ ENDPOINT = "institutions"
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ # Nordigen client initialization
9
+ @client = client
10
+ end
11
+
12
+ def get_institutions(country)
13
+ # Get list of institutions
14
+ return client.request.get("#{ENDPOINT}/?country=#{country}").body
15
+ end
16
+
17
+ def get_institution_by_id(id)
18
+ # Get single institution by id
19
+ return client.request.get("#{ENDPOINT}/#{id}/").body
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+
2
+ module Nordigen
3
+ class RequisitionsApi
4
+
5
+ ENDPOINT = "requisitions/"
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ # Nordigen client initialization
10
+ @client = client
11
+ end
12
+
13
+ def create_requisition(redirect_url:, reference:, institution_id:, user_language: "en", agreement: nil)
14
+ # Create requisition. For creating links and retrieving accounts.
15
+ payload = {
16
+ "redirect": redirect_url,
17
+ "reference": reference,
18
+ "institution_id": institution_id,
19
+ "user_language": user_language,
20
+ }
21
+
22
+ if agreement
23
+ payload["agreement"] = agreement
24
+ end
25
+
26
+ return client.request.post(ENDPOINT, payload).body
27
+ end
28
+
29
+ def get_requisitions(limit: 100, offset: 0)
30
+ # Get all requisitions
31
+ params = {limit: limit, offset: offset}
32
+ return client.request.get(ENDPOINT, params).body
33
+ end
34
+
35
+
36
+ def get_requisition_by_id(requisition_id)
37
+ # Get requisition by id
38
+ return client.request.get("#{ENDPOINT}#{requisition_id}/").body
39
+ end
40
+
41
+ def delete_requisition(requisition_id)
42
+ # Delete requisition by id
43
+ return client.request.delete("#{ENDPOINT}#{requisition_id}/").body
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nordigen
4
+ VERSION = "1.0.1"
5
+ end
data/nordigen.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
4
+
5
+ require "nordigen_ruby/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "nordigen-ruby"
9
+ spec.version = Nordigen::VERSION
10
+ spec.authors = ["Nordigen Solutions"]
11
+ spec.email = ["support@nordigen.com"]
12
+ spec.summary = "Nordigen client for Ruby"
13
+ spec.homepage = "https://github.com/nordigen/nordigen-ruby"
14
+ spec.description = "Nordigen official API client for Ruby"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.6.0"
17
+
18
+ spec.metadata["homepage_uri"] = "https://github.com/nordigen/nordigen-ruby"
19
+ spec.metadata["bug_tracker_uri"] = "https://github.com/nordigen/nordigen-ruby/issues"
20
+ spec.metadata["changelog_uri"] = "https://github.com/nordigen/nordigen-ruby/blob/master/CHANGELOG.md"
21
+ spec.metadata["documentation_uri"] = "https://github.com/nordigen/nordigen-ruby"
22
+ spec.metadata["github_repo"] = "https://github.com/nordigen/nordigen-ruby"
23
+ spec.metadata["source_code_uri"] = "https://github.com/nordigen/nordigen-ruby"
24
+
25
+ ignored = Regexp.union(
26
+ /\A\.env.template/,
27
+ /\A\.git/,
28
+ /\Atest/,
29
+ /\Aexample/,
30
+ /\Amain.rb/
31
+ )
32
+ spec.files = `git ls-files`.split("\n").reject { |f| ignored.match(f) }
33
+ spec.executables = `git ls-files -- bin/*`.split("\n")
34
+ .map { |f| ::File.basename(f) }
35
+
36
+ spec.add_dependency "faraday", "~> 1.8.0"
37
+ spec.add_dependency "faraday_middleware", "~> 1.2.0"
38
+
39
+ spec.require_paths = ["lib"]
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nordigen-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nordigen Solutions
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ description: Nordigen official API client for Ruby
42
+ email:
43
+ - support@nordigen.com
44
+ executables:
45
+ - console
46
+ - setup
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/nordigen-ruby.rb
59
+ - lib/nordigen_ruby/api/account.rb
60
+ - lib/nordigen_ruby/api/agreements.rb
61
+ - lib/nordigen_ruby/api/institutions.rb
62
+ - lib/nordigen_ruby/api/requisitions.rb
63
+ - lib/nordigen_ruby/version.rb
64
+ - nordigen.gemspec
65
+ homepage: https://github.com/nordigen/nordigen-ruby
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/nordigen/nordigen-ruby
70
+ bug_tracker_uri: https://github.com/nordigen/nordigen-ruby/issues
71
+ changelog_uri: https://github.com/nordigen/nordigen-ruby/blob/master/CHANGELOG.md
72
+ documentation_uri: https://github.com/nordigen/nordigen-ruby
73
+ github_repo: https://github.com/nordigen/nordigen-ruby
74
+ source_code_uri: https://github.com/nordigen/nordigen-ruby
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.6.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.15
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Nordigen client for Ruby
94
+ test_files: []