credit_card_finder 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +52 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/credit_card_finder.gemspec +43 -0
- data/lib/credit_card_finder/clients/bincodes.rb +92 -0
- data/lib/credit_card_finder/config.rb +20 -0
- data/lib/credit_card_finder/proxy.rb +37 -0
- data/lib/credit_card_finder/strategies/base_strategy.rb +27 -0
- data/lib/credit_card_finder/strategies/bincodes_strategy.rb +21 -0
- data/lib/credit_card_finder/strategies/credit_card_bins_strategy.rb +38 -0
- data/lib/credit_card_finder/version.rb +5 -0
- data/lib/credit_card_finder.rb +23 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9da1b9e2dca8b06f8a2742e4127537c008eec889
|
4
|
+
data.tar.gz: 29bf10980429137907793e676d9a5f0e5e2706d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe370c21c42295848bd7548ab7fa8802b607516cc4789f4ef05d844e63d1dd2f3781f16726b206500f651d679510eebd02eba2dab6d204ce43dd7029fd104115
|
7
|
+
data.tar.gz: 5ee9fed3465760da6188d7a82d2d5d9de2946a31dbb62146e78db8cb69f17e74143a7af94f51ff01b742e8f270f107fdacd755aeb8d4f3b64c306f7bab29fa72
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# This is the configuration used to check the rubocop source code.
|
2
|
+
|
3
|
+
inherit_from:
|
4
|
+
- https://raw.githubusercontent.com/serverscom/best-practices/master/.rubocop.yml
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 2.3
|
8
|
+
Exclude:
|
9
|
+
- '*/tmp/**/*'
|
10
|
+
Include:
|
11
|
+
- '**/Gemfile'
|
12
|
+
- '**/*.gemspec'
|
13
|
+
- '**/*.rb'
|
14
|
+
|
15
|
+
Style/AsciiComments:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Performance/Casecmp:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/FirstArrayElementLineBreak:
|
22
|
+
Enabled: true
|
23
|
+
Layout/FirstHashElementLineBreak:
|
24
|
+
Enabled: true
|
25
|
+
Layout/FirstMethodArgumentLineBreak:
|
26
|
+
Enabled: true
|
27
|
+
Layout/FirstMethodParameterLineBreak:
|
28
|
+
Enabled: true
|
29
|
+
Layout/FirstParameterIndentation:
|
30
|
+
Enabled: true
|
31
|
+
Layout/MultilineArrayBraceLayout:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyle: new_line
|
34
|
+
Layout/MultilineHashBraceLayout:
|
35
|
+
Enabled: true
|
36
|
+
EnforcedStyle: new_line
|
37
|
+
Layout/MultilineMethodCallBraceLayout:
|
38
|
+
Enabled: true
|
39
|
+
EnforcedStyle: symmetrical
|
40
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
41
|
+
Enabled: true
|
42
|
+
EnforcedStyle: symmetrical
|
43
|
+
Layout/DotPosition:
|
44
|
+
Enabled: true
|
45
|
+
EnforcedStyle: leading
|
46
|
+
Layout/MultilineMethodCallIndentation:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/BlockLength:
|
50
|
+
Exclude:
|
51
|
+
- 'spec/**/*.rb'
|
52
|
+
- '*.gemspec'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 sa@servers.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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
credit_card_finder (0.1.0)
|
5
|
+
credit_card_bins
|
6
|
+
dry-configurable
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
byebug (10.0.2)
|
15
|
+
coderay (1.1.2)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
crack (0.4.3)
|
18
|
+
safe_yaml (~> 1.0.0)
|
19
|
+
credit_card_bins (0.0.2)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
dry-configurable (0.7.0)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
hashdiff (0.3.7)
|
24
|
+
method_source (0.9.0)
|
25
|
+
parallel (1.12.1)
|
26
|
+
parser (2.5.1.0)
|
27
|
+
ast (~> 2.4.0)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
pry (0.11.3)
|
30
|
+
coderay (~> 1.1.0)
|
31
|
+
method_source (~> 0.9.0)
|
32
|
+
pry-byebug (3.6.0)
|
33
|
+
byebug (~> 10.0)
|
34
|
+
pry (~> 0.10)
|
35
|
+
public_suffix (3.0.2)
|
36
|
+
rainbow (3.0.0)
|
37
|
+
rake (10.5.0)
|
38
|
+
rspec (3.7.0)
|
39
|
+
rspec-core (~> 3.7.0)
|
40
|
+
rspec-expectations (~> 3.7.0)
|
41
|
+
rspec-mocks (~> 3.7.0)
|
42
|
+
rspec-core (3.7.1)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-expectations (3.7.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.7.0)
|
47
|
+
rspec-mocks (3.7.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.7.0)
|
50
|
+
rspec-support (3.7.1)
|
51
|
+
rubocop (0.56.0)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 2.5)
|
54
|
+
powerpack (~> 0.1)
|
55
|
+
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
ruby-progressbar (~> 1.7)
|
57
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
58
|
+
ruby-progressbar (1.9.0)
|
59
|
+
safe_yaml (1.0.4)
|
60
|
+
unicode-display_width (1.3.3)
|
61
|
+
vcr (4.0.0)
|
62
|
+
webmock (3.4.1)
|
63
|
+
addressable (>= 2.3.6)
|
64
|
+
crack (>= 0.3.2)
|
65
|
+
hashdiff
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
ruby
|
69
|
+
|
70
|
+
DEPENDENCIES
|
71
|
+
bundler (~> 1.16)
|
72
|
+
credit_card_finder!
|
73
|
+
pry-byebug
|
74
|
+
rake (~> 10.0)
|
75
|
+
rspec (~> 3.7)
|
76
|
+
rubocop
|
77
|
+
vcr (~> 4.0.0)
|
78
|
+
webmock
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sergei Alekseenko
|
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,60 @@
|
|
1
|
+
# CreditCardFinder
|
2
|
+
|
3
|
+
This gem allows you to find some credit card information by BIN/IIN code. Now it uses two strategies for search. First strategy use 'credit_card_bins' gem and provide search in YAML files.
|
4
|
+
Second strategy use bincodes.com API (so you will need register and get api key).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'credit_card_finder'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install credit_card_finder
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
CreditCardFinder::Config.configure do |config|
|
26
|
+
config.bincodes.api_key = 'your_api_key'
|
27
|
+
|
28
|
+
# set timeout for api request
|
29
|
+
config.bincodes.timeout = 10 # already set by default
|
30
|
+
|
31
|
+
# alredy set by default
|
32
|
+
config.strategies = %w[CreditCardBinsStrategy BincodesStrategy]
|
33
|
+
|
34
|
+
# also you can use custom logger instance
|
35
|
+
config.logger = Logger.new(STDOUT)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
If you want use strategies for search, you just need make call:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
bin = '427664'
|
45
|
+
CreditCardFinder.lookup(bin)
|
46
|
+
```
|
47
|
+
|
48
|
+
By default that call will be search firstly in YAML files via `credit_card_bins` gem, and if find nothing, will search via bincodes.com.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/serverscom/credit-card-finder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the CreditCardFinder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serverscom/credit-card-finder/blob/master/CODE_OF_CONDUCT.md).
|
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 'credit_card_finder'
|
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,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'credit_card_finder/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'credit_card_finder'
|
9
|
+
spec.version = CreditCardFinder::VERSION
|
10
|
+
spec.authors = ['Sergei Alekseenko']
|
11
|
+
spec.email = ['sa@servers.com']
|
12
|
+
|
13
|
+
spec.summary = 'Find credit card information by BIN/IIN'
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'pry-byebug'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
37
|
+
spec.add_development_dependency 'rubocop'
|
38
|
+
spec.add_development_dependency 'vcr', '~> 4.0.0'
|
39
|
+
spec.add_development_dependency 'webmock'
|
40
|
+
|
41
|
+
spec.add_dependency 'credit_card_bins'
|
42
|
+
spec.add_runtime_dependency 'dry-configurable'
|
43
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module CreditCardFinder
|
8
|
+
module Clients
|
9
|
+
class Bincodes
|
10
|
+
BIN_RANGE = 0..5
|
11
|
+
|
12
|
+
attr_reader :data, :errors
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@errors = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch(code)
|
19
|
+
response = nil
|
20
|
+
uri = uri(code.to_s[BIN_RANGE])
|
21
|
+
|
22
|
+
Net::HTTP.start(uri.host, uri.port, read_timeout: timeout, use_ssl: true) do |http|
|
23
|
+
request = Net::HTTP::Get.new(uri)
|
24
|
+
response = http.request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
handle_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
@errors.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def invalid?
|
35
|
+
!valid?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def logger
|
41
|
+
CreditCardFinder.logger
|
42
|
+
end
|
43
|
+
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
45
|
+
def handle_response(response)
|
46
|
+
unless response.is_a?(Net::HTTPSuccess)
|
47
|
+
halt_unexpected_error(response)
|
48
|
+
return self
|
49
|
+
end
|
50
|
+
|
51
|
+
body = JSON.parse(response.body)
|
52
|
+
if body.key?('error')
|
53
|
+
halt_service_error(body)
|
54
|
+
return self
|
55
|
+
end
|
56
|
+
|
57
|
+
@data = body
|
58
|
+
logger.info("Fetch credit card data bin #{body['bin']} from #{endpoint_host}")
|
59
|
+
self
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/MethodLength
|
62
|
+
|
63
|
+
def halt_service_error(body)
|
64
|
+
@errors[:code] = body['error']
|
65
|
+
@errors[:message] = body['message']
|
66
|
+
logger.error("BincodesError: [#{errors[:code]}] #{errors[:message]}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def halt_unexpected_error(response)
|
70
|
+
@errors[:code] = response.code
|
71
|
+
@errors[:message] = "Unexpected error from #{endpoint_host}"
|
72
|
+
logger.error("BincodesError: #{endpoint_host}. #{response.code}, #{response.body}")
|
73
|
+
end
|
74
|
+
|
75
|
+
def timeout
|
76
|
+
CreditCardFinder.config.bincodes.timeout || 10
|
77
|
+
end
|
78
|
+
|
79
|
+
def endpoint_host
|
80
|
+
CreditCardFinder.config.bincodes.api_url
|
81
|
+
end
|
82
|
+
|
83
|
+
def api_key
|
84
|
+
CreditCardFinder.config.bincodes.api_key
|
85
|
+
end
|
86
|
+
|
87
|
+
def uri(code)
|
88
|
+
URI("#{endpoint_host}/bin/json/#{api_key}/#{code}/")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'dry-configurable'
|
5
|
+
|
6
|
+
module CreditCardFinder
|
7
|
+
class Config
|
8
|
+
extend Dry::Configurable
|
9
|
+
|
10
|
+
setting :bincodes do
|
11
|
+
setting :api_key, '11111111111111'
|
12
|
+
setting :api_url, 'https://api.bincodes.com'
|
13
|
+
setting :timeout, 10
|
14
|
+
end
|
15
|
+
|
16
|
+
setting :strategies, %w[CreditCardBinsStrategy BincodesStrategy]
|
17
|
+
|
18
|
+
setting :logger, Logger.new(STDOUT)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CreditCardFinder
|
4
|
+
class Proxy
|
5
|
+
attr_reader :strategies
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@strategies ||= resolve_strategies
|
9
|
+
end
|
10
|
+
|
11
|
+
def lookup(code)
|
12
|
+
run_strategies(code)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def run_strategies(code)
|
18
|
+
strategies.each do |strategy|
|
19
|
+
strategy_class = search_strategy(strategy)
|
20
|
+
next if strategy_class.nil?
|
21
|
+
result = strategy_class.new.lookup(code)
|
22
|
+
return result if result
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def resolve_strategies
|
28
|
+
CreditCardFinder.config.strategies
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_strategy(strategy)
|
32
|
+
Object.const_get("CreditCardFinder::Strategies::#{strategy}")
|
33
|
+
rescue NameError
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CreditCardFinder
|
4
|
+
module Strategies
|
5
|
+
class BaseStrategy
|
6
|
+
CARD_INFO_METHODS = %w[
|
7
|
+
bin
|
8
|
+
bank
|
9
|
+
card
|
10
|
+
type
|
11
|
+
level
|
12
|
+
country
|
13
|
+
countrycode
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
CARD_INFO_METHODS.each do |m|
|
17
|
+
define_method(m) do
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def lookup(_code)
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CreditCardFinder
|
4
|
+
module Strategies
|
5
|
+
class BincodesStrategy < BaseStrategy
|
6
|
+
def lookup(code)
|
7
|
+
res = CreditCardFinder::Clients::Bincodes.new.fetch(code)
|
8
|
+
return if res.invalid?
|
9
|
+
|
10
|
+
@card_data = res.data
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
CARD_INFO_METHODS.each do |m|
|
15
|
+
define_method(m) do
|
16
|
+
@card_data.fetch(m, nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'credit_card_bins'
|
4
|
+
|
5
|
+
module CreditCardFinder
|
6
|
+
module Strategies
|
7
|
+
class CreditCardBinsStrategy < BaseStrategy
|
8
|
+
CARD_INFO_MATCHING = {
|
9
|
+
'bin' => 'bin',
|
10
|
+
'bank' => 'issuer',
|
11
|
+
'card' => 'brand',
|
12
|
+
'type' => 'type',
|
13
|
+
'level' => 'category'
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
def lookup(number)
|
17
|
+
@card_data = CreditCardBin.new(number).data
|
18
|
+
self
|
19
|
+
rescue NotFound
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
(CARD_INFO_METHODS - %w[country countrycode]).each do |m|
|
24
|
+
define_method(m) do
|
25
|
+
@card_data.fetch(CARD_INFO_MATCHING[m], nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def country
|
30
|
+
@card_data.fetch('country', {})['name']
|
31
|
+
end
|
32
|
+
|
33
|
+
def countrycode
|
34
|
+
@card_data.fetch('country', {})['alpha_2']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'credit_card_finder/clients/bincodes'
|
4
|
+
require 'credit_card_finder/strategies/base_strategy'
|
5
|
+
require 'credit_card_finder/strategies/credit_card_bins_strategy'
|
6
|
+
require 'credit_card_finder/strategies/bincodes_strategy'
|
7
|
+
require 'credit_card_finder/proxy'
|
8
|
+
require 'credit_card_finder/config'
|
9
|
+
require 'credit_card_finder/version'
|
10
|
+
|
11
|
+
module CreditCardFinder
|
12
|
+
def self.config
|
13
|
+
@config ||= Config.config
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.lookup(code)
|
17
|
+
Proxy.new.lookup(code)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger
|
21
|
+
@logger ||= config.logger
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: credit_card_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergei Alekseenko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: credit_card_bins
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: dry-configurable
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- sa@servers.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- credit_card_finder.gemspec
|
159
|
+
- lib/credit_card_finder.rb
|
160
|
+
- lib/credit_card_finder/clients/bincodes.rb
|
161
|
+
- lib/credit_card_finder/config.rb
|
162
|
+
- lib/credit_card_finder/proxy.rb
|
163
|
+
- lib/credit_card_finder/strategies/base_strategy.rb
|
164
|
+
- lib/credit_card_finder/strategies/bincodes_strategy.rb
|
165
|
+
- lib/credit_card_finder/strategies/credit_card_bins_strategy.rb
|
166
|
+
- lib/credit_card_finder/version.rb
|
167
|
+
homepage: ''
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
metadata:
|
171
|
+
allowed_push_host: https://rubygems.org
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.5.2
|
189
|
+
signing_key:
|
190
|
+
specification_version: 4
|
191
|
+
summary: Find credit card information by BIN/IIN
|
192
|
+
test_files: []
|