ibanity 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
+ SHA1:
3
+ metadata.gz: 6424b97332b6c11ff8b87d743b7e3c55cf31ff46
4
+ data.tar.gz: dac09c7b80ad9cb73ddfca79fad9486dab10fe55
5
+ SHA512:
6
+ metadata.gz: 3131d40ca2c646d7818b34402c1e78b0af9234f5c17012b75b864471c5db7565c93fb73ba58fe16ca3f00ae30930d5b02fd23955b3cd06aa65bfe7ddab831fd3
7
+ data.tar.gz: b7516df69d7e500e77b3baa990e898045a5a0ef8362b2d35828d2391c69d74ef14019e7f1872d3a56f9d09a3b8c552aff707a8da27c6b95584963c05579d5724
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
16
+ .ruby*
17
+ *.gem
18
+ *.env
data/.gitkeep ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,8 @@
1
+ he MIT License (MIT)
2
+ Copyright (c) 2017 Lockey SPRL
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Ibanity Ruby Library
2
+
3
+ The Ibanity Ruby Library provide convenient wrappers around the Ibanity API. The object attributes are dynamically defined based on the API response allowing to support minor API changes seamlessly.
4
+
5
+ ## Documentation
6
+
7
+ Visit our [Ruby API docs](https://documentation.ibanity.com/api/ruby).
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ gem install "ibanity"
13
+ ```
14
+
15
+ ### Requirements
16
+
17
+ * Ruby 2.0+.
18
+
19
+ ## Usage
20
+
21
+ * Usage
22
+
23
+ Ibanity must be configured using the details of your application on the [Ibanity developer portal](https://developer.ibanity.com).
24
+
25
+ ```ruby
26
+ require "ibanity"
27
+
28
+ Ibanity.configure do |config|
29
+ config.certificate = ENV["IBANITY_CERTIFICATE"]
30
+ config.key = ENV["IBANITY_KEY"]
31
+ config.key_passphrase = ENV["IBANITY_PASSPHRASE"]
32
+ end
33
+
34
+ puts Ibanity::FinancialInstitution.list.first
35
+ puts Ibanity::SandboxUser.list
36
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ exec "irb -r ibanity -I ./lib"
5
+ end
data/ibanity.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ibanity/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ibanity"
8
+ spec.version = Ibanity::VERSION
9
+ spec.authors = ["Ibanity"]
10
+ spec.email = ["info@ibanity.com"]
11
+ spec.summary = "Ibanity Ruby Client"
12
+ spec.description = "A Ruby wrapper for the Ibanity API."
13
+ spec.homepage = "https://documentation.ibanity.com/api/ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", ">= 1.8.0"
22
+ spec.add_development_dependency "rspec", "3.4.0"
23
+ spec.add_development_dependency "webmock", "1.24.2"
24
+ end
@@ -0,0 +1,20 @@
1
+ module Ibanity
2
+ class Account < Ibanity::BaseResource
3
+ def self.list(financial_institution_id: nil, customer_access_token:, **query_params)
4
+ uri = if financial_institution_id
5
+ Ibanity.api_schema["customer"]["financialInstitution"]["accounts"].sub("{financialInstitutionId}", financial_institution_id).sub("{accountId}", "")
6
+ else
7
+ Ibanity.api_schema["customer"]["accounts"].sub("{accountId}", "")
8
+ end
9
+
10
+ list_by_uri(uri, query_params, customer_access_token)
11
+ end
12
+
13
+ def self.find(id:, financial_institution_id:, customer_access_token:)
14
+ uri = Ibanity.api_schema["customer"]["financialInstitution"]["accounts"]
15
+ .sub("{financialInstitutionId}", financial_institution_id)
16
+ .sub("{accountId}", id)
17
+ find_by_uri(uri, customer_access_token)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Ibanity
2
+ class AccountInformationAccessRequest < Ibanity::BaseResource
3
+ def self.create_for_financial_institution(financial_institution_id:, customer_access_token:, **attributes)
4
+ path = Ibanity.api_schema["customer"]["financialInstitution"]["accountInformationAccessRequests"]
5
+ .gsub("{financialInstitutionId}", financial_institution_id)
6
+ .gsub("{accountInformationAccessRequestId}", "")
7
+ uri = Ibanity.client.build_uri(path)
8
+ create_by_uri(uri, "accountInformationAccessRequest", attributes, customer_access_token)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,105 @@
1
+ module Ibanity
2
+ class BaseResource < OpenStruct
3
+ def self.create_by_uri(uri, resource_type, attributes, customer_access_token = nil)
4
+ payload = {
5
+ data: {
6
+ type: resource_type,
7
+ attributes: attributes
8
+ }
9
+ }
10
+ raw_item = Ibanity.client.post(uri, payload, {}, customer_access_token)
11
+ new(raw_item["data"], customer_access_token)
12
+ end
13
+
14
+ def self.list_by_uri(uri, query_params = {}, customer_access_token = nil)
15
+ raw_items = Ibanity.client.get(uri, query_params, customer_access_token)
16
+ raw_items["data"].map do |raw_item|
17
+ new(raw_item, customer_access_token)
18
+ end
19
+ end
20
+
21
+ def self.find_by_uri(uri, customer_access_token = nil)
22
+ new(find_raw_by_uri(uri, customer_access_token), customer_access_token)
23
+ end
24
+
25
+ def self.find_raw_by_uri(uri, customer_access_token = nil)
26
+ raw_item = Ibanity.client.get(uri, {}, customer_access_token)
27
+ raw_item["data"]
28
+ end
29
+
30
+ def self.destroy_by_uri(uri, customer_access_token = nil)
31
+ raw_item = Ibanity.client.delete(uri, {}, customer_access_token)
32
+ new(raw_item["data"])
33
+ end
34
+
35
+ def self.update_by_uri(uri, resource_type, attributes, customer_access_token = nil)
36
+ payload = {
37
+ data: {
38
+ type: resource_type,
39
+ attributes: attributes
40
+ }
41
+ }
42
+ raw_item = Ibanity.client.patch(uri, payload, {}, customer_access_token)
43
+ new(raw_item["data"])
44
+ end
45
+
46
+ def initialize(raw, customer_access_token = nil)
47
+ attributes = prepare_attributes(raw)
48
+ super(attributes)
49
+
50
+ relationships = raw["relationships"] || {}
51
+ setup_relationships(relationships, customer_access_token)
52
+
53
+ links = raw["links"] || {}
54
+ setup_links(links)
55
+ end
56
+
57
+ def reload!
58
+ reloaded = self.class.find_raw_by_uri(uri)
59
+ attributes = prepare_attributes(reloaded)
60
+ attributes.each do |key, value|
61
+ self[key] = value
62
+ end
63
+ self
64
+ end
65
+
66
+ private
67
+
68
+ def prepare_attributes(raw)
69
+ base = {
70
+ "id" => raw["id"],
71
+ }
72
+ attributes = raw["attributes"] || {}
73
+ meta = raw["meta"] || {}
74
+ params = base.merge(attributes).merge(meta)
75
+ Ibanity::Util.underscorize_hash(params)
76
+ end
77
+
78
+ def setup_relationships(relationships, customer_access_token = nil)
79
+ relationships.each do |key, relationship|
80
+ if relationship["data"]
81
+ klass = Ibanity.const_get(Ibanity::Util.camelize(key))
82
+ method_name = Ibanity::Util.underscore(key)
83
+ define_singleton_method(method_name) do
84
+ klass.find_by_uri(relationship["links"]["related"], customer_access_token)
85
+ end
86
+ self[Ibanity::Util.underscore("#{key}_id")] = relationship["data"]["id"]
87
+ else
88
+ singular_key = key[0..-2]
89
+ klass = Ibanity.const_get(Ibanity::Util.camelize(singular_key))
90
+ method_name = Ibanity::Util.underscore(key)
91
+ define_singleton_method(method_name) do
92
+ uri = relationship["links"]["related"]
93
+ klass.list_by_uri(uri, customer_access_token)
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ def setup_links(links)
100
+ links.each do |key, link|
101
+ self[Ibanity::Util.underscore("#{key}_link")] = link
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,18 @@
1
+ module Ibanity
2
+ class Customer < Ibanity::BaseResource
3
+ def self.list
4
+ uri = Ibanity.api_schema["customers"].sub("{customerId}", "")
5
+ list_by_uri(uri)
6
+ end
7
+
8
+ def self.find(id)
9
+ uri = Ibanity.api_schema["customers"].sub("{customerId}", id)
10
+ find_by_uri(uri)
11
+ end
12
+
13
+ def self.destroy(id)
14
+ uri = Ibanity.api_schema["customers"].sub("{customerId}", id)
15
+ destroy_by_uri(uri)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Ibanity
2
+ class CustomerAccessToken < ::Ibanity::BaseResource
3
+ def self.create(attributes)
4
+ path = ::Ibanity.api_schema["customerAccessTokens"]
5
+ uri = ::Ibanity.client.build_uri(path)
6
+ create_by_uri(uri, "customerAccessToken", attributes)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Ibanity
2
+ class FinancialInstitution < Ibanity::BaseResource
3
+ def self.list(**query_params)
4
+ uri = Ibanity.api_schema["financialInstitutions"].sub("{financialInstitutionId}", "")
5
+ list_by_uri(uri, query_params)
6
+ end
7
+
8
+ # def self.all_for_customer(customer_access_token, **query_params)
9
+ # uri = Ibanity.api_schema["customer"]["financialInstitutions"]
10
+ # list_by_uri(uri, query_params = {}, customer_access_token)
11
+ # end
12
+
13
+ def self.find(id:)
14
+ uri = Ibanity.api_schema["financialInstitutions"].sub("{financialInstitutionId}", id)
15
+ find_by_uri(uri)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Ibanity
2
+ class FundAvailabilityAccessRequest < Ibanity::BaseResource
3
+ def self.create_for_financial_institution(financial_institution_id:, customer_access_token:, **attributes)
4
+ path = Ibanity.api_schema["financialInstitution"]["fundAvailabilityAccessRequests"]
5
+ .gsub("{financialInstitutionId}", financial_institution_id)
6
+ .gsub("{fundAvailabilityAccessRequestId}", "")
7
+ uri = Ibanity.client.build_uri(path)
8
+ create_by_uri(uri, "fundAvailabilityAccessRequest", attributes, customer_access_token)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ibanity
2
+ class PaymentInitiationRequest < Ibanity::BaseResource
3
+ def self.create_for_financial_institution(financial_institution_id:, customer_access_token:, **attributes)
4
+ path = Ibanity.api_schema["financialInstitution"]["paymentInitiationRequests"]
5
+ .gsub("{financialInstitutionId}", financial_institution_id)
6
+ .gsub("{paymentInitiationRequestId}", "")
7
+ uri = Ibanity.client.build_uri(path)
8
+ create_by_uri(uri, "paymentInitiationRequest", attributes, customer_access_token)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ module Ibanity
2
+ class SandboxAccount < Ibanity::BaseResource
3
+ def self.create(sandbox_user_id:, financial_institution_id:, **attributes)
4
+ path = Ibanity.api_schema["sandbox"]["accounts"]
5
+ .gsub("{financialInstitutionId}", financial_institution_id)
6
+ .gsub("{sandboxUserId}", sandbox_user_id)
7
+ .gsub("{sandboxAccountId}", "")
8
+ uri = Ibanity.client.build_uri(path)
9
+ create_by_uri(uri, "sandboxAccount", attributes)
10
+ end
11
+
12
+ def self.list(financial_institution_id:, sandbox_user_id:, **query_params)
13
+ path = Ibanity.api_schema["sandbox"]["accounts"]
14
+ .gsub("{financialInstitutionId}", financial_institution_id)
15
+ .gsub("{sandboxUserId}", sandbox_user_id)
16
+ .gsub("{sandboxAccountId}", "")
17
+ uri = Ibanity.client.build_uri(path)
18
+ list_by_uri(uri, query_params)
19
+ end
20
+
21
+ def self.find(id:, sandbox_user_id:, financial_institution_id:)
22
+ path = Ibanity.api_schema["sandbox"]["accounts"]
23
+ .gsub("{financialInstitutionId}", financial_institution_id)
24
+ .gsub("{sandboxUserId}", sandbox_user_id)
25
+ .gsub("{sandboxAccountId}", id)
26
+ uri = Ibanity.client.build_uri(path)
27
+ find_by_uri(uri)
28
+ end
29
+
30
+ def self.delete(id:, sandbox_user_id:, financial_institution_id:)
31
+ path = Ibanity.api_schema["sandbox"]["accounts"]
32
+ .gsub("{financialInstitutionId}", financial_institution_id)
33
+ .gsub("{sandboxUserId}", sandbox_user_id)
34
+ .gsub("{sandboxAccountId}", id)
35
+ uri = Ibanity.client.build_uri(path)
36
+ destroy_by_uri(uri)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module Ibanity
2
+ class SandboxFinancialInstitution < Ibanity::BaseResource
3
+ def self.create(attributes)
4
+ path = Ibanity.api_schema["sandbox"]["financialInstitutions"].gsub("{financialInstitutionId}", "")
5
+ uri = Ibanity.client.build_uri(path)
6
+ create_by_uri(uri, "financialInstitution", attributes)
7
+ end
8
+
9
+ def self.update(id:, **attributes)
10
+ path = Ibanity.api_schema["sandbox"]["financialInstitutions"].gsub("{financialInstitutionId}", id)
11
+ uri = Ibanity.client.build_uri(path)
12
+ update_by_uri(uri, "financialInstitution", attributes)
13
+ end
14
+
15
+ def self.delete(id:)
16
+ uri = Ibanity.api_schema["sandbox"]["financialInstitutions"].gsub("{financialInstitutionId}", id)
17
+ destroy_by_uri(uri)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ module Ibanity
2
+ class SandboxTransaction < Ibanity::BaseResource
3
+ def self.create(sandbox_user_id:, financial_institution_id:, sandbox_account_id:, **attributes)
4
+ path = Ibanity.api_schema["sandbox"]["transactions"]
5
+ .gsub("{financialInstitutionId}", financial_institution_id)
6
+ .gsub("{sandboxUserId}", sandbox_user_id)
7
+ .gsub("{sandboxAccountId}", sandbox_account_id)
8
+ .gsub("{sandboxTransactionId}", "")
9
+ uri = Ibanity.client.build_uri(path)
10
+ create_by_uri(uri, "sandboxTransaction", attributes)
11
+ end
12
+
13
+ def self.list(sandbox_user_id:, financial_institution_id:, sandbox_account_id:, **query_params)
14
+ path = Ibanity.api_schema["sandbox"]["transactions"]
15
+ .gsub("{financialInstitutionId}", financial_institution_id)
16
+ .gsub("{sandboxUserId}", sandbox_user_id)
17
+ .gsub("{sandboxAccountId}", sandbox_account_id)
18
+ .gsub("{sandboxTransactionId}", "")
19
+ uri = Ibanity.client.build_uri(path)
20
+ list_by_uri(uri, query_params)
21
+ end
22
+
23
+ def self.find(id:, sandbox_user_id:, financial_institution_id:, sandbox_account_id:)
24
+ path = Ibanity.api_schema["sandbox"]["transactions"]
25
+ .gsub("{financialInstitutionId}", financial_institution_id)
26
+ .gsub("{sandboxUserId}", sandbox_user_id)
27
+ .gsub("{sandboxAccountId}", sandbox_account_id)
28
+ .gsub("{sandboxTransactionId}", id)
29
+ uri = Ibanity.client.build_uri(path)
30
+ find_by_uri(uri)
31
+ end
32
+
33
+ def self.delete(id:, sandbox_user_id:, financial_institution_id:, sandbox_account_id:)
34
+ path = Ibanity.api_schema["sandbox"]["transactions"]
35
+ .gsub("{financialInstitutionId}", financial_institution_id)
36
+ .gsub("{sandboxUserId}", sandbox_user_id)
37
+ .gsub("{sandboxAccountId}", sandbox_account_id)
38
+ .gsub("{sandboxTransactionId}", id)
39
+ uri = Ibanity.client.build_uri(path)
40
+ destroy_by_uri(uri)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ module Ibanity
2
+ class SandboxUser < Ibanity::BaseResource
3
+ def self.create(attributes)
4
+ path = Ibanity.api_schema["sandbox"]["users"].gsub("{sandboxUserId}", "")
5
+ uri = Ibanity.client.build_uri(path)
6
+ create_by_uri(uri, "sandboxUser", attributes)
7
+ end
8
+
9
+ def self.list(**query_params)
10
+ uri = Ibanity.api_schema["sandbox"]["users"].sub("{sandboxUserId}", "")
11
+ list_by_uri(uri, query_params)
12
+ end
13
+
14
+ def self.find(id:)
15
+ uri = Ibanity.api_schema["sandbox"]["users"].sub("{sandboxUserId}", id)
16
+ find_by_uri(uri)
17
+ end
18
+
19
+ def self.update(id:, **attributes)
20
+ path = Ibanity.api_schema["sandbox"]["users"].sub("{sandboxUserId}", id)
21
+ uri = Ibanity.client.build_uri(path)
22
+ update_by_uri(uri, "sandboxUser", attributes)
23
+ end
24
+
25
+ def self.delete(id:)
26
+ uri = Ibanity.api_schema["sandbox"]["users"].sub("{sandboxUserId}", id)
27
+ destroy_by_uri(uri)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Ibanity
2
+ class Transaction < Ibanity::BaseResource
3
+ # def self.all_for_customer_account(customer_id, account_id, query_params = {})
4
+ # uri = Ibanity.api_schema["customerAccountTransactions"]
5
+ # .sub("{customerId}", customer_id)
6
+ # .sub("{accountId}", account_id)
7
+ # .sub("{transactionId}", "")
8
+ # list_by_uri(uri, query_params)
9
+ # end
10
+
11
+ def self.list(financial_institution_id:, account_id:, customer_access_token:, **query_params)
12
+ uri = Ibanity.api_schema["customer"]["financialInstitution"]["transactions"]
13
+ .sub("{financialInstitutionId}", financial_institution_id)
14
+ .sub("{accountId}", account_id)
15
+ .sub("{transactionId}", "")
16
+ list_by_uri(uri, query_params, customer_access_token)
17
+ end
18
+
19
+ def self.find(id:, financial_institution_id:, account_id:, customer_access_token:)
20
+ uri = Ibanity.api_schema["customer"]["financialInstitution"]["transactions"]
21
+ .sub("{financialInstitutionId}", financial_institution_id)
22
+ .sub("{accountId}", account_id)
23
+ .sub("{transactionId}", id)
24
+ find_by_uri(uri, customer_access_token)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ module Ibanity
2
+ class Client
3
+
4
+ attr_reader :base_uri
5
+
6
+ def initialize(certificate:, key:, key_passphrase:, api_scheme: "https", api_host: "api.ibanity.com", api_port: "443", ssl_ca_file: nil)
7
+ @certificate = OpenSSL::X509::Certificate.new(certificate)
8
+ @key = OpenSSL::PKey::RSA.new(key, key_passphrase)
9
+ @base_uri = "#{api_scheme}://#{api_host}:#{api_port}"
10
+ @ssl_ca_file = ssl_ca_file
11
+ end
12
+
13
+ def get(uri, query_params = {}, customer_access_token = nil)
14
+ execute(:get, uri, build_headers(customer_access_token), query_params, nil)
15
+ end
16
+
17
+ def post(uri, payload, query_params = {}, customer_access_token = nil)
18
+ execute(:post, uri, build_headers(customer_access_token), query_params, payload)
19
+ end
20
+
21
+ def patch(uri, payload, query_params = {}, customer_access_token = nil)
22
+ execute(:patch, uri, build_headers(customer_access_token), query_params, payload)
23
+ end
24
+
25
+ def delete(uri, query_params = {}, customer_access_token = nil)
26
+ execute(:delete, uri, build_headers(customer_access_token), query_params)
27
+ end
28
+
29
+ def build_uri(path)
30
+ URI.join(@base_uri, path).to_s
31
+ end
32
+
33
+ private
34
+
35
+ def execute(method, uri, headers, query_params = {}, payload = nil)
36
+ query = {
37
+ method: method,
38
+ url: uri,
39
+ headers: headers.merge(params: query_params),
40
+ payload: payload ? payload.to_json : nil,
41
+ ssl_client_cert: @certificate,
42
+ ssl_client_key: @key,
43
+ ssl_ca_file: @ssl_ca_file
44
+ }
45
+ raw_response = RestClient::Request.execute(query) do |response, request, result, &block|
46
+ if response.code >= 400
47
+ body = JSON.parse(response.body)
48
+ raise Ibanity::Error.new(body["errors"]), "Ibanity request failed."
49
+ else
50
+ response.return!(&block)
51
+ end
52
+ end
53
+ JSON.parse(raw_response)
54
+ end
55
+
56
+ def build_headers(customer_access_token = nil)
57
+ {
58
+ content_type: :json,
59
+ accept: :json,
60
+ authorization: customer_access_token.nil? ? nil : "Bearer #{customer_access_token}"
61
+ }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ module Ibanity
2
+ class Error < StandardError
3
+ attr_reader :errors
4
+
5
+ def initialize(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def to_s
10
+ @errors.map do |error|
11
+ if error["attribute"]
12
+ "* #{error["code"]}: '#{error["attribute"]}' #{error["message"]}"
13
+ else
14
+ "* #{error["code"]}: #{error["message"]}"
15
+ end
16
+ end.join("\n")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module Ibanity
2
+ module Util
3
+ def self.underscorize_hash(attributes)
4
+ attributes.keys.reduce({}) do |result, key|
5
+ result[underscore(key)] = attributes[key]
6
+ result
7
+ end
8
+ end
9
+
10
+ def self.underscore(camel_cased_word)
11
+ return camel_cased_word unless camel_cased_word =~ /[A-Z-]/
12
+ word = camel_cased_word.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
13
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
14
+ word.tr!("-", "_")
15
+ word.downcase!
16
+ word
17
+ end
18
+
19
+ def self.camelize(string, uppercase_first_letter = true)
20
+ string = if uppercase_first_letter
21
+ string.sub(/^[a-z\d]*/) { $&.capitalize }
22
+ else
23
+ string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
24
+ end
25
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }.gsub("/", "::")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Ibanity
2
+ VERSION = "0.1"
3
+ end
data/lib/ibanity.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "ostruct"
2
+ require "openssl"
3
+ require "uri"
4
+ require "rest_client"
5
+ require "json"
6
+
7
+ require_relative "ibanity/util"
8
+ require_relative "ibanity/error"
9
+ require_relative "ibanity/client"
10
+ require_relative "ibanity/api/base_resource"
11
+ require_relative "ibanity/api/customer"
12
+ require_relative "ibanity/api/account"
13
+ require_relative "ibanity/api/transaction"
14
+ require_relative "ibanity/api/financial_institution"
15
+ require_relative "ibanity/api/account_information_access_request"
16
+ require_relative "ibanity/api/payment_initiation_request"
17
+ require_relative "ibanity/api/fund_availability_access_request"
18
+ require_relative "ibanity/api/sandbox_account"
19
+ require_relative "ibanity/api/sandbox_transaction"
20
+ require_relative "ibanity/api/sandbox_user"
21
+ require_relative "ibanity/api/sandbox_financial_institution"
22
+ require_relative "ibanity/api/customer_access_token"
23
+
24
+ module Ibanity
25
+ class << self
26
+ def client
27
+ options = configuration.to_h.delete_if { |_, v| v.nil? }
28
+ @client ||= Ibanity::Client.new(options)
29
+ end
30
+
31
+ def configure
32
+ yield configuration
33
+ end
34
+
35
+ def configuration
36
+ @configuration ||= Struct.new(
37
+ :certificate,
38
+ :key,
39
+ :key_passphrase,
40
+ :api_scheme,
41
+ :api_host,
42
+ :api_port,
43
+ :ssl_ca_file
44
+ ).new
45
+ end
46
+
47
+ def api_schema
48
+ @api_schema ||= client.get(client.base_uri)["links"]
49
+ end
50
+
51
+ def respond_to_missing?(method_name, include_private = false)
52
+ client.respond_to?(method_name, include_private)
53
+ end
54
+
55
+ def method_missing(method_name, *args, &block)
56
+ if client.respond_to?(method_name)
57
+ client.__send__(method_name, *args, &block)
58
+ else
59
+ super
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ibanity
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ibanity
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.24.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.24.2
55
+ description: A Ruby wrapper for the Ibanity API.
56
+ email:
57
+ - info@ibanity.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".gitkeep"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ibanity.gemspec
69
+ - lib/ibanity.rb
70
+ - lib/ibanity/api/account.rb
71
+ - lib/ibanity/api/account_information_access_request.rb
72
+ - lib/ibanity/api/base_resource.rb
73
+ - lib/ibanity/api/customer.rb
74
+ - lib/ibanity/api/customer_access_token.rb
75
+ - lib/ibanity/api/financial_institution.rb
76
+ - lib/ibanity/api/fund_availability_access_request.rb
77
+ - lib/ibanity/api/payment_initiation_request.rb
78
+ - lib/ibanity/api/sandbox_account.rb
79
+ - lib/ibanity/api/sandbox_financial_institution.rb
80
+ - lib/ibanity/api/sandbox_transaction.rb
81
+ - lib/ibanity/api/sandbox_user.rb
82
+ - lib/ibanity/api/transaction.rb
83
+ - lib/ibanity/client.rb
84
+ - lib/ibanity/error.rb
85
+ - lib/ibanity/util.rb
86
+ - lib/ibanity/version.rb
87
+ homepage: https://documentation.ibanity.com/api/ruby
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.14
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ibanity Ruby Client
111
+ test_files: []