investec_open_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d69402eec4e9726ed5bfe503c817b6b179b53b5cd3658ae5d5906971482908da
4
+ data.tar.gz: f98b0b7abc269d4d915787061ae937ce6674a1d3a80bc94627490973e6a74c63
5
+ SHA512:
6
+ metadata.gz: 9fa72caba53822a4ed58cceae465e629044ba5a6b5c0699e546695d1f4ff91694253f410ae81b55bb7e8ad4713cd02f4e1052164fc0991f3e0413a564c94a876
7
+ data.tar.gz: 90cdd9eab5eb502edd1f6995a95d91780aa7def38f47c7957bbe0d4b7c64a62bd6a3259238f10b03341bcb0041d86da01bc03ba2389385c37250e8122a42240c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.5.4
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mkk0856@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in investec_open_api.gemspec
4
+ # gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "active_attr"
9
+ gem "money"
10
+ gem "faraday"
11
+ gem "faraday_middleware"
12
+ gem "webmock"
@@ -0,0 +1,101 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionpack (6.0.3.2)
5
+ actionview (= 6.0.3.2)
6
+ activesupport (= 6.0.3.2)
7
+ rack (~> 2.0, >= 2.0.8)
8
+ rack-test (>= 0.6.3)
9
+ rails-dom-testing (~> 2.0)
10
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
11
+ actionview (6.0.3.2)
12
+ activesupport (= 6.0.3.2)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
17
+ active_attr (0.15.0)
18
+ actionpack (>= 3.0.2, < 6.1)
19
+ activemodel (>= 3.0.2, < 6.1)
20
+ activesupport (>= 3.0.2, < 6.1)
21
+ activemodel (6.0.3.2)
22
+ activesupport (= 6.0.3.2)
23
+ activesupport (6.0.3.2)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 0.7, < 2)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ zeitwerk (~> 2.2, >= 2.2.2)
29
+ addressable (2.7.0)
30
+ public_suffix (>= 2.0.2, < 5.0)
31
+ builder (3.2.4)
32
+ concurrent-ruby (1.1.6)
33
+ crack (0.4.3)
34
+ safe_yaml (~> 1.0.0)
35
+ crass (1.0.6)
36
+ diff-lcs (1.4.4)
37
+ erubi (1.9.0)
38
+ faraday (1.0.1)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday_middleware (1.0.0)
41
+ faraday (~> 1.0)
42
+ hashdiff (1.0.1)
43
+ i18n (1.8.4)
44
+ concurrent-ruby (~> 1.0)
45
+ loofah (2.6.0)
46
+ crass (~> 1.0.2)
47
+ nokogiri (>= 1.5.9)
48
+ mini_portile2 (2.4.0)
49
+ minitest (5.14.1)
50
+ money (6.13.8)
51
+ i18n (>= 0.6.4, <= 2)
52
+ multipart-post (2.1.1)
53
+ nokogiri (1.10.10)
54
+ mini_portile2 (~> 2.4.0)
55
+ public_suffix (4.0.5)
56
+ rack (2.2.3)
57
+ rack-test (1.1.0)
58
+ rack (>= 1.0, < 3)
59
+ rails-dom-testing (2.0.3)
60
+ activesupport (>= 4.2.0)
61
+ nokogiri (>= 1.6)
62
+ rails-html-sanitizer (1.3.0)
63
+ loofah (~> 2.3)
64
+ rake (12.3.3)
65
+ rspec (3.9.0)
66
+ rspec-core (~> 3.9.0)
67
+ rspec-expectations (~> 3.9.0)
68
+ rspec-mocks (~> 3.9.0)
69
+ rspec-core (3.9.2)
70
+ rspec-support (~> 3.9.3)
71
+ rspec-expectations (3.9.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.9.0)
74
+ rspec-mocks (3.9.1)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.9.0)
77
+ rspec-support (3.9.3)
78
+ safe_yaml (1.0.5)
79
+ thread_safe (0.3.6)
80
+ tzinfo (1.2.7)
81
+ thread_safe (~> 0.1)
82
+ webmock (3.8.3)
83
+ addressable (>= 2.3.6)
84
+ crack (>= 0.3.2)
85
+ hashdiff (>= 0.4.0, < 2.0.0)
86
+ zeitwerk (2.4.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ active_attr
93
+ faraday
94
+ faraday_middleware
95
+ money
96
+ rake (~> 12.0)
97
+ rspec (~> 3.0)
98
+ webmock
99
+
100
+ BUNDLED WITH
101
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 OfferZen
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.
@@ -0,0 +1,68 @@
1
+ # InvestecOpenApi Client
2
+
3
+ A simple client wrapper for the [Investec Open API](https://developer.investec.com/programmable-banking/#open-api).
4
+
5
+ *Features:*
6
+
7
+ - Authorize access via OAuth
8
+ - Retrieve accounts
9
+ - Retrieve transactions per account
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'investec_open_api'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ $ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ $ gem install investec_open_api
29
+ ```
30
+
31
+ Create a new initializer called `investec_open_api.rb` in `config/initializers`:
32
+
33
+ ```ruby
34
+ InvestecOpenApi.configuration do |config|
35
+ config.api_username = "https://openapi.investec.com/"
36
+ config.api_password = "<Open API username>"
37
+ config.api_url = "<Open API password>"
38
+ end
39
+ ```
40
+
41
+ You will need to register for Open API access. Follow the steps in [Enrolment in the documentation](https://developer.investec.com/programmable-banking/#enrolment).
42
+
43
+
44
+ ## Usage
45
+
46
+ To use the wrapper, create an instance of `InvestecOpenApi::Client` and then authenticate with your credentials:
47
+
48
+ ```ruby
49
+ client = InvestecOpenApi::Client.new
50
+ client.authenticate!
51
+ ```
52
+
53
+ Once authenticated you can retrieve your accounts:
54
+
55
+ ```ruby
56
+ accounts = client.accounts
57
+ my_account = accounts.first
58
+ ```
59
+
60
+ Use the ID of one of your accounts to retrieve transactions:
61
+
62
+ ```ruby
63
+ client.transactions(my_account.id)
64
+ ```
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "investec_open_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,29 @@
1
+ require_relative 'lib/investec_open_api/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "investec_open_api"
5
+ spec.version = InvestecOpenApi::VERSION
6
+ spec.authors = ["Markus Kuhn", "Jethro Flanagan"]
7
+ spec.email = ["mkk0856@gmail.com", "jethroflanagan@gmail.com"]
8
+
9
+ spec.summary = %q{Investec Open API Wrapper}
10
+ spec.description = %q{A small wrapper client for accessing Investec's Open API}
11
+ spec.homepage = "https://github.com/offerzen/investec_open_api"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,14 @@
1
+ require "investec_open_api/version"
2
+ require "investec_open_api/models/base"
3
+
4
+ module InvestecOpenApi
5
+ class Error < StandardError; end
6
+
7
+ class << self
8
+ mattr_accessor :api_url, :api_username, :api_password, :scope
9
+ end
10
+
11
+ def self.configuration(&block)
12
+ yield self
13
+ end
14
+ end
@@ -0,0 +1,59 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "investec_open_api/models/account"
4
+ require "investec_open_api/models/transaction"
5
+
6
+ class InvestecOpenApi::Client
7
+ def authenticate!
8
+ @token = get_oauth_token["access_token"]
9
+ end
10
+
11
+ def accounts
12
+ response = connection.get("za/pb/v1/accounts")
13
+ response.body["data"]["accounts"].map do |account_raw|
14
+ InvestecOpenApi::Models::Account.from_api(account_raw)
15
+ end
16
+ end
17
+
18
+ def transactions(account_id)
19
+ response = connection.get("za/pb/v1/accounts/#{account_id}/transactions")
20
+ response.body["data"]["transactions"].map do |transaction_raw|
21
+ InvestecOpenApi::Models::Transaction.from_api(transaction_raw)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def get_oauth_token
28
+ auth_connection = Faraday.new(url: InvestecOpenApi.api_url) do |builder|
29
+ builder.headers["Accept"] = "application/json"
30
+ builder.basic_auth(InvestecOpenApi.api_username, InvestecOpenApi.api_password)
31
+ builder.response :raise_error
32
+ builder.response :json
33
+ builder.adapter Faraday.default_adapter
34
+ end
35
+
36
+ response = auth_connection.post("identity/v2/oauth2/token", {
37
+ grant_type: "client_credentials",
38
+ scope: "accounts"
39
+ }.to_query)
40
+
41
+ response.body
42
+ end
43
+
44
+ def connection
45
+ @_connection ||= Faraday.new(url: InvestecOpenApi.api_url) do |builder|
46
+ if @token
47
+ builder.headers["Authorization"] = "Bearer #{@token}"
48
+ end
49
+
50
+ builder.headers["Accept"] = "application/json"
51
+ builder.request :json
52
+
53
+ builder.response :raise_error
54
+ builder.response :json
55
+
56
+ builder.adapter Faraday.default_adapter
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ module InvestecOpenApi::Models
2
+ class Account < Base
3
+ attribute :id
4
+ attribute :number
5
+ attribute :name
6
+ attribute :reference_name
7
+ attribute :product_name
8
+
9
+ def self.from_api(params = {})
10
+ if params['accountId'].present?
11
+ params['id'] = params['accountId']
12
+ end
13
+
14
+ if params['accountNumber'].present?
15
+ params['number'] = params['accountNumber']
16
+ end
17
+
18
+ if params['accountName'].present?
19
+ params['name'] = params['accountName']
20
+ end
21
+
22
+ super
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require "active_attr"
2
+
3
+ module InvestecOpenApi::Models
4
+ class Base
5
+ include ActiveAttr::Model
6
+
7
+ def self.from_api(params = {})
8
+ underscored_params = params.deep_transform_keys do |key|
9
+ key.underscore.to_sym
10
+ end
11
+
12
+ new(underscored_params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require "money"
2
+
3
+ module InvestecOpenApi::Models
4
+ class Transaction < Base
5
+ attribute :account_id
6
+ attribute :type
7
+ attribute :status
8
+ attribute :card_number
9
+ attribute :amount
10
+ attribute :description
11
+ attribute :posting_date, type: Date
12
+ attribute :value_date, type: Date
13
+ attribute :action_date, type: Date
14
+
15
+ # At this point, there is no unique identifier being returned from Investec's API.
16
+ # This method serves to create a stable unique identifier based on the transaction details.
17
+ def id
18
+ [
19
+ amount.to_i,
20
+ description,
21
+ posting_date.to_s
22
+ ].map(&:to_s).join('-')
23
+ end
24
+
25
+ def self.from_api(params)
26
+ if params['amount'].present?
27
+ adjusted_amount = params['amount'] * 100
28
+ adjusted_amount = -adjusted_amount if params['type'] == 'DEBIT'
29
+ params['amount'] = Money.new(adjusted_amount, "ZAR")
30
+ end
31
+
32
+ super
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module InvestecOpenApi
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: investec_open_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Markus Kuhn
8
+ - Jethro Flanagan
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-07-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A small wrapper client for accessing Investec's Open API
15
+ email:
16
+ - mkk0856@gmail.com
17
+ - jethroflanagan@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - ".ruby-version"
25
+ - ".travis.yml"
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - investec_open_api.gemspec
35
+ - lib/investec_open_api.rb
36
+ - lib/investec_open_api/client.rb
37
+ - lib/investec_open_api/models/account.rb
38
+ - lib/investec_open_api/models/base.rb
39
+ - lib/investec_open_api/models/transaction.rb
40
+ - lib/investec_open_api/version.rb
41
+ homepage: https://github.com/offerzen/investec_open_api
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ allowed_push_host: https://rubygems.org
46
+ homepage_uri: https://github.com/offerzen/investec_open_api
47
+ source_code_uri: https://github.com/offerzen/investec_open_api
48
+ changelog_uri: https://github.com/offerzen/investec_open_api
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.3.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.0.8
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Investec Open API Wrapper
68
+ test_files: []