passfort 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +17 -0
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +89 -0
- data/LICENCE.txt +22 -0
- data/README.md +6 -0
- data/lib/passfort.rb +35 -0
- data/lib/passfort/client.rb +23 -0
- data/lib/passfort/endpoint.rb +10 -0
- data/lib/passfort/endpoint/checks.rb +19 -0
- data/lib/passfort/endpoint/profiles.rb +46 -0
- data/lib/passfort/endpoint/tasks.rb +16 -0
- data/lib/passfort/errors.rb +12 -0
- data/lib/passfort/errors/api_error.rb +15 -0
- data/lib/passfort/errors/chargeable_limit_reached_error.rb +12 -0
- data/lib/passfort/errors/invalid_api_key_error.rb +12 -0
- data/lib/passfort/errors/invalid_input_data_error.rb +12 -0
- data/lib/passfort/errors/request_error.rb +12 -0
- data/lib/passfort/http.rb +60 -0
- data/lib/passfort/resource.rb +12 -0
- data/lib/passfort/resource/base.rb +21 -0
- data/lib/passfort/resource/check.rb +10 -0
- data/lib/passfort/resource/company_data.rb +11 -0
- data/lib/passfort/resource/individual_data.rb +11 -0
- data/lib/passfort/resource/profile.rb +15 -0
- data/lib/passfort/resource/task.rb +9 -0
- data/lib/passfort/version.rb +5 -0
- data/passfort.gemspec +29 -0
- data/spec/fixtures/check.json +67 -0
- data/spec/fixtures/collected_data.json +7 -0
- data/spec/fixtures/company_ownership_check/check.json +78 -0
- data/spec/fixtures/company_ownership_check/collected_data.json +7 -0
- data/spec/fixtures/company_ownership_check/collected_data_update_request.json +63 -0
- data/spec/fixtures/company_ownership_check/profile.json +128 -0
- data/spec/fixtures/profile.json +128 -0
- data/spec/fixtures/task.json +6 -0
- data/spec/integration/company_ownership_check_spec.rb +74 -0
- data/spec/passfort/endpoint/checks_spec.rb +22 -0
- data/spec/passfort/endpoint/profiles_spec.rb +79 -0
- data/spec/passfort/endpoint/tasks_spec.rb +21 -0
- data/spec/passfort/http_spec.rb +91 -0
- data/spec/spec_helper.rb +9 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11120072e170612a1a224a7e5494a78401ac7c840b9efd54e43c104948f0c9fd
|
4
|
+
data.tar.gz: 035174f509a2106dd5ea314517ec24b503d6d22b30100c64c935f360b6860396
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5041f41f44de8502abe4b7d3c0b4d59570e5ad629b66c74b10980cad3333c4bb3ce19fbaeb050a3e4a9355caa394df365586c1f883a57746d6546470d290700
|
7
|
+
data.tar.gz: 94f245e7d800b9bfbf7ca0b40db72f5f37894bd56a8df125858c703cfcd742a00a324c50d28421fc3ccc60e09423ad9d198feae5d3d5b6bb2fef5595600b66a6
|
@@ -0,0 +1,17 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: ~/passfort
|
5
|
+
docker:
|
6
|
+
- image: ruby:2.5
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
key: gemfile-lock-{{ checksum "Gemfile.lock" }}
|
11
|
+
- run: bundle install --deployment
|
12
|
+
- save_cache:
|
13
|
+
key: gemfile-lock-{{ checksum "Gemfile.lock" }}
|
14
|
+
paths:
|
15
|
+
- "vendor/bundle"
|
16
|
+
- run: bundle exec rubocop
|
17
|
+
- run: bundle exec rspec --format RspecJunitFormatter
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
passfort (0.2.0)
|
5
|
+
activesupport (~> 5.0)
|
6
|
+
excon (~> 0.60)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.1.5)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
addressable (2.5.2)
|
17
|
+
public_suffix (>= 2.0.2, < 4.0)
|
18
|
+
ast (2.4.0)
|
19
|
+
coderay (1.1.2)
|
20
|
+
concurrent-ruby (1.0.5)
|
21
|
+
crack (0.4.3)
|
22
|
+
safe_yaml (~> 1.0.0)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
excon (0.60.0)
|
25
|
+
gc_ruboconfig (2.3.4)
|
26
|
+
rubocop (~> 0.53.0)
|
27
|
+
rubocop-rspec (~> 1.24)
|
28
|
+
hashdiff (0.3.7)
|
29
|
+
i18n (0.9.5)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
method_source (0.9.0)
|
32
|
+
minitest (5.11.3)
|
33
|
+
parallel (1.12.1)
|
34
|
+
parser (2.5.0.3)
|
35
|
+
ast (~> 2.4.0)
|
36
|
+
powerpack (0.1.1)
|
37
|
+
pry (0.11.3)
|
38
|
+
coderay (~> 1.1.0)
|
39
|
+
method_source (~> 0.9.0)
|
40
|
+
public_suffix (3.0.1)
|
41
|
+
rainbow (3.0.0)
|
42
|
+
rspec (3.7.0)
|
43
|
+
rspec-core (~> 3.7.0)
|
44
|
+
rspec-expectations (~> 3.7.0)
|
45
|
+
rspec-mocks (~> 3.7.0)
|
46
|
+
rspec-core (3.7.1)
|
47
|
+
rspec-support (~> 3.7.0)
|
48
|
+
rspec-expectations (3.7.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.7.0)
|
51
|
+
rspec-mocks (3.7.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.7.0)
|
54
|
+
rspec-support (3.7.1)
|
55
|
+
rspec_junit_formatter (0.3.0)
|
56
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
57
|
+
rubocop (0.53.0)
|
58
|
+
parallel (~> 1.10)
|
59
|
+
parser (>= 2.5)
|
60
|
+
powerpack (~> 0.1)
|
61
|
+
rainbow (>= 2.2.2, < 4.0)
|
62
|
+
ruby-progressbar (~> 1.7)
|
63
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
64
|
+
rubocop-rspec (1.24.0)
|
65
|
+
rubocop (>= 0.53.0)
|
66
|
+
ruby-progressbar (1.9.0)
|
67
|
+
safe_yaml (1.0.4)
|
68
|
+
thread_safe (0.3.6)
|
69
|
+
tzinfo (1.2.5)
|
70
|
+
thread_safe (~> 0.1)
|
71
|
+
unicode-display_width (1.3.0)
|
72
|
+
webmock (3.3.0)
|
73
|
+
addressable (>= 2.3.6)
|
74
|
+
crack (>= 0.3.2)
|
75
|
+
hashdiff
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
gc_ruboconfig (~> 2.3)
|
82
|
+
passfort!
|
83
|
+
pry (~> 0.10)
|
84
|
+
rspec (~> 3.2)
|
85
|
+
rspec_junit_formatter (~> 0.3)
|
86
|
+
webmock (~> 3.3)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
1.16.1
|
data/LICENCE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 GoCardless
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/lib/passfort.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "passfort/version"
|
4
|
+
require "passfort/errors"
|
5
|
+
|
6
|
+
require "passfort/resource"
|
7
|
+
require "passfort/endpoint"
|
8
|
+
require "passfort/client"
|
9
|
+
|
10
|
+
module Passfort
|
11
|
+
module CheckType
|
12
|
+
IDENTITY_CHECK = "IDENTITY_CHECK"
|
13
|
+
DOCUMENT_VERIFICATION = "DOCUMENT_VERIFICATION"
|
14
|
+
DOCUMENT_FETCH = "DOCUMENT_FETCH"
|
15
|
+
PEPS_SCREEN = "PEPS_SCREEN"
|
16
|
+
SANCTIONS_SCREEN = "SANCTIONS_SCREEN"
|
17
|
+
PEPS_AND_SANCTIONS_SCREEN = "PEPS_AND_SANCTIONS_SCREEN"
|
18
|
+
COMPANY_REGISTRY = "COMPANY_REGISTRY"
|
19
|
+
COMPANY_OWNERSHIP = "COMPANY_OWNERSHIP"
|
20
|
+
COMPANY_FILINGS = "COMPANY_FILINGS"
|
21
|
+
COMPANY_FILING_PURCHASE = "COMPANY_FILING_PURCHASE"
|
22
|
+
COMPANY_PEPS_AND_SANCTIONS_SCREEN = "COMPANY_PEPS_AND_SANCTIONS_SCREEN"
|
23
|
+
end
|
24
|
+
|
25
|
+
module EntityType
|
26
|
+
INDIVIDUAL = "INDIVIDUAL"
|
27
|
+
COMPANY = "COMPANY"
|
28
|
+
end
|
29
|
+
|
30
|
+
module Role
|
31
|
+
INDIVIDUAL_CUSTOMER = "INDIVIDUAL_CUSTOMER"
|
32
|
+
INDIVIDUAL_ASSOCIATED = "INDIVIDUAL_ASSOCIATED"
|
33
|
+
COMPANY_CUSTOMER = "COMPANY_CUSTOMER"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "passfort/http"
|
4
|
+
|
5
|
+
module Passfort
|
6
|
+
class Client
|
7
|
+
def initialize(api_key:)
|
8
|
+
@http = Passfort::Http.new(api_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def profiles
|
12
|
+
Endpoint::Profiles.new(@http)
|
13
|
+
end
|
14
|
+
|
15
|
+
def checks
|
16
|
+
Endpoint::Checks.new(@http)
|
17
|
+
end
|
18
|
+
|
19
|
+
def tasks
|
20
|
+
Endpoint::Tasks.new(@http)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Endpoint
|
5
|
+
class Checks
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(profile_id:, check_type:)
|
11
|
+
response = @client.post(
|
12
|
+
"/profiles/#{profile_id}/checks",
|
13
|
+
body: { check_type: check_type },
|
14
|
+
)
|
15
|
+
Passfort::Resource::Check.new(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "passfort/resource/profile"
|
4
|
+
|
5
|
+
module Passfort
|
6
|
+
module Endpoint
|
7
|
+
class Profiles
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(role:, collected_data: {})
|
13
|
+
profile = @client.post(
|
14
|
+
"/profiles",
|
15
|
+
body: { role: role, collected_data: collected_data },
|
16
|
+
)
|
17
|
+
::Passfort::Resource::Profile.new(profile)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(id)
|
21
|
+
profile = @client.get("/profiles/#{id}")
|
22
|
+
::Passfort::Resource::Profile.new(profile)
|
23
|
+
end
|
24
|
+
|
25
|
+
def collected_data(id)
|
26
|
+
collected_data = @client.get("/profiles/#{id}/collected_data")
|
27
|
+
resource_class(collected_data["entity_type"]).new(collected_data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_collected_data(id, data)
|
31
|
+
collected_data = @client.post("/profiles/#{id}/collected_data", body: data)
|
32
|
+
resource_class(collected_data["entity_type"]).new(collected_data)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def resource_class(entity_type)
|
38
|
+
case entity_type
|
39
|
+
when Passfort::EntityType::COMPANY then ::Passfort::Resource::CompanyData
|
40
|
+
when Passfort::EntityType::INDIVIDUAL then ::Passfort::Resource::IndividualData
|
41
|
+
else raise ArgumentError, "Invalid entity type #{entity_type.inspect}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Endpoint
|
5
|
+
class Tasks
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(profile_id:, task_id:)
|
11
|
+
response = @client.get("/profiles/#{profile_id}/tasks/#{task_id}")
|
12
|
+
Passfort::Resource::Task.new(response)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "passfort/errors/api_error"
|
4
|
+
require "passfort/errors/chargeable_limit_reached_error"
|
5
|
+
require "passfort/errors/invalid_api_key_error"
|
6
|
+
require "passfort/errors/invalid_input_data_error"
|
7
|
+
require "passfort/errors/request_error"
|
8
|
+
|
9
|
+
module Passfort
|
10
|
+
module Errors
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Errors
|
5
|
+
# Represents any response from the API which is not a 200 OK
|
6
|
+
class APIError < StandardError
|
7
|
+
attr_reader :response
|
8
|
+
|
9
|
+
def initialize(msg, response = nil)
|
10
|
+
super(msg)
|
11
|
+
@response = response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Errors
|
5
|
+
# Specific error class for when the chargeable limit has been reached
|
6
|
+
class ChargeableLimitReachedError < APIError
|
7
|
+
def initialize(response = nil)
|
8
|
+
super("Rate limit exceeded", response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Errors
|
5
|
+
# Specific error class for when an invalid API key is used to access the service
|
6
|
+
class InvalidAPIKeyError < APIError
|
7
|
+
def initialize(response = nil)
|
8
|
+
super("Invalid API key", response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Errors
|
5
|
+
# Specific error class for when an invalid input data is used to query the service
|
6
|
+
class InvalidInputDataError < APIError
|
7
|
+
def initialize(response = nil)
|
8
|
+
super("Invalid input data", response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Passfort
|
4
|
+
module Errors
|
5
|
+
# Specific error class for when an HTTP request error has occurred
|
6
|
+
class RequestError < APIError
|
7
|
+
def initialize(response)
|
8
|
+
super("Request API error - HTTP #{response.status}", response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "excon"
|
5
|
+
|
6
|
+
module Passfort
|
7
|
+
class Http
|
8
|
+
DOMAIN = "https://api.passfort.com"
|
9
|
+
ROOT_PATH = "/4.0"
|
10
|
+
|
11
|
+
def initialize(api_key, connection: Excon.new(DOMAIN))
|
12
|
+
@api_key = api_key
|
13
|
+
@connection = connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
response = @connection.get(path: ROOT_PATH + path, headers: { apikey: @api_key })
|
18
|
+
body = JSON.parse(response.body)
|
19
|
+
handle_error(response, body)
|
20
|
+
body
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(path, body:)
|
24
|
+
response = @connection.post(
|
25
|
+
path: ROOT_PATH + path,
|
26
|
+
body: body.to_json,
|
27
|
+
headers: { apikey: @api_key, "Content-Type" => "application/json" },
|
28
|
+
)
|
29
|
+
body = JSON.parse(response.body)
|
30
|
+
handle_error(response, body)
|
31
|
+
body
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# error codes: https://passfort.com/developer/v4/data-reference/ErrorCodes
|
37
|
+
def handle_error(response, body)
|
38
|
+
unless [200, 201].include?(response.status)
|
39
|
+
raise Passfort::Errors::RequestError, response
|
40
|
+
end
|
41
|
+
|
42
|
+
errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]
|
43
|
+
|
44
|
+
handle_response_error(errors[0], response) if errors.any?
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_response_error(error, response)
|
48
|
+
case error["code"]
|
49
|
+
when 201
|
50
|
+
raise Passfort::Errors::InvalidInputDataError, response
|
51
|
+
when 204
|
52
|
+
raise Passfort::Errors::InvalidAPIKeyError, response
|
53
|
+
when 104
|
54
|
+
raise Passfort::Errors::ChargeableLimitReachedError, response
|
55
|
+
else
|
56
|
+
raise Passfort::Errors::APIError.new("Unknown API error", response)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|