bridge_bankin 0.1.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: dfe54b48509650b463422657a08f719b65ddbdd67f02c51acfb02cde720cf795
4
+ data.tar.gz: 789e29bc5b5f95a3a9dac2954c17c95a5a5420cff9fffd45e46d4dde85bfa0ad
5
+ SHA512:
6
+ metadata.gz: 8808c5e9381f0b3c79cab3c93663561e1f4e8688c172b752a39e02885694b910f669a026822f134d2e9c741400e31438af592e2481b794fe044f9c312ca3d9b4
7
+ data.tar.gz: 129b232bd2b76a61616deec2f430d1d3b59c3523f4cf802d36bf0ac142548124f40a648fb53f7f2b69e549cd629f6bfec196a478e5a6aa362432fcf94e310c3f
@@ -0,0 +1,24 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - "*"
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.7.2
20
+ - name: Run the default task
21
+ run: |
22
+ gem install bundler -v 2.2.1
23
+ bundle install
24
+ bundle exec rake
@@ -0,0 +1,13 @@
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
12
+
13
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,45 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/StringLiteralsInInterpolation:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+
17
+ Layout/LineLength:
18
+ Max: 120
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Metrics/BlockLength:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Enabled: false
28
+
29
+ Metrics/CyclomaticComplexity:
30
+ Max: 10
31
+
32
+ Metrics/MethodLength:
33
+ Max: 25
34
+
35
+ RSpec/ExampleLength:
36
+ Enabled: false
37
+
38
+ RSpec/MessageSpies:
39
+ Enabled: false
40
+
41
+ RSpec/SubjectStub:
42
+ Enabled: false
43
+
44
+ RSpec/MultipleDescribes:
45
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in sisense.gemspec
8
+ gemspec
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bridge_bankin (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.1.0)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ zeitwerk (~> 2.3)
15
+ addressable (2.7.0)
16
+ public_suffix (>= 2.0.2, < 5.0)
17
+ ast (2.4.1)
18
+ awesome_print (1.8.0)
19
+ coderay (1.1.3)
20
+ concurrent-ruby (1.1.7)
21
+ crack (0.4.5)
22
+ rexml
23
+ diff-lcs (1.4.4)
24
+ hashdiff (1.0.1)
25
+ i18n (1.8.5)
26
+ concurrent-ruby (~> 1.0)
27
+ method_source (1.0.0)
28
+ minitest (5.14.2)
29
+ parallel (1.20.1)
30
+ parser (3.0.0.0)
31
+ ast (~> 2.4.1)
32
+ pry (0.13.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ public_suffix (4.0.6)
36
+ rainbow (3.0.0)
37
+ rake (13.0.3)
38
+ regexp_parser (2.0.3)
39
+ rexml (3.2.4)
40
+ rspec (3.10.0)
41
+ rspec-core (~> 3.10.0)
42
+ rspec-expectations (~> 3.10.0)
43
+ rspec-mocks (~> 3.10.0)
44
+ rspec-core (3.10.1)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-expectations (3.10.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-mocks (3.10.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-support (3.10.1)
53
+ rubocop (1.7.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 2.7.1.5)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.8, < 3.0)
58
+ rexml
59
+ rubocop-ast (>= 1.2.0, < 2.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 1.4.0, < 2.0)
62
+ rubocop-ast (1.3.0)
63
+ parser (>= 2.7.1.5)
64
+ rubocop-rake (0.5.1)
65
+ rubocop
66
+ rubocop-rspec (2.1.0)
67
+ rubocop (~> 1.0)
68
+ rubocop-ast (>= 1.1.0)
69
+ ruby-progressbar (1.10.1)
70
+ shoulda-matchers (4.4.1)
71
+ activesupport (>= 4.2.0)
72
+ tzinfo (2.0.4)
73
+ concurrent-ruby (~> 1.0)
74
+ unicode-display_width (1.7.0)
75
+ vcr (6.0.0)
76
+ webmock (3.11.0)
77
+ addressable (>= 2.3.6)
78
+ crack (>= 0.3.2)
79
+ hashdiff (>= 0.4.0, < 2.0.0)
80
+ zeitwerk (2.4.2)
81
+
82
+ PLATFORMS
83
+ x86_64-darwin-19
84
+
85
+ DEPENDENCIES
86
+ awesome_print
87
+ bridge_bankin!
88
+ pry
89
+ rake
90
+ rspec
91
+ rubocop
92
+ rubocop-rake
93
+ rubocop-rspec
94
+ shoulda-matchers
95
+ vcr
96
+ webmock
97
+
98
+ BUNDLED WITH
99
+ 2.2.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Olivier Buffon
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,43 @@
1
+ # BridgeBankin
2
+
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bridge_bankin'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bridge_bankin
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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).
32
+
33
+ ## Contributing
34
+
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).
36
+
37
+ ## License
38
+
39
+ 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).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "bridge_bankin"
6
+ require "awesome_print"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "pry"
16
+ Pry.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,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridge_bankin/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridge_bankin"
7
+ spec.version = BridgeBankin::VERSION
8
+ spec.authors = ["Olivier Buffon"]
9
+ spec.email = ["olivier@buffon.dev"]
10
+
11
+ spec.summary = "Unofficial client to consume Bridge by Bankin’ API"
12
+
13
+ spec.description = "Thanks to a safe and automated access to bank data, Bridge powered by Bankin’ provides " \
14
+ "competitive and smart solutions to build conversion-driver financial services."
15
+
16
+ spec.homepage = "https://github.com/neatops/bridge_bankin"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, checkout our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+
39
+ spec.add_development_dependency "awesome_print"
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "rake"
42
+ spec.add_development_dependency "rspec"
43
+ spec.add_development_dependency "rubocop"
44
+ spec.add_development_dependency "rubocop-rake"
45
+ spec.add_development_dependency "rubocop-rspec"
46
+ spec.add_development_dependency "shoulda-matchers"
47
+ spec.add_development_dependency "vcr"
48
+ spec.add_development_dependency "webmock"
49
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configurations
4
+ require "bridge_bankin/configuration"
5
+ require "bridge_bankin/version"
6
+
7
+ # API
8
+ require "bridge_bankin/api/client"
9
+ require "bridge_bankin/api/resource"
10
+
11
+ # Business logic
12
+ require "bridge_bankin/bridge_object"
13
+ require "bridge_bankin/object_types"
14
+
15
+ # Resources
16
+ require "bridge_bankin/resources"
17
+
18
+ module BridgeBankin
19
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgeBankin
4
+ class Account < BridgeObject
5
+ RESOURCE_TYPE = "account"
6
+
7
+ class << self
8
+ include API::Resource
9
+
10
+ def list(access_token:, **params)
11
+ protected_resource(access_token) do
12
+ data = api_client.get("/v2/accounts", params)
13
+ convert_to_bridge_object(data)
14
+ end
15
+ end
16
+
17
+ def find(id:, access_token:, **params)
18
+ protected_resource(access_token) do
19
+ data = api_client.get("/v2/accounts/#{id}", params)
20
+ convert_to_bridge_object(data)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
6
+
7
+ require "bridge_bankin/api/error"
8
+
9
+ module BridgeBankin
10
+ module API
11
+ class Client
12
+ HTTP_VERBS_MAP = {
13
+ get: Net::HTTP::Get,
14
+ post: Net::HTTP::Post,
15
+ put: Net::HTTP::Put,
16
+ delete: Net::HTTP::Delete
17
+ }.freeze
18
+
19
+ attr_accessor :access_token
20
+
21
+ def get(path, **params)
22
+ request :get, path, params
23
+ end
24
+
25
+ def post(path, **params)
26
+ request :post, path, params
27
+ end
28
+
29
+ def put(path, **params)
30
+ request :put, path, params
31
+ end
32
+
33
+ def delete(path, **params)
34
+ request :delete, path, params
35
+ end
36
+
37
+ private
38
+
39
+ def request(method, path, params = {})
40
+ make_http_request do
41
+ HTTP_VERBS_MAP[method].new(encode_path(path, params), headers).tap do |request|
42
+ request.set_form_data(params) if method != :get
43
+ end
44
+ end
45
+ end
46
+
47
+ def make_http_request
48
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
49
+ api_response = http.request(yield)
50
+
51
+ return parse_response_body(api_response.body) if %w[200 201].include?(api_response.code)
52
+
53
+ handle_error(api_response)
54
+ end
55
+ end
56
+
57
+ def parse_response_body(json_response_body)
58
+ JSON.parse(json_response_body, symbolize_names: true)
59
+ end
60
+
61
+ def uri
62
+ @uri ||= URI.parse(BridgeBankin.configuration.api_base_url)
63
+ end
64
+
65
+ def headers
66
+ headers =
67
+ {
68
+ "Bankin-Version" => BridgeBankin.configuration.api_version,
69
+ "Client-Id" => BridgeBankin.configuration.api_client_id,
70
+ "Client-Secret" => BridgeBankin.configuration.api_client_secret,
71
+ "Content-Type" => "application/json"
72
+ }
73
+
74
+ return headers unless access_token
75
+
76
+ headers.merge!("Authorization" => "Bearer #{access_token}")
77
+ end
78
+
79
+ def encode_path(path, params = nil)
80
+ URI::HTTP
81
+ .build(path: path, query: URI.encode_www_form(params))
82
+ .request_uri
83
+ end
84
+
85
+ def handle_error(api_response)
86
+ response_body = parse_response_body(api_response.body)
87
+
88
+ case api_response.code
89
+ when "400"
90
+ raise API::BadRequestError.new(api_response.code, response_body)
91
+ when "401"
92
+ raise API::UnauthorizedError.new(api_response.code, response_body)
93
+ when "403"
94
+ raise API::ForbiddenError.new(api_response.code, response_body)
95
+ when "404"
96
+ raise API::NotFoundError.new(api_response.code, response_body)
97
+ when "409"
98
+ raise API::ConflictError.new(api_response.code, response_body)
99
+ when "415"
100
+ raise API::UnsupportedMediaTypeError.new(api_response.code, response_body)
101
+ when "422"
102
+ raise API::UnprocessableEntityError.new(api_response.code, response_body)
103
+ when "429"
104
+ raise API::TooManyRequestsError.new(api_response.code, response_body)
105
+ when "500"
106
+ raise API::InternalServerError.new(api_response.code, response_body)
107
+ else
108
+ raise API::Error.new(api_response.code, response_body)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end