passfort 0.4.1 → 0.4.2

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.
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,21 +1,21 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe Passfort::Endpoint::Tasks do
6
- let(:endpoint) { described_class.new(Passfort::Http.new("api_key")) }
7
-
8
- describe "#find" do
9
- subject { endpoint.find(profile_id: profile_id, task_id: task_id) }
10
-
11
- let(:profile_id) { "a_profile_id" }
12
- let(:task_id) { "a_task_id" }
13
-
14
- before do
15
- stub_request(:get, %r{/profiles/#{profile_id}/tasks/#{task_id}\z}).
16
- to_return(status: 200, body: load_fixture("task.json"))
17
- end
18
-
19
- it { is_expected.to have_attributes(id: "33cdc540-61e0-11e7-b07b-acbc32b67d7b") }
20
- end
21
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Passfort::Endpoint::Tasks do
6
+ let(:endpoint) { described_class.new(Passfort::Http.new("api_key")) }
7
+
8
+ describe "#find" do
9
+ subject { endpoint.find(profile_id: profile_id, task_id: task_id) }
10
+
11
+ let(:profile_id) { "a_profile_id" }
12
+ let(:task_id) { "a_task_id" }
13
+
14
+ before do
15
+ stub_request(:get, %r{/profiles/#{profile_id}/tasks/#{task_id}\z}).
16
+ to_return(status: 200, body: load_fixture("task.json"))
17
+ end
18
+
19
+ it { is_expected.to have_attributes(id: "33cdc540-61e0-11e7-b07b-acbc32b67d7b") }
20
+ end
21
+ end
@@ -1,167 +1,167 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "timecop"
5
-
6
- RSpec.describe Passfort::Http do
7
- let(:http) { described_class.new("api_key") }
8
- let(:path) { "a/path" }
9
-
10
- shared_examples "an API call that handles all errors" do
11
- let(:api_path) { Passfort::Http::DOMAIN + Passfort::Http::ROOT_PATH + path }
12
- let(:status) { 200 }
13
- let(:error_code) { 0 }
14
- let(:body) { { errors: { code: error_code } }.to_json }
15
-
16
- before { stub_request(method, api_path).to_return(status: status, body: body) }
17
-
18
- context "when returning a request error" do
19
- let(:status) { 404 }
20
- let(:error_class) { Passfort::Errors::RequestError }
21
-
22
- it { is_expected.to raise_error(error_class) }
23
- end
24
-
25
- context "when returning an invalid API Key error" do
26
- let(:error_code) { 204 }
27
- let(:error_class) { Passfort::Errors::InvalidAPIKeyError }
28
-
29
- it { is_expected.to raise_error(error_class) }
30
- end
31
-
32
- context "when returning an invalid input data error" do
33
- let(:error_code) { 201 }
34
- let(:error_class) { Passfort::Errors::InvalidInputDataError }
35
-
36
- it { is_expected.to raise_error(error_class) }
37
- end
38
-
39
- context "when returning a chargeable limit reached error" do
40
- let(:error_code) { 104 }
41
- let(:error_class) { Passfort::Errors::ChargeableLimitReachedError }
42
-
43
- it { is_expected.to raise_error(error_class) }
44
- end
45
-
46
- context "when returning an unknown API error" do
47
- let(:error_code) { 203 }
48
- let(:error_class) { Passfort::Errors::UnknownApiError }
49
-
50
- it { is_expected.to raise_error(error_class) }
51
- end
52
-
53
- context "when returning a response that can't be parsed as JSON" do
54
- let(:body) { "<html><body><h1>something that isn't json</h1></body></html>" }
55
- let(:error_class) { Passfort::Errors::UnparseableResponseError }
56
-
57
- it { is_expected.to raise_error(error_class) }
58
- end
59
-
60
- context "when returning a successful result" do
61
- let(:result) { subject.call }
62
-
63
- before do
64
- stub_request(method, api_path).
65
- to_return(status: status, body: load_fixture("check.json"))
66
- end
67
-
68
- it "includes the id response" do
69
- expect(result).to include("id" => "6c1d594a-496e-11e7-911e-acbc32b67d7b")
70
- end
71
- end
72
-
73
- context "when the request times out" do
74
- before { stub_request(method, api_path).to_raise(Excon::Errors::Timeout) }
75
-
76
- let(:error_class) { Passfort::Errors::TimeoutError }
77
-
78
- it { is_expected.to raise_error(error_class) }
79
- end
80
-
81
- context "when the request returns a bad gateway error" do
82
- before { stub_request(method, api_path).to_raise(Excon::Errors::BadGateway) }
83
-
84
- let(:error_class) { Passfort::Errors::BadGatewayError }
85
-
86
- it { is_expected.to raise_error(error_class) }
87
- end
88
- end
89
-
90
- shared_examples_for "an API call that sends notifications" do
91
- let(:api_path) { Passfort::Http::DOMAIN + Passfort::Http::ROOT_PATH + path }
92
- let(:notifications) { [] }
93
- let(:time) { Time.local(1990) }
94
- let(:payload) { { path: path, response: be_truthy } }
95
- let(:expected_notification) do
96
- have_attributes(
97
- name: "passfort.#{method}",
98
- transaction_id: match(/\A.{20}\Z/),
99
- time: time,
100
- end: time,
101
- payload: payload,
102
- )
103
- end
104
- let(:result) { subject.call }
105
-
106
- before do
107
- ActiveSupport::Notifications.subscribe do |*args|
108
- notifications << ActiveSupport::Notifications::Event.new(*args)
109
- end
110
- stub_request(method, api_path).to_return(body: {}.to_json)
111
- payload[:body] = be_truthy if method == :post
112
- end
113
-
114
- it "records a notification" do
115
- Timecop.freeze(time) do
116
- result
117
- end
118
- expect(notifications).to match([expected_notification])
119
- end
120
- end
121
-
122
- describe "#initialize" do
123
- describe "with an API key" do
124
- it "sets the .api_key" do
125
- expect(http.api_key).to eq("api_key")
126
- end
127
-
128
- it "sets a default endpoint" do
129
- expect(described_class::DOMAIN).to include(http.connection.data[:hostname])
130
- end
131
- end
132
-
133
- it "accepts an alternate endpoint" do
134
- example_endpoint = "https://example.net"
135
- client = described_class.new("api_key", "domain": example_endpoint)
136
- expect(example_endpoint).to include(client.connection.data[:hostname])
137
- end
138
-
139
- it "supports setting open_timeout" do
140
- http = described_class.new("api_key", "open_timeout": 1)
141
- expect(http.connection.data[:open_timeout]).to eq(1)
142
- end
143
-
144
- it "supports setting read_timeout" do
145
- http = described_class.new("api_key", "read_timeout": 2)
146
- expect(http.connection.data[:read_timeout]).to eq(2)
147
- end
148
- end
149
-
150
- describe "#get" do
151
- subject { -> { http.get(path) } }
152
-
153
- let(:method) { :get }
154
-
155
- it_behaves_like "an API call that handles all errors"
156
- it_behaves_like "an API call that sends notifications"
157
- end
158
-
159
- describe "#post" do
160
- subject { -> { http.post(path, body: {}) } }
161
-
162
- let(:method) { :post }
163
-
164
- it_behaves_like "an API call that handles all errors"
165
- it_behaves_like "an API call that sends notifications"
166
- end
167
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "timecop"
5
+
6
+ RSpec.describe Passfort::Http do
7
+ let(:http) { described_class.new("api_key") }
8
+ let(:path) { "a/path" }
9
+
10
+ shared_examples "an API call that handles all errors" do
11
+ let(:api_path) { Passfort::Http::DOMAIN + Passfort::Http::ROOT_PATH + path }
12
+ let(:status) { 200 }
13
+ let(:error_code) { 0 }
14
+ let(:body) { { errors: { code: error_code } }.to_json }
15
+
16
+ before { stub_request(method, api_path).to_return(status: status, body: body) }
17
+
18
+ context "when returning a request error" do
19
+ let(:status) { 404 }
20
+ let(:error_class) { Passfort::Errors::RequestError }
21
+
22
+ it { is_expected.to raise_error(error_class) }
23
+ end
24
+
25
+ context "when returning an invalid API Key error" do
26
+ let(:error_code) { 204 }
27
+ let(:error_class) { Passfort::Errors::InvalidAPIKeyError }
28
+
29
+ it { is_expected.to raise_error(error_class) }
30
+ end
31
+
32
+ context "when returning an invalid input data error" do
33
+ let(:error_code) { 201 }
34
+ let(:error_class) { Passfort::Errors::InvalidInputDataError }
35
+
36
+ it { is_expected.to raise_error(error_class) }
37
+ end
38
+
39
+ context "when returning a chargeable limit reached error" do
40
+ let(:error_code) { 104 }
41
+ let(:error_class) { Passfort::Errors::ChargeableLimitReachedError }
42
+
43
+ it { is_expected.to raise_error(error_class) }
44
+ end
45
+
46
+ context "when returning an unknown API error" do
47
+ let(:error_code) { 203 }
48
+ let(:error_class) { Passfort::Errors::UnknownApiError }
49
+
50
+ it { is_expected.to raise_error(error_class) }
51
+ end
52
+
53
+ context "when returning a response that can't be parsed as JSON" do
54
+ let(:body) { "<html><body><h1>something that isn't json</h1></body></html>" }
55
+ let(:error_class) { Passfort::Errors::UnparseableResponseError }
56
+
57
+ it { is_expected.to raise_error(error_class) }
58
+ end
59
+
60
+ context "when returning a successful result" do
61
+ let(:result) { subject.call }
62
+
63
+ before do
64
+ stub_request(method, api_path).
65
+ to_return(status: status, body: load_fixture("check.json"))
66
+ end
67
+
68
+ it "includes the id response" do
69
+ expect(result).to include("id" => "6c1d594a-496e-11e7-911e-acbc32b67d7b")
70
+ end
71
+ end
72
+
73
+ context "when the request times out" do
74
+ before { stub_request(method, api_path).to_raise(Excon::Errors::Timeout) }
75
+
76
+ let(:error_class) { Passfort::Errors::TimeoutError }
77
+
78
+ it { is_expected.to raise_error(error_class) }
79
+ end
80
+
81
+ context "when the request returns a bad gateway error" do
82
+ before { stub_request(method, api_path).to_raise(Excon::Errors::BadGateway) }
83
+
84
+ let(:error_class) { Passfort::Errors::BadGatewayError }
85
+
86
+ it { is_expected.to raise_error(error_class) }
87
+ end
88
+ end
89
+
90
+ shared_examples_for "an API call that sends notifications" do
91
+ let(:api_path) { Passfort::Http::DOMAIN + Passfort::Http::ROOT_PATH + path }
92
+ let(:notifications) { [] }
93
+ let(:time) { Time.local(1990) }
94
+ let(:payload) { { path: path, response: be_truthy } }
95
+ let(:expected_notification) do
96
+ have_attributes(
97
+ name: "passfort.#{method}",
98
+ transaction_id: match(/\A.{20}\Z/),
99
+ time: time,
100
+ end: time,
101
+ payload: payload,
102
+ )
103
+ end
104
+ let(:result) { subject.call }
105
+
106
+ before do
107
+ ActiveSupport::Notifications.subscribe do |*args|
108
+ notifications << ActiveSupport::Notifications::Event.new(*args)
109
+ end
110
+ stub_request(method, api_path).to_return(body: {}.to_json)
111
+ payload[:body] = be_truthy if method == :post
112
+ end
113
+
114
+ it "records a notification" do
115
+ Timecop.freeze(time) do
116
+ result
117
+ end
118
+ expect(notifications).to match([expected_notification])
119
+ end
120
+ end
121
+
122
+ describe "#initialize" do
123
+ describe "with an API key" do
124
+ it "sets the .api_key" do
125
+ expect(http.api_key).to eq("api_key")
126
+ end
127
+
128
+ it "sets a default endpoint" do
129
+ expect(described_class::DOMAIN).to include(http.connection.data[:hostname])
130
+ end
131
+ end
132
+
133
+ it "accepts an alternate endpoint" do
134
+ example_endpoint = "https://example.net"
135
+ client = described_class.new("api_key", "domain": example_endpoint)
136
+ expect(example_endpoint).to include(client.connection.data[:hostname])
137
+ end
138
+
139
+ it "supports setting open_timeout" do
140
+ http = described_class.new("api_key", "open_timeout": 1)
141
+ expect(http.connection.data[:open_timeout]).to eq(1)
142
+ end
143
+
144
+ it "supports setting read_timeout" do
145
+ http = described_class.new("api_key", "read_timeout": 2)
146
+ expect(http.connection.data[:read_timeout]).to eq(2)
147
+ end
148
+ end
149
+
150
+ describe "#get" do
151
+ subject { -> { http.get(path) } }
152
+
153
+ let(:method) { :get }
154
+
155
+ it_behaves_like "an API call that handles all errors"
156
+ it_behaves_like "an API call that sends notifications"
157
+ end
158
+
159
+ describe "#post" do
160
+ subject { -> { http.post(path, body: {}) } }
161
+
162
+ let(:method) { :post }
163
+
164
+ it_behaves_like "an API call that handles all errors"
165
+ it_behaves_like "an API call that sends notifications"
166
+ end
167
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- require "passfort"
4
- require "pry"
5
- require "webmock/rspec"
6
-
7
- def load_fixture(path)
8
- File.read(File.join(__dir__, "fixtures", path))
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "passfort"
4
+ require "pry"
5
+ require "webmock/rspec"
6
+
7
+ def load_fixture(path)
8
+ File.read(File.join(__dir__, "fixtures", path))
9
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passfort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -199,8 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  requirements: []
202
- rubyforge_project:
203
- rubygems_version: 2.7.3
202
+ rubygems_version: 3.0.6
204
203
  signing_key:
205
204
  specification_version: 4
206
205
  summary: Client for the PassFort API