swiftcodesapi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +43 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/swiftcodesapi/base_api.rb +45 -0
- data/lib/swiftcodesapi/configuration.rb +12 -0
- data/lib/swiftcodesapi/error.rb +6 -0
- data/lib/swiftcodesapi/iban.rb +55 -0
- data/lib/swiftcodesapi/ibans.rb +17 -0
- data/lib/swiftcodesapi/version.rb +5 -0
- data/lib/swiftcodesapi.rb +22 -0
- data/sig/swiftcodesapi.rbs +4 -0
- data/swiftcodesapi.gemspec +37 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c89e8b974a8efbbdbe7221f815ba2eb019442c8285ccb9bf6ce47e9802098f0
|
4
|
+
data.tar.gz: 222bd1b154f40b591e28a794439272dcf453a88f05e58267af2ed89e13287f52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c69580eacbc257affa71940139a63ba75f84ce3988cec40c53f09bb8e64fc5517b10f47493ef010b4092b7516567555a9eb4ce0be6bd7a5a56b6538d837d3e8
|
7
|
+
data.tar.gz: d94f3576b9c9f3901c838a146db8621a9b752ecbb67b443b875e18bc35ffd8238cb95a24a3a2182343da2f3bd7ebdbdf46b03cf506fe3b86317da77e4ddabeee
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
Layout/ParameterAlignment:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/MultilineMethodCallIndentation:
|
20
|
+
EnforcedStyle: indented
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/DoubleNegation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/FormatStringToken:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/NumericLiterals:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/TrailingCommaInArrayLiteral:
|
35
|
+
EnforcedStyleForMultiline: comma
|
36
|
+
|
37
|
+
Style/TrailingCommaInHashLiteral:
|
38
|
+
EnforcedStyleForMultiline: comma
|
39
|
+
|
40
|
+
Metrics/BlockLength:
|
41
|
+
Exclude:
|
42
|
+
- 'spec/**/*'
|
43
|
+
- '*.gemspec'
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in swiftcodesapi.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "faraday", "~> 2"
|
9
|
+
|
10
|
+
gem "rake", "~> 13.0"
|
11
|
+
|
12
|
+
gem "rspec", "~> 3.0"
|
13
|
+
|
14
|
+
gem "rubocop", "~> 1.21"
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem "webmock", "~> 3.8"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
swiftcodesapi (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
faraday (2.2.0)
|
16
|
+
faraday-net_http (~> 2.0)
|
17
|
+
ruby2_keywords (>= 0.0.4)
|
18
|
+
faraday-net_http (2.0.1)
|
19
|
+
hashdiff (1.0.1)
|
20
|
+
parallel (1.21.0)
|
21
|
+
parser (3.1.1.0)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
public_suffix (4.0.6)
|
24
|
+
rainbow (3.1.1)
|
25
|
+
rake (13.0.6)
|
26
|
+
regexp_parser (2.2.1)
|
27
|
+
rexml (3.2.5)
|
28
|
+
rspec (3.11.0)
|
29
|
+
rspec-core (~> 3.11.0)
|
30
|
+
rspec-expectations (~> 3.11.0)
|
31
|
+
rspec-mocks (~> 3.11.0)
|
32
|
+
rspec-core (3.11.0)
|
33
|
+
rspec-support (~> 3.11.0)
|
34
|
+
rspec-expectations (3.11.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.11.0)
|
37
|
+
rspec-mocks (3.11.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.11.0)
|
40
|
+
rspec-support (3.11.0)
|
41
|
+
rubocop (1.26.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.1.0.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml
|
47
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.16.0)
|
51
|
+
parser (>= 3.1.1.0)
|
52
|
+
ruby-progressbar (1.11.0)
|
53
|
+
ruby2_keywords (0.0.5)
|
54
|
+
unicode-display_width (2.1.0)
|
55
|
+
webmock (3.14.0)
|
56
|
+
addressable (>= 2.8.0)
|
57
|
+
crack (>= 0.3.2)
|
58
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-darwin-21
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
faraday (~> 2)
|
65
|
+
rake (~> 13.0)
|
66
|
+
rspec (~> 3.0)
|
67
|
+
rubocop (~> 1.21)
|
68
|
+
swiftcodesapi!
|
69
|
+
webmock (~> 3.8)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.3.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Lubomir Vnenk
|
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,39 @@
|
|
1
|
+
# Swiftcodesapi
|
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/swiftcodesapi`. 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 'swiftcodesapi'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install swiftcodesapi
|
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]/swiftcodesapi.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
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 "swiftcodesapi"
|
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,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swiftcodesapi
|
4
|
+
class BaseApi
|
5
|
+
API_URL = "/v1"
|
6
|
+
|
7
|
+
def self.request(uri, method = "POST", payload = nil)
|
8
|
+
client = initialize_client
|
9
|
+
|
10
|
+
response = client.send(method.downcase.to_sym) do |request|
|
11
|
+
request.headers["x-api-key"] = Swiftcodesapi.config.api_key
|
12
|
+
request.url("#{API_URL}#{uri}")
|
13
|
+
request.body = payload
|
14
|
+
end
|
15
|
+
|
16
|
+
raise ServiceError, response.body if response.status != 200
|
17
|
+
|
18
|
+
JSON.parse(response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.initialize_client
|
22
|
+
Faraday.new(url: Swiftcodesapi.config.api_url) do |faraday|
|
23
|
+
faraday.request :json
|
24
|
+
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get(path)
|
30
|
+
request(path, "GET")
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.post(path, payload)
|
34
|
+
request(path, "POST", payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.delete(path)
|
38
|
+
request(path, "DELETE")
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.put(path, payload)
|
42
|
+
request(path, "PUT", payload)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swiftcodesapi
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_key, :api_url
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@api_key = ENV["SWIFTCODESAPI_API_KEY"]
|
9
|
+
@api_url = ENV["SWIFTCODESAPI_API_URL"] || "https://swiftcodesapi.com"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swiftcodesapi
|
4
|
+
class Iban
|
5
|
+
attr_reader :data, :id, :account_number, :national_bank_code, :national_branch_code, :swift, :country_iso2
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@data = response["data"]
|
9
|
+
@id = data["id"]
|
10
|
+
@account_number = data["account_number"]
|
11
|
+
@national_bank_code = data["national_bank_code"]
|
12
|
+
@national_branch_code = data["national_branch_code"]
|
13
|
+
@swift = data["swift"]
|
14
|
+
@country_iso2 = data.dig("country", "id")
|
15
|
+
end
|
16
|
+
|
17
|
+
def swift_id
|
18
|
+
swift_data? && swift["id"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def swift_address
|
22
|
+
swift_data? && swift["address"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def swift_postcode
|
26
|
+
swift_data? && swift["postcode"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def swift_branch_name
|
30
|
+
swift_data? && swift["branch_name"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def swift_branch_code
|
34
|
+
swift_data? && swift["branch_code"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def swift_country_iso2
|
38
|
+
swift_data? && swift.dig("country", "id")
|
39
|
+
end
|
40
|
+
|
41
|
+
def swift_city
|
42
|
+
swift_data? && swift.dig("city", "name")
|
43
|
+
end
|
44
|
+
|
45
|
+
def swift_bank
|
46
|
+
swift_data? && swift.dig("bank", "name")
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def swift_data?
|
52
|
+
swift&.count&.positive?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swiftcodesapi
|
4
|
+
class Ibans < BaseApi
|
5
|
+
URL = "/ibans"
|
6
|
+
|
7
|
+
def self.find_by_iban(iban)
|
8
|
+
response = get("#{URL}/#{iban}")
|
9
|
+
raise IbanError, response["data"] unless response["success"]
|
10
|
+
|
11
|
+
Swiftcodesapi::Iban.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
class IbanError < Swiftcodesapi::Error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
require_relative "swiftcodesapi/error"
|
6
|
+
require_relative "swiftcodesapi/version"
|
7
|
+
require_relative "swiftcodesapi/configuration"
|
8
|
+
require_relative "swiftcodesapi/base_api"
|
9
|
+
require_relative "swiftcodesapi/iban"
|
10
|
+
require_relative "swiftcodesapi/ibans"
|
11
|
+
|
12
|
+
module Swiftcodesapi
|
13
|
+
@configuration = Configuration.new
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield(@configuration)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/swiftcodesapi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "swiftcodesapi"
|
7
|
+
spec.version = Swiftcodesapi::VERSION
|
8
|
+
spec.authors = ["Lubomir Vnenk"]
|
9
|
+
spec.email = ["lubomir.vnenk@zoho.com"]
|
10
|
+
|
11
|
+
spec.summary = "Gem to get iban info from swiftcodesapi.com"
|
12
|
+
spec.homepage = "https://github.com/lubosch/swiftcodesapi"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/lubosch/swiftcodesapi"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/lubosch/swiftcodesapi/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swiftcodesapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lubomir Vnenk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- lubomir.vnenk@zoho.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- lib/swiftcodesapi.rb
|
31
|
+
- lib/swiftcodesapi/base_api.rb
|
32
|
+
- lib/swiftcodesapi/configuration.rb
|
33
|
+
- lib/swiftcodesapi/error.rb
|
34
|
+
- lib/swiftcodesapi/iban.rb
|
35
|
+
- lib/swiftcodesapi/ibans.rb
|
36
|
+
- lib/swiftcodesapi/version.rb
|
37
|
+
- sig/swiftcodesapi.rbs
|
38
|
+
- swiftcodesapi.gemspec
|
39
|
+
homepage: https://github.com/lubosch/swiftcodesapi
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: https://github.com/lubosch/swiftcodesapi
|
44
|
+
source_code_uri: https://github.com/lubosch/swiftcodesapi
|
45
|
+
changelog_uri: https://github.com/lubosch/swiftcodesapi/blob/main/CHANGELOG.md
|
46
|
+
rubygems_mfa_required: 'true'
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.6.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.3.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Gem to get iban info from swiftcodesapi.com
|
66
|
+
test_files: []
|