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,6 +1,6 @@
1
- {
2
- "type": "INDIVIDUAL_VERIFY_ADDRESS",
3
- "check_ids": [],
4
- "id": "33cdc540-61e0-11e7-b07b-acbc32b67d7b",
5
- "is_complete": false
6
- }
1
+ {
2
+ "type": "INDIVIDUAL_VERIFY_ADDRESS",
3
+ "check_ids": [],
4
+ "id": "33cdc540-61e0-11e7-b07b-acbc32b67d7b",
5
+ "is_complete": false
6
+ }
@@ -1,74 +1,74 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- # https://www.passfort.com/developer/recipes/running-a-company-ownership-check
6
- # rubocop:disable RSpec/DescribeClass
7
- # rubocop:disable RSpec/ExampleLength
8
- RSpec.describe "running a company ownership check" do
9
- let(:api_key) { "api_key" }
10
- let(:client) { Passfort::Client.new(api_key: api_key) }
11
-
12
- let(:profile_fixture) { load_fixture("company_ownership_check/profile.json") }
13
- let(:check_fixture) { load_fixture("company_ownership_check/check.json") }
14
- let(:collected_data_fixture) do
15
- load_fixture("company_ownership_check/collected_data.json")
16
- end
17
- let(:collected_data_update_fixture) do
18
- load_fixture("company_ownership_check/collected_data_update_request.json")
19
- end
20
-
21
- let(:profile_id) { JSON.parse(profile_fixture)["id"] }
22
- let(:create_profile_args) do
23
- {
24
- role: Passfort::Role::COMPANY_CUSTOMER,
25
- collected_data: {
26
- entity_type: Passfort::EntityType::COMPANY,
27
- metadata: {
28
- country_of_incorporation: "GBR",
29
- number: "09565115",
30
- },
31
- },
32
- }
33
- end
34
-
35
- before do
36
- stub_request(:post, %r{/profiles\z}).
37
- with(body: create_profile_args).
38
- to_return(status: 201, body: profile_fixture)
39
- stub_request(:post, %r{/profiles/#{profile_id}/checks\z}).
40
- with(body: { check_type: "COMPANY_OWNERSHIP" }).
41
- to_return(status: 201, body: check_fixture)
42
- stub_request(:get, %r{/profiles/#{profile_id}/collected_data\z}).
43
- to_return(
44
- status: 200,
45
- body: collected_data_fixture,
46
- )
47
- stub_request(:post, %r{/profiles/#{profile_id}/collected_data\z}).
48
- with(body: JSON.parse(collected_data_update_fixture)).
49
- to_return(
50
- status: 200,
51
- body: collected_data_fixture,
52
- )
53
- end
54
-
55
- it "succeeds" do
56
- profile = client.profiles.create(create_profile_args)
57
-
58
- expect(profile.id).to eq(profile_id)
59
-
60
- check = client.checks.create(profile_id: profile.id, check_type: "COMPANY_OWNERSHIP")
61
-
62
- shareholders = check.output_data[:ownership_structure][:shareholders]
63
- beneficial_owners = shareholders.select { |sh| sh[:total_percentage] >= 25 }
64
-
65
- collected_data = client.profiles.collected_data(profile.id).to_h
66
-
67
- collected_data[:ownership_structure] ||= {}
68
- collected_data[:ownership_structure][:shareholders] = beneficial_owners
69
-
70
- client.profiles.update_collected_data(profile.id, collected_data)
71
- end
72
- end
73
- # rubocop:enable RSpec/DescribeClass
74
- # rubocop:enable RSpec/ExampleLength
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # https://www.passfort.com/developer/recipes/running-a-company-ownership-check
6
+ # rubocop:disable RSpec/DescribeClass
7
+ # rubocop:disable RSpec/ExampleLength
8
+ RSpec.describe "running a company ownership check" do
9
+ let(:api_key) { "api_key" }
10
+ let(:client) { Passfort::Client.new(api_key: api_key) }
11
+
12
+ let(:profile_fixture) { load_fixture("company_ownership_check/profile.json") }
13
+ let(:check_fixture) { load_fixture("company_ownership_check/check.json") }
14
+ let(:collected_data_fixture) do
15
+ load_fixture("company_ownership_check/collected_data.json")
16
+ end
17
+ let(:collected_data_update_fixture) do
18
+ load_fixture("company_ownership_check/collected_data_update_request.json")
19
+ end
20
+
21
+ let(:profile_id) { JSON.parse(profile_fixture)["id"] }
22
+ let(:create_profile_args) do
23
+ {
24
+ role: Passfort::Role::COMPANY_CUSTOMER,
25
+ collected_data: {
26
+ entity_type: Passfort::EntityType::COMPANY,
27
+ metadata: {
28
+ country_of_incorporation: "GBR",
29
+ number: "09565115",
30
+ },
31
+ },
32
+ }
33
+ end
34
+
35
+ before do
36
+ stub_request(:post, %r{/profiles\z}).
37
+ with(body: create_profile_args).
38
+ to_return(status: 201, body: profile_fixture)
39
+ stub_request(:post, %r{/profiles/#{profile_id}/checks\z}).
40
+ with(body: { check_type: "COMPANY_OWNERSHIP" }).
41
+ to_return(status: 201, body: check_fixture)
42
+ stub_request(:get, %r{/profiles/#{profile_id}/collected_data\z}).
43
+ to_return(
44
+ status: 200,
45
+ body: collected_data_fixture,
46
+ )
47
+ stub_request(:post, %r{/profiles/#{profile_id}/collected_data\z}).
48
+ with(body: JSON.parse(collected_data_update_fixture)).
49
+ to_return(
50
+ status: 200,
51
+ body: collected_data_fixture,
52
+ )
53
+ end
54
+
55
+ it "succeeds" do
56
+ profile = client.profiles.create(create_profile_args)
57
+
58
+ expect(profile.id).to eq(profile_id)
59
+
60
+ check = client.checks.create(profile_id: profile.id, check_type: "COMPANY_OWNERSHIP")
61
+
62
+ shareholders = check.output_data[:ownership_structure][:shareholders]
63
+ beneficial_owners = shareholders.select { |sh| sh[:total_percentage] >= 25 }
64
+
65
+ collected_data = client.profiles.collected_data(profile.id).to_h
66
+
67
+ collected_data[:ownership_structure] ||= {}
68
+ collected_data[:ownership_structure][:shareholders] = beneficial_owners
69
+
70
+ client.profiles.update_collected_data(profile.id, collected_data)
71
+ end
72
+ end
73
+ # rubocop:enable RSpec/DescribeClass
74
+ # rubocop:enable RSpec/ExampleLength
@@ -1,43 +1,43 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Passfort::Client do
6
- let(:client) { described_class.new(api_key: "api_key") }
7
-
8
- describe "#company_search" do
9
- let(:result) { client.company_search(country, query, state, provider) }
10
-
11
- let(:country) { "GBR" }
12
- let(:query) { "GoCard" }
13
- let(:state) { nil }
14
- let(:provider) { "duedil" }
15
-
16
- before do
17
- stub_request(
18
- :get,
19
- %r{/search/companies\?country=#{country}&provider=#{provider}&query=#{query}\z},
20
- ).to_return(status: 200, body: load_fixture("companies.json"))
21
- end
22
-
23
- it "returns an array of companies" do
24
- expect(result).to be_a(Array)
25
- end
26
-
27
- it "returns expected number of companies" do
28
- expect(result.count).to eq(3)
29
- end
30
-
31
- it "returns right type of company summary resource" do
32
- expect(result[0]).to be_a(Passfort::Resource::CompanySummary)
33
- end
34
-
35
- it "returns maps company summary data" do
36
- expect(result[0]).to have_attributes(
37
- country: "GBR",
38
- name: "GOCARDLESS LTD",
39
- number: "07495895",
40
- )
41
- end
42
- end
43
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Passfort::Client do
6
+ let(:client) { described_class.new(api_key: "api_key") }
7
+
8
+ describe "#company_search" do
9
+ let(:result) { client.company_search(country, query, state, provider) }
10
+
11
+ let(:country) { "GBR" }
12
+ let(:query) { "GoCard" }
13
+ let(:state) { nil }
14
+ let(:provider) { "duedil" }
15
+
16
+ before do
17
+ stub_request(
18
+ :get,
19
+ %r{/search/companies\?country=#{country}&provider=#{provider}&query=#{query}\z},
20
+ ).to_return(status: 200, body: load_fixture("companies.json"))
21
+ end
22
+
23
+ it "returns an array of companies" do
24
+ expect(result).to be_a(Array)
25
+ end
26
+
27
+ it "returns expected number of companies" do
28
+ expect(result.count).to eq(3)
29
+ end
30
+
31
+ it "returns right type of company summary resource" do
32
+ expect(result[0]).to be_a(Passfort::Resource::CompanySummary)
33
+ end
34
+
35
+ it "returns maps company summary data" do
36
+ expect(result[0]).to have_attributes(
37
+ country: "GBR",
38
+ name: "GOCARDLESS LTD",
39
+ number: "07495895",
40
+ )
41
+ end
42
+ end
43
+ end
@@ -1,22 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Passfort::Endpoint::Checks do
6
- let(:endpoint) { described_class.new(Passfort::Http.new("api_key")) }
7
-
8
- describe "#create" do
9
- subject { endpoint.create(profile_id: profile_id, check_type: check_type) }
10
-
11
- let(:profile_id) { "a_profile_id" }
12
- let(:check_type) { "a_check_type" }
13
-
14
- before do
15
- stub_request(:post, %r{/profiles/#{profile_id}/checks\z}).
16
- with(body: { check_type: check_type }).
17
- to_return(status: 200, body: load_fixture("check.json"))
18
- end
19
-
20
- it { is_expected.to have_attributes(id: "6c1d594a-496e-11e7-911e-acbc32b67d7b") }
21
- end
22
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Passfort::Endpoint::Checks do
6
+ let(:endpoint) { described_class.new(Passfort::Http.new("api_key")) }
7
+
8
+ describe "#create" do
9
+ subject { endpoint.create(profile_id: profile_id, check_type: check_type) }
10
+
11
+ let(:profile_id) { "a_profile_id" }
12
+ let(:check_type) { "a_check_type" }
13
+
14
+ before do
15
+ stub_request(:post, %r{/profiles/#{profile_id}/checks\z}).
16
+ with(body: { check_type: check_type }).
17
+ to_return(status: 200, body: load_fixture("check.json"))
18
+ end
19
+
20
+ it { is_expected.to have_attributes(id: "6c1d594a-496e-11e7-911e-acbc32b67d7b") }
21
+ end
22
+ end
@@ -1,79 +1,79 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Passfort::Endpoint::Profiles do
6
- let(:profiles) { described_class.new(client) }
7
-
8
- let(:client) { instance_double(Passfort::Http) }
9
-
10
- let(:profile_fixture) { JSON.parse(load_fixture("profile.json")) }
11
- let(:collected_data_fixture) { JSON.parse(load_fixture("collected_data.json")) }
12
-
13
- describe "#create" do
14
- subject { profiles.create(role: role, collected_data: collected_data) }
15
-
16
- let(:role) { Passfort::Role::COMPANY_CUSTOMER }
17
- let(:collected_data) { {} }
18
-
19
- before do
20
- allow(client).
21
- to receive(:post).
22
- with("/profiles", body: { role: role, collected_data: collected_data }).
23
- and_return(profile_fixture)
24
- end
25
-
26
- it { is_expected.to have_attributes(id: profile_fixture["id"]) }
27
- end
28
-
29
- describe "#find" do
30
- subject { profiles.find(id) }
31
-
32
- let(:id) { profile_fixture["id"] }
33
-
34
- before do
35
- allow(client).to receive(:get).with("/profiles/#{id}").and_return(profile_fixture)
36
- end
37
-
38
- it { is_expected.to have_attributes(id: id) }
39
- end
40
-
41
- describe "#collected_data" do
42
- subject { profiles.collected_data(id) }
43
-
44
- let(:id) { profile_fixture["id"] }
45
-
46
- before do
47
- allow(client).
48
- to receive(:get).
49
- with("/profiles/#{id}/collected_data").
50
- and_return(collected_data_fixture)
51
- end
52
-
53
- it { is_expected.to have_attributes(entity_type: Passfort::EntityType::COMPANY) }
54
- it { is_expected.to be_a(Passfort::Resource::CompanyData) }
55
- end
56
-
57
- describe "#update_collected_data" do
58
- subject(:update_collected_data) { profiles.update_collected_data(id, data) }
59
-
60
- let(:id) { profile_fixture["id"] }
61
- let(:data) do
62
- collected_data_fixture.merge(metadata: { country_of_incorporation: "FR" })
63
- end
64
-
65
- before do
66
- allow(client).
67
- to receive(:post).
68
- with("/profiles/#{id}/collected_data", body: data).
69
- and_return(data)
70
- end
71
-
72
- it do
73
- expect(update_collected_data).to have_attributes(
74
- entity_type: Passfort::EntityType::COMPANY,
75
- metadata: { country_of_incorporation: "FR" },
76
- )
77
- end
78
- end
79
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Passfort::Endpoint::Profiles do
6
+ let(:profiles) { described_class.new(client) }
7
+
8
+ let(:client) { instance_double(Passfort::Http) }
9
+
10
+ let(:profile_fixture) { JSON.parse(load_fixture("profile.json")) }
11
+ let(:collected_data_fixture) { JSON.parse(load_fixture("collected_data.json")) }
12
+
13
+ describe "#create" do
14
+ subject { profiles.create(role: role, collected_data: collected_data) }
15
+
16
+ let(:role) { Passfort::Role::COMPANY_CUSTOMER }
17
+ let(:collected_data) { {} }
18
+
19
+ before do
20
+ allow(client).
21
+ to receive(:post).
22
+ with("/profiles", body: { role: role, collected_data: collected_data }).
23
+ and_return(profile_fixture)
24
+ end
25
+
26
+ it { is_expected.to have_attributes(id: profile_fixture["id"]) }
27
+ end
28
+
29
+ describe "#find" do
30
+ subject { profiles.find(id) }
31
+
32
+ let(:id) { profile_fixture["id"] }
33
+
34
+ before do
35
+ allow(client).to receive(:get).with("/profiles/#{id}").and_return(profile_fixture)
36
+ end
37
+
38
+ it { is_expected.to have_attributes(id: id) }
39
+ end
40
+
41
+ describe "#collected_data" do
42
+ subject { profiles.collected_data(id) }
43
+
44
+ let(:id) { profile_fixture["id"] }
45
+
46
+ before do
47
+ allow(client).
48
+ to receive(:get).
49
+ with("/profiles/#{id}/collected_data").
50
+ and_return(collected_data_fixture)
51
+ end
52
+
53
+ it { is_expected.to have_attributes(entity_type: Passfort::EntityType::COMPANY) }
54
+ it { is_expected.to be_a(Passfort::Resource::CompanyData) }
55
+ end
56
+
57
+ describe "#update_collected_data" do
58
+ subject(:update_collected_data) { profiles.update_collected_data(id, data) }
59
+
60
+ let(:id) { profile_fixture["id"] }
61
+ let(:data) do
62
+ collected_data_fixture.merge(metadata: { country_of_incorporation: "FR" })
63
+ end
64
+
65
+ before do
66
+ allow(client).
67
+ to receive(:post).
68
+ with("/profiles/#{id}/collected_data", body: data).
69
+ and_return(data)
70
+ end
71
+
72
+ it do
73
+ expect(update_collected_data).to have_attributes(
74
+ entity_type: Passfort::EntityType::COMPANY,
75
+ metadata: { country_of_incorporation: "FR" },
76
+ )
77
+ end
78
+ end
79
+ end