metropol 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +92 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/metropol.rb +40 -0
- data/lib/metropol/client.rb +75 -0
- data/lib/metropol/default.rb +17 -0
- data/lib/metropol/legal_id.rb +28 -0
- data/lib/metropol/request.rb +78 -0
- data/lib/metropol/request/id_modifier.rb +44 -0
- data/lib/metropol/request/report_reason.rb +30 -0
- data/lib/metropol/version.rb +3 -0
- data/metropol.gemspec +31 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9e57370162782406161f87c39d49ba5593054334
|
|
4
|
+
data.tar.gz: 762ddbe89ffe76daaf72694913afdeee2f22d87b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 05d81db3c87c9857be5a56933a8afe40c469458d2958d17f3e53796b1ad95af9520319f64d5012893f00a949c498f940506ee7587283ba1e3d9fcbf3df4b9aed
|
|
7
|
+
data.tar.gz: 98b37f655dd03b309041d5a5378886e990e989cba6a0bb69046acd094fc725cc68d0b9470d45a93c1389875bc0b8aa1442b71a1ed3bc128ef5e83a45653b1e63
|
data/.gitignore
ADDED
data/.rspec
ADDED
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 alkarim.lalani@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 [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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
#git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
|
+
|
|
5
|
+
gem 'rest-client'
|
|
6
|
+
|
|
7
|
+
group :test do
|
|
8
|
+
gem 'rspec', '~> 3.5'
|
|
9
|
+
gem 'fuubar'
|
|
10
|
+
gem 'webmock'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Specify your gem's dependencies in metropol.gemspec
|
|
14
|
+
gemspec
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
metropol (0.1.0)
|
|
5
|
+
rest-client
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.5.2)
|
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
12
|
+
crack (0.4.3)
|
|
13
|
+
safe_yaml (~> 1.0.0)
|
|
14
|
+
diff-lcs (1.3)
|
|
15
|
+
domain_name (0.5.20170404)
|
|
16
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
17
|
+
fuubar (2.3.1)
|
|
18
|
+
rspec-core (~> 3.0)
|
|
19
|
+
ruby-progressbar (~> 1.4)
|
|
20
|
+
hashdiff (0.3.7)
|
|
21
|
+
http-cookie (1.0.3)
|
|
22
|
+
domain_name (~> 0.5)
|
|
23
|
+
mime-types (3.1)
|
|
24
|
+
mime-types-data (~> 3.2015)
|
|
25
|
+
mime-types-data (3.2016.0521)
|
|
26
|
+
netrc (0.11.0)
|
|
27
|
+
public_suffix (3.0.2)
|
|
28
|
+
rake (10.4.2)
|
|
29
|
+
rest-client (2.0.2)
|
|
30
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
31
|
+
mime-types (>= 1.16, < 4.0)
|
|
32
|
+
netrc (~> 0.8)
|
|
33
|
+
rspec (3.7.0)
|
|
34
|
+
rspec-core (~> 3.7.0)
|
|
35
|
+
rspec-expectations (~> 3.7.0)
|
|
36
|
+
rspec-mocks (~> 3.7.0)
|
|
37
|
+
rspec-core (3.7.1)
|
|
38
|
+
rspec-support (~> 3.7.0)
|
|
39
|
+
rspec-expectations (3.7.0)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.7.0)
|
|
42
|
+
rspec-mocks (3.7.0)
|
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
+
rspec-support (~> 3.7.0)
|
|
45
|
+
rspec-support (3.7.1)
|
|
46
|
+
ruby-progressbar (1.9.0)
|
|
47
|
+
safe_yaml (1.0.4)
|
|
48
|
+
unf (0.1.4)
|
|
49
|
+
unf_ext
|
|
50
|
+
unf_ext (0.0.7.5)
|
|
51
|
+
webmock (3.3.0)
|
|
52
|
+
addressable (>= 2.3.6)
|
|
53
|
+
crack (>= 0.3.2)
|
|
54
|
+
hashdiff
|
|
55
|
+
|
|
56
|
+
PLATFORMS
|
|
57
|
+
ruby
|
|
58
|
+
|
|
59
|
+
DEPENDENCIES
|
|
60
|
+
bundler (~> 1.16)
|
|
61
|
+
fuubar
|
|
62
|
+
metropol!
|
|
63
|
+
rake (~> 10.0)
|
|
64
|
+
rest-client
|
|
65
|
+
rspec (~> 3.5)
|
|
66
|
+
webmock
|
|
67
|
+
|
|
68
|
+
BUNDLED WITH
|
|
69
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Al-Karim Lalani
|
|
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,92 @@
|
|
|
1
|
+
Metropol
|
|
2
|
+
==============
|
|
3
|
+
metropol is a client for the [Metropol Credit Reference Bureau](https://www.metropol.co.ke/) API
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'metropol'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install metropol
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Create an instance of the Metropol client:
|
|
24
|
+
```ruby
|
|
25
|
+
client = Metropol::Client.new(public_key: 'YOUR_PUBLIC_KEY',
|
|
26
|
+
private_key: 'YOUR PRIVATE_KEY')
|
|
27
|
+
```
|
|
28
|
+
Or, configure the module directly
|
|
29
|
+
```ruby
|
|
30
|
+
Metropol.configure do |config|
|
|
31
|
+
config.public_key = 'YOUR_PUBLIC_KEY'
|
|
32
|
+
config.private_key = 'YOUR_PRIVATE_KEY'
|
|
33
|
+
config.port = 'YOUR_PORT' # Defaults to 5555
|
|
34
|
+
config.api_version = 'API_VERSION' # Defaults to 'v2_1'
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
### Making requests
|
|
38
|
+
Once you have a client (or have configured the module), you can start making requests.
|
|
39
|
+
|
|
40
|
+
There are 5 API methods you can call, and you can use the following Legal Identification Types to look up data: `national_id`, `passport`, `service_id`, `alien_registration`, `company_id`
|
|
41
|
+
|
|
42
|
+
##### verify
|
|
43
|
+
```ruby
|
|
44
|
+
# You can pass parameters to the method to specify the ID type and number:
|
|
45
|
+
client.verify(id_type: :national_id, id_number: 'ID_NUMBER_HERE')
|
|
46
|
+
# Or for convenience you can also do:
|
|
47
|
+
client.verify.national_id('ID_NUMBER_HERE')
|
|
48
|
+
# And lets say you want to look up a company's credit score
|
|
49
|
+
client.verify.company_id('ID_NUMBER_HERE')
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or, call the method directly on the module
|
|
53
|
+
```ruby
|
|
54
|
+
Metropol.verify.national_id('ID_NUMBER_HERE')
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
##### delinquency_status
|
|
58
|
+
```ruby
|
|
59
|
+
client.delinquency_status(id_type: :national_id, id_number: 'ID_NUMBER_HERE')
|
|
60
|
+
# Or
|
|
61
|
+
client.delinquency_status.national_id('ID_NUMBER_HERE')
|
|
62
|
+
# Or
|
|
63
|
+
Metropol.delinquency_status.company_id('ID_NUMBER_HERE')
|
|
64
|
+
```
|
|
65
|
+
##### credit_score
|
|
66
|
+
```ruby
|
|
67
|
+
Metropol.credit_score.national_id('ID_NUMBER_HERE')
|
|
68
|
+
# You know all the other variants by now
|
|
69
|
+
```
|
|
70
|
+
##### json_report
|
|
71
|
+
This method also takes a loan_amount parameter (defaults to 0) and a report_reason parameter which could be either: `:new_credit_app`, `:credit_review`, `:verify_credit_info` or `:customer_request` (defaults to `:new_credit_app`)
|
|
72
|
+
```ruby
|
|
73
|
+
Metropol.json_report(loan_amount: 2000).national_id('ID_NUMBER_HERE')
|
|
74
|
+
# Or
|
|
75
|
+
Metropol.json_report(loan_amount: 2000).new_credit_app.national_id('ID_NUMBER_HERE')
|
|
76
|
+
```
|
|
77
|
+
##### noncredit_data
|
|
78
|
+
```ruby
|
|
79
|
+
Metropol.noncredit_data.national_id('ID_NUMBER_HERE')
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Contributing
|
|
83
|
+
|
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alkarimlalani/metropol. 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.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
89
|
+
|
|
90
|
+
## Code of Conduct
|
|
91
|
+
|
|
92
|
+
Everyone interacting in the Metropol project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/metropol/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "metropol"
|
|
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__)
|
data/bin/setup
ADDED
data/lib/metropol.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'metropol/client'
|
|
2
|
+
require 'metropol/version'
|
|
3
|
+
|
|
4
|
+
module Metropol
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
|
|
8
|
+
attr_writer :public_key, :private_key, :port, :api_version
|
|
9
|
+
|
|
10
|
+
def client
|
|
11
|
+
@client ||= Metropol::Client.new(public_key: @public_key,
|
|
12
|
+
private_key: @private_key,
|
|
13
|
+
port: @port,
|
|
14
|
+
api_version: @api_version)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Set configuration variables using a block
|
|
18
|
+
def configure
|
|
19
|
+
yield self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_missing(method_name, *args, &block)
|
|
23
|
+
if client.respond_to?(method_name)
|
|
24
|
+
return client.send(method_name, *args, &block)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def reset!
|
|
31
|
+
@public_key = nil
|
|
32
|
+
@private_key = nil
|
|
33
|
+
@port = nil
|
|
34
|
+
@api_version = nil
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'metropol/legal_id'
|
|
2
|
+
require 'metropol/request'
|
|
3
|
+
|
|
4
|
+
module Metropol
|
|
5
|
+
class Client
|
|
6
|
+
include Metropol::LegalId
|
|
7
|
+
|
|
8
|
+
def initialize(public_key:, private_key:, port: nil, api_version: nil)
|
|
9
|
+
@public_key = public_key
|
|
10
|
+
@private_key = private_key
|
|
11
|
+
@port = port
|
|
12
|
+
@api_version = api_version
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def verify(id_type: nil, id_number: nil)
|
|
16
|
+
payload = {report_type: 1}
|
|
17
|
+
path = 'identity/verify'
|
|
18
|
+
fetch(path, payload, id_type, id_number)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def delinquency_status(loan_amount: 0, id_type: nil, id_number: nil)
|
|
22
|
+
payload = {report_type: 2, loan_amount: loan_amount}
|
|
23
|
+
path = 'delinquency/status'
|
|
24
|
+
fetch(path, payload, id_type, id_number)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def credit_score(id_type: nil, id_number: nil)
|
|
28
|
+
payload = {report_type: 3}
|
|
29
|
+
path = 'score/consumer'
|
|
30
|
+
fetch(path, payload, id_type, id_number)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def json_report(loan_amount: 0, report_reason: 1, id_type: nil, id_number: nil)
|
|
34
|
+
payload = {report_type: 8, loan_amount: loan_amount, report_reason: report_reason}
|
|
35
|
+
path = 'report/credit_info'
|
|
36
|
+
fetch(path, payload, id_type, id_number)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def noncredit_data(id_type: nil, id_number: nil)
|
|
40
|
+
payload = {report_type: 6}
|
|
41
|
+
path = 'identity/scrub'
|
|
42
|
+
fetch(path, payload, id_type, id_number)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# If a valid ID Type and number are given then
|
|
48
|
+
# returns a JSON object with the response payload.
|
|
49
|
+
# Else returns a Metropol::Request object that needs
|
|
50
|
+
# the ID Type and number data added to its payload
|
|
51
|
+
def fetch(path, payload, id_type, id_number)
|
|
52
|
+
request = unsent_request(path, payload)
|
|
53
|
+
|
|
54
|
+
if has_id_info? id_type, id_number
|
|
55
|
+
return request.send(id_type, id_number)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
request
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unsent_request(path, payload)
|
|
62
|
+
Request.new(public_key: @public_key,
|
|
63
|
+
private_key: @private_key,
|
|
64
|
+
path: path,
|
|
65
|
+
port: @port,
|
|
66
|
+
api_version: @api_version,
|
|
67
|
+
payload: payload)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def has_id_info?(id_type, id_number)
|
|
71
|
+
valid_id?(id_type) && !(id_number.nil?)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Metropol
|
|
2
|
+
|
|
3
|
+
# Default configuration options for Metropol API requests
|
|
4
|
+
module Default
|
|
5
|
+
|
|
6
|
+
HOST = 'api.metropol.co.ke'.freeze
|
|
7
|
+
PORT = 5555.freeze
|
|
8
|
+
API_VERSION = 'v2_1'.freeze
|
|
9
|
+
HEADERS = { 'Accept' => 'application/json',
|
|
10
|
+
'Content-Type' => 'application/json' }.freeze
|
|
11
|
+
|
|
12
|
+
def default_headers
|
|
13
|
+
return HEADERS.dup
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Metropol
|
|
2
|
+
module LegalId
|
|
3
|
+
|
|
4
|
+
ID_TYPES = {
|
|
5
|
+
national_id: '001',
|
|
6
|
+
passport: '002',
|
|
7
|
+
service_id: '003',
|
|
8
|
+
alien_registration: '004',
|
|
9
|
+
company_id: '005'
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
# Return the Metropol code for a given
|
|
13
|
+
# legal identity type
|
|
14
|
+
def code_for(id_type)
|
|
15
|
+
if valid_id? id_type
|
|
16
|
+
return ID_TYPES[id_type]
|
|
17
|
+
else
|
|
18
|
+
raise(ArgumentError,
|
|
19
|
+
'Invalid id_type. Please use a valid id_type for e.g. :national_id')
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def valid_id?(id_type)
|
|
24
|
+
return ID_TYPES.has_key? id_type
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'rest-client'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'digest'
|
|
5
|
+
require 'metropol/default'
|
|
6
|
+
require 'metropol/legal_id'
|
|
7
|
+
require 'metropol/request/id_modifier'
|
|
8
|
+
require 'metropol/request/report_reason'
|
|
9
|
+
|
|
10
|
+
module Metropol
|
|
11
|
+
class Request
|
|
12
|
+
include Metropol::Default
|
|
13
|
+
include Metropol::LegalId
|
|
14
|
+
include Metropol::Request::IdModifier
|
|
15
|
+
include Metropol::Request::ReportReason
|
|
16
|
+
|
|
17
|
+
def initialize(public_key:, private_key:, path:, port:, api_version:, payload: {})
|
|
18
|
+
@public_key = public_key
|
|
19
|
+
@private_key = private_key
|
|
20
|
+
@path = path
|
|
21
|
+
@port = port
|
|
22
|
+
@api_version = api_version
|
|
23
|
+
@payload = payload
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate_url
|
|
27
|
+
URI::HTTPS.build(
|
|
28
|
+
host: HOST,
|
|
29
|
+
port: port,
|
|
30
|
+
path: "/#{api_version}/#{@path}"
|
|
31
|
+
).to_s
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def generate_headers
|
|
35
|
+
timestamp = generate_timestamp
|
|
36
|
+
api_hash = generate_api_hash(timestamp)
|
|
37
|
+
|
|
38
|
+
headers = default_headers
|
|
39
|
+
headers['X-METROPOL-REST-API-KEY'] = @public_key
|
|
40
|
+
headers['X-METROPOL-REST-API-TIMESTAMP'] = timestamp
|
|
41
|
+
headers['X-METROPOL-REST-API-HASH'] = api_hash
|
|
42
|
+
headers
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def generate_timestamp
|
|
46
|
+
t = Time.now.utc
|
|
47
|
+
t.strftime('%Y%m%d%H%M%S%6N')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def generate_api_hash(timestamp)
|
|
51
|
+
json = JSON.generate(@payload)
|
|
52
|
+
str = @private_key + json + @public_key + timestamp
|
|
53
|
+
Digest::SHA256.hexdigest(str.encode('UTF-8'))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def post
|
|
57
|
+
url = generate_url
|
|
58
|
+
headers = generate_headers
|
|
59
|
+
resp = RestClient.post(url, payload_json, headers)
|
|
60
|
+
JSON.parse resp.body
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def port
|
|
66
|
+
@port || PORT
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def api_version
|
|
70
|
+
@api_version || API_VERSION
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def payload_json
|
|
74
|
+
@payload.to_json
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Metropol
|
|
2
|
+
class Request
|
|
3
|
+
# Methods to allow requests to specify legal ID in the method call
|
|
4
|
+
module IdModifier
|
|
5
|
+
|
|
6
|
+
# Add methods to specify the identity type and number
|
|
7
|
+
# of the request
|
|
8
|
+
# Usage:
|
|
9
|
+
# > client.verify.national_id('880000088')
|
|
10
|
+
def method_missing(method_name, *args, &block)
|
|
11
|
+
if valid_id? method_name
|
|
12
|
+
@payload[:identity_number] = args.first
|
|
13
|
+
@payload[:identity_type] = code_for(method_name)
|
|
14
|
+
sort_payload!
|
|
15
|
+
return post
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# Sorts the payload so that the first three params are:
|
|
24
|
+
# :report_type, :identity_number, :identity_type and
|
|
25
|
+
# then the remaining are in the order that they were
|
|
26
|
+
# inserted into the hash
|
|
27
|
+
#
|
|
28
|
+
# Note:
|
|
29
|
+
# - The Metropol API throws an error if the params
|
|
30
|
+
# are not in the order specified in their documentation.
|
|
31
|
+
# We rely on Ruby's sorted hashes to ensure that parameters
|
|
32
|
+
# are in order of insert
|
|
33
|
+
# - We implicitly assume that the keys :report_type,
|
|
34
|
+
# :identity_number and :identity_type are inserted in that order
|
|
35
|
+
def sort_payload!
|
|
36
|
+
partition = @payload.partition do |key, value|
|
|
37
|
+
[:report_type, :identity_number, :identity_type].include? key
|
|
38
|
+
end
|
|
39
|
+
@payload = partition.flatten(1).to_h
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Metropol
|
|
2
|
+
class Request
|
|
3
|
+
module ReportReason
|
|
4
|
+
|
|
5
|
+
REASON_TYPES = {
|
|
6
|
+
new_credit_app: 1,
|
|
7
|
+
credit_review: 2,
|
|
8
|
+
verify_credit_info: 3,
|
|
9
|
+
customer_request: 4
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
def valid_reason?(reason_type)
|
|
13
|
+
REASON_TYPES.has_key? reason_type
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Adds methods to specify the report reason
|
|
17
|
+
# Usage:
|
|
18
|
+
# > client.json_report.new_credit_app.national_id('880000088')
|
|
19
|
+
def method_missing(method_name, *args, &block)
|
|
20
|
+
if valid_reason? method_name
|
|
21
|
+
@payload[:report_reason] = REASON_TYPES[method_name]
|
|
22
|
+
return self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/metropol.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "metropol/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "metropol"
|
|
8
|
+
spec.version = Metropol::VERSION
|
|
9
|
+
spec.authors = ["Alkarim Lalani"]
|
|
10
|
+
spec.email = ["alkarim.lalani@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = 'A Ruby interface to the Metropol Credit Reference ' \
|
|
13
|
+
'Bureau API'
|
|
14
|
+
spec.description = 'Metropol is a Kenyan Credit Reference Bureau (CRB). ' \
|
|
15
|
+
'This Ruby library provides a simple interface to ' \
|
|
16
|
+
'their API'
|
|
17
|
+
spec.homepage = "https://github.com/alkarimlalani/metropol"
|
|
18
|
+
spec.license = "MIT"
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = "exe"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
29
|
+
|
|
30
|
+
spec.add_dependency "rest-client"
|
|
31
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: metropol
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alkarim Lalani
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-02-13 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: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rest-client
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Metropol is a Kenyan Credit Reference Bureau (CRB). This Ruby library
|
|
70
|
+
provides a simple interface to their API
|
|
71
|
+
email:
|
|
72
|
+
- alkarim.lalani@gmail.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".gitignore"
|
|
78
|
+
- ".rspec"
|
|
79
|
+
- ".travis.yml"
|
|
80
|
+
- CODE_OF_CONDUCT.md
|
|
81
|
+
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/setup
|
|
88
|
+
- lib/metropol.rb
|
|
89
|
+
- lib/metropol/client.rb
|
|
90
|
+
- lib/metropol/default.rb
|
|
91
|
+
- lib/metropol/legal_id.rb
|
|
92
|
+
- lib/metropol/request.rb
|
|
93
|
+
- lib/metropol/request/id_modifier.rb
|
|
94
|
+
- lib/metropol/request/report_reason.rb
|
|
95
|
+
- lib/metropol/version.rb
|
|
96
|
+
- metropol.gemspec
|
|
97
|
+
homepage: https://github.com/alkarimlalani/metropol
|
|
98
|
+
licenses:
|
|
99
|
+
- MIT
|
|
100
|
+
metadata: {}
|
|
101
|
+
post_install_message:
|
|
102
|
+
rdoc_options: []
|
|
103
|
+
require_paths:
|
|
104
|
+
- lib
|
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubyforge_project:
|
|
117
|
+
rubygems_version: 2.6.13
|
|
118
|
+
signing_key:
|
|
119
|
+
specification_version: 4
|
|
120
|
+
summary: A Ruby interface to the Metropol Credit Reference Bureau API
|
|
121
|
+
test_files: []
|