passfort 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +17 -17
  3. data/.rubocop.yml +8 -8
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +53 -48
  6. data/Gemfile +5 -5
  7. data/Gemfile.lock +95 -93
  8. data/LICENCE.txt +22 -22
  9. data/README.md +6 -6
  10. data/lib/passfort.rb +35 -35
  11. data/lib/passfort/client.rb +35 -35
  12. data/lib/passfort/endpoint.rb +10 -10
  13. data/lib/passfort/endpoint/checks.rb +19 -19
  14. data/lib/passfort/endpoint/profiles.rb +46 -46
  15. data/lib/passfort/endpoint/tasks.rb +16 -16
  16. data/lib/passfort/errors.rb +16 -16
  17. data/lib/passfort/errors/api_error.rb +16 -16
  18. data/lib/passfort/errors/bad_gateway_error.rb +12 -12
  19. data/lib/passfort/errors/chargeable_limit_reached_error.rb +12 -12
  20. data/lib/passfort/errors/invalid_api_key_error.rb +12 -12
  21. data/lib/passfort/errors/invalid_input_data_error.rb +12 -12
  22. data/lib/passfort/errors/request_error.rb +12 -12
  23. data/lib/passfort/errors/timeout_error.rb +12 -12
  24. data/lib/passfort/errors/unknown_api_error.rb +12 -12
  25. data/lib/passfort/errors/unparseable_response_error.rb +11 -11
  26. data/lib/passfort/http.rb +95 -95
  27. data/lib/passfort/resource.rb +13 -13
  28. data/lib/passfort/resource/base.rb +21 -21
  29. data/lib/passfort/resource/check.rb +10 -10
  30. data/lib/passfort/resource/company_data.rb +11 -11
  31. data/lib/passfort/resource/company_summary.rb +9 -9
  32. data/lib/passfort/resource/individual_data.rb +11 -11
  33. data/lib/passfort/resource/profile.rb +15 -15
  34. data/lib/passfort/resource/task.rb +9 -9
  35. data/lib/passfort/version.rb +5 -5
  36. data/passfort.gemspec +30 -30
  37. data/spec/fixtures/check.json +67 -67
  38. data/spec/fixtures/collected_data.json +7 -7
  39. data/spec/fixtures/companies.json +18 -18
  40. data/spec/fixtures/company_ownership_check/check.json +78 -78
  41. data/spec/fixtures/company_ownership_check/collected_data.json +7 -7
  42. data/spec/fixtures/company_ownership_check/collected_data_update_request.json +63 -63
  43. data/spec/fixtures/company_ownership_check/profile.json +128 -128
  44. data/spec/fixtures/profile.json +128 -128
  45. data/spec/fixtures/task.json +6 -6
  46. data/spec/integration/company_ownership_check_spec.rb +74 -74
  47. data/spec/passfort/client_spec.rb +43 -43
  48. data/spec/passfort/endpoint/checks_spec.rb +22 -22
  49. data/spec/passfort/endpoint/profiles_spec.rb +79 -79
  50. data/spec/passfort/endpoint/tasks_spec.rb +21 -21
  51. data/spec/passfort/http_spec.rb +167 -167
  52. data/spec/spec_helper.rb +9 -9
  53. metadata +5 -6
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Errors
5
- # Specific error class for when an HTTP request has timed out
6
- class TimeoutError < APIError
7
- def initialize
8
- super("Request timed out")
9
- end
10
- end
11
- end
12
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Errors
5
+ # Specific error class for when an HTTP request has timed out
6
+ class TimeoutError < APIError
7
+ def initialize
8
+ super("Request timed out")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Errors
5
- # Specific error class for when an unknown error is returned
6
- class UnknownApiError < APIError
7
- def initialize(*args)
8
- super("Unknown API error", *args)
9
- end
10
- end
11
- end
12
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Errors
5
+ # Specific error class for when an unknown error is returned
6
+ class UnknownApiError < APIError
7
+ def initialize(*args)
8
+ super("Unknown API error", *args)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Errors
5
- class UnparseableResponseError < APIError
6
- def initialize(*args)
7
- super("Unparseable response body", *args)
8
- end
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Errors
5
+ class UnparseableResponseError < APIError
6
+ def initialize(*args)
7
+ super("Unparseable response body", *args)
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/passfort/http.rb CHANGED
@@ -1,95 +1,95 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/notifications"
4
- require "excon"
5
- require "json"
6
-
7
- module Passfort
8
- class Http
9
- DOMAIN = "https://api.passfort.com"
10
- ROOT_PATH = "/4.0"
11
-
12
- attr_reader :api_key, :connection
13
-
14
- def initialize(api_key, excon_opts = {})
15
- @api_key = api_key
16
- uri = excon_opts[:domain] || DOMAIN
17
- @connection = Excon.new(uri, excon_opts.except(:domain))
18
- end
19
-
20
- def get(path)
21
- execute(
22
- -> {
23
- @connection.get(
24
- path: ROOT_PATH + path,
25
- headers: { apikey: @api_key },
26
- )
27
- },
28
- :get,
29
- path: path,
30
- )
31
- end
32
-
33
- def post(path, body:)
34
- execute(
35
- -> {
36
- @connection.post(
37
- path: ROOT_PATH + path,
38
- body: body.to_json,
39
- headers: { apikey: @api_key, "Content-Type" => "application/json" },
40
- )
41
- },
42
- :post,
43
- path: path,
44
- body: body,
45
- )
46
- end
47
-
48
- private
49
-
50
- def execute(get_response, method, payload)
51
- started = Time.now
52
- response = get_response.call
53
- payload[:response] = response.body
54
- body = JSON.parse(response.body)
55
- handle_error(response, body)
56
- body
57
- rescue JSON::ParserError => raw_error
58
- payload[:error] = raw_error
59
- raise Passfort::Errors::UnparseableResponseError.new([], response)
60
- rescue Excon::Errors::Timeout => raw_error
61
- payload[:error] = raw_error
62
- raise Passfort::Errors::TimeoutError
63
- rescue Excon::Error::BadGateway => raw_error
64
- payload[:error] = raw_error
65
- raise Passfort::Errors::BadGatewayError
66
- ensure
67
- publish("passfort.#{method}", started, Time.now, SecureRandom.hex(10), payload)
68
- end
69
-
70
- # error codes: https://passfort.com/developer/v4/data-reference/ErrorCodes
71
- def handle_error(response, body)
72
- unless [200, 201].include?(response.status)
73
- raise Passfort::Errors::RequestError.new([], response)
74
- end
75
-
76
- errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]
77
-
78
- handle_response_error(errors, response) if errors.any?
79
- end
80
-
81
- def handle_response_error(errors, response)
82
- error_class = case errors[0]["code"]
83
- when 201 then Passfort::Errors::InvalidInputDataError
84
- when 204 then Passfort::Errors::InvalidAPIKeyError
85
- when 104 then Passfort::Errors::ChargeableLimitReachedError
86
- else Passfort::Errors::UnknownApiError
87
- end
88
- raise error_class.new(errors, response)
89
- end
90
-
91
- def publish(*args)
92
- ActiveSupport::Notifications.publish(*args)
93
- end
94
- end
95
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/notifications"
4
+ require "excon"
5
+ require "json"
6
+
7
+ module Passfort
8
+ class Http
9
+ DOMAIN = "https://api.passfort.com"
10
+ ROOT_PATH = "/4.0"
11
+
12
+ attr_reader :api_key, :connection
13
+
14
+ def initialize(api_key, excon_opts = {})
15
+ @api_key = api_key
16
+ uri = excon_opts[:domain] || DOMAIN
17
+ @connection = Excon.new(uri, excon_opts.except(:domain))
18
+ end
19
+
20
+ def get(path)
21
+ execute(
22
+ -> {
23
+ @connection.get(
24
+ path: ROOT_PATH + path,
25
+ headers: { apikey: @api_key },
26
+ )
27
+ },
28
+ :get,
29
+ path: path,
30
+ )
31
+ end
32
+
33
+ def post(path, body:)
34
+ execute(
35
+ -> {
36
+ @connection.post(
37
+ path: ROOT_PATH + path,
38
+ body: body.to_json,
39
+ headers: { apikey: @api_key, "Content-Type" => "application/json" },
40
+ )
41
+ },
42
+ :post,
43
+ path: path,
44
+ body: body,
45
+ )
46
+ end
47
+
48
+ private
49
+
50
+ def execute(get_response, method, payload)
51
+ started = Time.now
52
+ response = get_response.call
53
+ payload[:response] = response.body
54
+ body = JSON.parse(response.body)
55
+ handle_error(response, body)
56
+ body
57
+ rescue JSON::ParserError => raw_error
58
+ payload[:error] = raw_error
59
+ raise Passfort::Errors::UnparseableResponseError.new([], response)
60
+ rescue Excon::Errors::Timeout => raw_error
61
+ payload[:error] = raw_error
62
+ raise Passfort::Errors::TimeoutError
63
+ rescue Excon::Error::BadGateway => raw_error
64
+ payload[:error] = raw_error
65
+ raise Passfort::Errors::BadGatewayError
66
+ ensure
67
+ publish("passfort.#{method}", started, Time.now, SecureRandom.hex(10), payload)
68
+ end
69
+
70
+ # error codes: https://passfort.com/developer/v4/data-reference/ErrorCodes
71
+ def handle_error(response, body)
72
+ unless [200, 201].include?(response.status)
73
+ raise Passfort::Errors::RequestError.new([], response)
74
+ end
75
+
76
+ errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]
77
+
78
+ handle_response_error(errors, response) if errors.any?
79
+ end
80
+
81
+ def handle_response_error(errors, response)
82
+ error_class = case errors[0]["code"]
83
+ when 201 then Passfort::Errors::InvalidInputDataError
84
+ when 204 then Passfort::Errors::InvalidAPIKeyError
85
+ when 104 then Passfort::Errors::ChargeableLimitReachedError
86
+ else Passfort::Errors::UnknownApiError
87
+ end
88
+ raise error_class.new(errors, response)
89
+ end
90
+
91
+ def publish(*args)
92
+ ActiveSupport::Notifications.publish(*args)
93
+ end
94
+ end
95
+ end
@@ -1,13 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort/resource/base"
4
- require "passfort/resource/profile"
5
- require "passfort/resource/company_data"
6
- require "passfort/resource/company_summary"
7
- require "passfort/resource/task"
8
- require "passfort/resource/check"
9
-
10
- module Passfort
11
- module Resource
12
- end
13
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort/resource/base"
4
+ require "passfort/resource/profile"
5
+ require "passfort/resource/company_data"
6
+ require "passfort/resource/company_summary"
7
+ require "passfort/resource/task"
8
+ require "passfort/resource/check"
9
+
10
+ module Passfort
11
+ module Resource
12
+ end
13
+ end
@@ -1,21 +1,21 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/core_ext/hash"
4
-
5
- module Passfort
6
- module Resource
7
- class Base
8
- def self.attributes(*keys)
9
- keys.each { |key| define_method(key) { @attributes[key] } }
10
- end
11
-
12
- def initialize(attributes)
13
- @attributes = attributes.with_indifferent_access
14
- end
15
-
16
- def to_h
17
- @attributes
18
- end
19
- end
20
- end
21
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/hash"
4
+
5
+ module Passfort
6
+ module Resource
7
+ class Base
8
+ def self.attributes(*keys)
9
+ keys.each { |key| define_method(key) { @attributes[key] } }
10
+ end
11
+
12
+ def initialize(attributes)
13
+ @attributes = attributes.with_indifferent_access
14
+ end
15
+
16
+ def to_h
17
+ @attributes
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Resource
5
- class Check < Base
6
- attributes :id, :check_type, :state, :input_data, :output_data, :result,
7
- :performed_on, :errors, :task_ids, :instructed_externally
8
- end
9
- end
10
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Resource
5
+ class Check < Base
6
+ attributes :id, :check_type, :state, :input_data, :output_data, :result,
7
+ :performed_on, :errors, :task_ids, :instructed_externally
8
+ end
9
+ end
10
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Resource
5
- class CompanyData < Base
6
- attributes :entity_type, :metadata, :authorized_persons,
7
- :unauthorized_persons, :ownership_structure, :officers,
8
- :filings, :customer_ref, :external_refs
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Resource
5
+ class CompanyData < Base
6
+ attributes :entity_type, :metadata, :authorized_persons,
7
+ :unauthorized_persons, :ownership_structure, :officers,
8
+ :filings, :customer_ref, :external_refs
9
+ end
10
+ end
11
+ end
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Resource
5
- class CompanySummary < Base
6
- attributes :name, :number, :country, :state
7
- end
8
- end
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Resource
5
+ class CompanySummary < Base
6
+ attributes :name, :number, :country, :state
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Passfort
4
- module Resource
5
- class IndividualData < Base
6
- attributes :entity_type, :personal_details, :address_history,
7
- :contact_details, :phone_number, :email, :ip_location,
8
- :documents
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Passfort
4
+ module Resource
5
+ class IndividualData < Base
6
+ attributes :entity_type, :personal_details, :address_history,
7
+ :contact_details, :phone_number, :email, :ip_location,
8
+ :documents
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort/resource/task"
4
-
5
- module Passfort
6
- module Resource
7
- class Profile < Base
8
- attributes :id, :role, :collected_data, :verified_data, :checks,
9
- :collection_steps, :display_name, :applications, :task_types,
10
- :tasks, :events, :category, :status, :document_images, :tags,
11
- :risk, :unresolved_event_types, :task_progress,
12
- :has_associates, :has_collection_steps
13
- end
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort/resource/task"
4
+
5
+ module Passfort
6
+ module Resource
7
+ class Profile < Base
8
+ attributes :id, :role, :collected_data, :verified_data, :checks,
9
+ :collection_steps, :display_name, :applications, :task_types,
10
+ :tasks, :events, :category, :status, :document_images, :tags,
11
+ :risk, :unresolved_event_types, :task_progress,
12
+ :has_associates, :has_collection_steps
13
+ end
14
+ end
15
+ end