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,35 +1,35 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort/http"
4
-
5
- module Passfort
6
- class Client
7
- def initialize(api_key:, excon_opts: {})
8
- @http = Passfort::Http.new(api_key, excon_opts)
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
-
23
- def company_search(country, query, state = nil, provider = nil)
24
- search_query = "/search/companies?country=#{CGI.escape(country)}"
25
- search_query += "&query=#{CGI.escape(query)}"
26
- search_query += "&state=#{CGI.escape(state)}" unless state.nil?
27
- search_query += "&provider=#{CGI.escape(provider)}" unless provider.nil?
28
-
29
- response = @http.get(search_query)
30
- response["companies"].map do |company|
31
- Passfort::Resource::CompanySummary.new(company)
32
- end
33
- end
34
- end
35
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort/http"
4
+
5
+ module Passfort
6
+ class Client
7
+ def initialize(api_key:, excon_opts: {})
8
+ @http = Passfort::Http.new(api_key, excon_opts)
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
+
23
+ def company_search(country, query, state = nil, provider = nil)
24
+ search_query = "/search/companies?country=#{CGI.escape(country)}"
25
+ search_query += "&query=#{CGI.escape(query)}"
26
+ search_query += "&state=#{CGI.escape(state)}" unless state.nil?
27
+ search_query += "&provider=#{CGI.escape(provider)}" unless provider.nil?
28
+
29
+ response = @http.get(search_query)
30
+ response["companies"].map do |company|
31
+ Passfort::Resource::CompanySummary.new(company)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort/endpoint/profiles"
4
- require "passfort/endpoint/checks"
5
- require "passfort/endpoint/tasks"
6
-
7
- module Passfort
8
- module Endpoint
9
- end
10
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort/endpoint/profiles"
4
+ require "passfort/endpoint/checks"
5
+ require "passfort/endpoint/tasks"
6
+
7
+ module Passfort
8
+ module Endpoint
9
+ end
10
+ end
@@ -1,19 +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
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
@@ -1,46 +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
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
@@ -1,16 +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
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
@@ -1,16 +1,16 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort/errors/api_error"
4
- require "passfort/errors/unknown_api_error"
5
- require "passfort/errors/chargeable_limit_reached_error"
6
- require "passfort/errors/invalid_api_key_error"
7
- require "passfort/errors/invalid_input_data_error"
8
- require "passfort/errors/request_error"
9
- require "passfort/errors/unparseable_response_error"
10
- require "passfort/errors/timeout_error"
11
- require "passfort/errors/bad_gateway_error"
12
-
13
- module Passfort
14
- module Errors
15
- end
16
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort/errors/api_error"
4
+ require "passfort/errors/unknown_api_error"
5
+ require "passfort/errors/chargeable_limit_reached_error"
6
+ require "passfort/errors/invalid_api_key_error"
7
+ require "passfort/errors/invalid_input_data_error"
8
+ require "passfort/errors/request_error"
9
+ require "passfort/errors/unparseable_response_error"
10
+ require "passfort/errors/timeout_error"
11
+ require "passfort/errors/bad_gateway_error"
12
+
13
+ module Passfort
14
+ module Errors
15
+ end
16
+ end
@@ -1,16 +1,16 @@
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, :errors
8
-
9
- def initialize(msg, errors = [], response = nil)
10
- super(msg)
11
- @response = response
12
- @errors = errors
13
- end
14
- end
15
- end
16
- end
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, :errors
8
+
9
+ def initialize(msg, errors = [], response = nil)
10
+ super(msg)
11
+ @response = response
12
+ @errors = errors
13
+ end
14
+ end
15
+ end
16
+ end
@@ -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 returned a 502
6
- class BadGatewayError < APIError
7
- def initialize
8
- super("Request returned a bad gateway error")
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 returned a 502
6
+ class BadGatewayError < APIError
7
+ def initialize
8
+ super("Request returned a bad gateway error")
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 the chargeable limit has been reached
6
- class ChargeableLimitReachedError < APIError
7
- def initialize(*args)
8
- super("Rate limit exceeded", *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 the chargeable limit has been reached
6
+ class ChargeableLimitReachedError < APIError
7
+ def initialize(*args)
8
+ super("Rate limit exceeded", *args)
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 invalid API key is used to access the service
6
- class InvalidAPIKeyError < APIError
7
- def initialize(*args)
8
- super("Invalid API key", *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 invalid API key is used to access the service
6
+ class InvalidAPIKeyError < APIError
7
+ def initialize(*args)
8
+ super("Invalid API key", *args)
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 invalid input data is used to query the service
6
- class InvalidInputDataError < APIError
7
- def initialize(*args)
8
- super("Invalid input data", *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 invalid input data is used to query the service
6
+ class InvalidInputDataError < APIError
7
+ def initialize(*args)
8
+ super("Invalid input data", *args)
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 HTTP request error has occurred
6
- class RequestError < APIError
7
- def initialize(errors, response)
8
- super("Request API error - HTTP #{response.status}", errors, response)
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 error has occurred
6
+ class RequestError < APIError
7
+ def initialize(errors, response)
8
+ super("Request API error - HTTP #{response.status}", errors, response)
9
+ end
10
+ end
11
+ end
12
+ end