creditsafe 0.5.1 → 0.5.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +17 -17
  3. data/.gitignore +2 -2
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +11 -11
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +41 -37
  8. data/Gemfile +5 -5
  9. data/Gemfile.lock +127 -125
  10. data/LICENSE.txt +22 -22
  11. data/README.md +138 -138
  12. data/creditsafe.gemspec +35 -35
  13. data/data/creditsafe-live.xml +342 -342
  14. data/data/creditsafe-test.xml +342 -342
  15. data/lib/creditsafe.rb +4 -4
  16. data/lib/creditsafe/client.rb +158 -156
  17. data/lib/creditsafe/errors.rb +16 -14
  18. data/lib/creditsafe/match_type.rb +115 -115
  19. data/lib/creditsafe/messages.rb +97 -97
  20. data/lib/creditsafe/namespace.rb +20 -20
  21. data/lib/creditsafe/request/company_report.rb +42 -42
  22. data/lib/creditsafe/request/find_company.rb +98 -98
  23. data/lib/creditsafe/version.rb +5 -5
  24. data/spec/creditsafe/client_spec.rb +369 -372
  25. data/spec/creditsafe/messages_spec.rb +76 -76
  26. data/spec/fixtures/company-report-not-found.xml +13 -13
  27. data/spec/fixtures/company-report-request.xml +1 -1
  28. data/spec/fixtures/company-report-successful.xml +582 -582
  29. data/spec/fixtures/error-fault.xml +8 -8
  30. data/spec/fixtures/error-invalid-credentials.html +31 -31
  31. data/spec/fixtures/find-companies-error-no-text.xml +11 -11
  32. data/spec/fixtures/find-companies-error.xml +11 -11
  33. data/spec/fixtures/find-companies-none-found.xml +13 -13
  34. data/spec/fixtures/find-companies-request.xml +1 -1
  35. data/spec/fixtures/find-companies-successful-multi.xml +493 -493
  36. data/spec/fixtures/find-companies-successful.xml +29 -29
  37. data/spec/spec_helper.rb +14 -14
  38. metadata +4 -4
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Creditsafe
4
- VERSION = "0.5.1"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ VERSION = "0.5.2"
5
+ end
@@ -1,372 +1,369 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "creditsafe/client"
5
- require "timecop"
6
-
7
- URL = "https://webservices.creditsafe.com/GlobalData/1.3/"\
8
- "MainServiceBasic.svc"
9
-
10
- RSpec.describe(Creditsafe::Client) do
11
- notifications = []
12
- let(:username) { "AzureDiamond" }
13
- let(:password) { "hunter2" }
14
-
15
- # rubocop:disable RSpec/BeforeAfterAll
16
- before(:all) do
17
- ActiveSupport::Notifications.subscribe do |*args|
18
- notifications << ActiveSupport::Notifications::Event.new(*args)
19
- end
20
- end
21
- # rubocop:enable RSpec/BeforeAfterAll
22
-
23
- before { notifications = [] }
24
-
25
- shared_examples_for "sends notifications" do
26
- let(:time) { Time.local(1990) }
27
-
28
- it "records a SOAP event" do
29
- Timecop.freeze(time) { method_call }
30
-
31
- expect(notifications).to match(
32
- [
33
- have_attributes(
34
- name: "creditsafe.#{soap_verb}",
35
- transaction_id: match(/\A.{20}\Z/),
36
- time: time,
37
- end: time,
38
- payload: {
39
- request: be_truthy,
40
- response: be_truthy,
41
- },
42
- ),
43
- ],
44
- )
45
- end
46
- end
47
-
48
- shared_examples_for "handles api errors" do
49
- context "when an error occurs due to invalid credentials" do
50
- before do
51
- stub_request(:post, URL).to_return(
52
- body: load_fixture("error-invalid-credentials.html"),
53
- status: 401,
54
- )
55
- end
56
-
57
- it "raises an AccountError" do
58
- expect { method_call }.to raise_error(
59
- Creditsafe::AccountError, /invalid credentials/
60
- ) do |error|
61
- expect(notifications).to match(
62
- [
63
- have_attributes(
64
- name: "creditsafe.#{soap_verb}",
65
- payload: {
66
- request: be_truthy,
67
- error: error,
68
- },
69
- ),
70
- ],
71
- )
72
- end
73
- end
74
- end
75
-
76
- context "when an error occurs due to a fault" do
77
- before do
78
- stub_request(:post, URL).
79
- to_return(body: load_fixture("error-fault.xml"))
80
- end
81
-
82
- it "raises an UnknownApiError" do
83
- expect { method_call }.to raise_error(Creditsafe::UnknownApiError) do |error|
84
- expect(notifications).to match(
85
- [
86
- have_attributes(
87
- name: "creditsafe.#{soap_verb}",
88
- payload: {
89
- request: be_truthy,
90
- error: error,
91
- },
92
- ),
93
- ],
94
- )
95
- end
96
- end
97
- end
98
-
99
- context "when a HTTP error occurs" do
100
- before do
101
- stub_request(:post, URL).to_timeout
102
- end
103
-
104
- it "raises an HttpError" do
105
- expect { method_call }.
106
- to raise_error(Creditsafe::HttpError, /Excon::Error(?:s)?::Timeout/)
107
- end
108
- end
109
- end
110
-
111
- describe "#new" do
112
- subject do
113
- -> { described_class.new(username: username, password: password) }
114
- end
115
-
116
- it { is_expected.to_not raise_error }
117
-
118
- context "without a username" do
119
- let(:username) { nil }
120
-
121
- it { is_expected.to raise_error(ArgumentError) }
122
- end
123
- end
124
-
125
- describe "#inspect" do
126
- subject { client.inspect }
127
-
128
- let(:client) { described_class.new(username: username, password: password) }
129
-
130
- it { is_expected.to_not include(password) }
131
- end
132
-
133
- describe "#find_company" do
134
- subject { -> { method_call } }
135
-
136
- let(:soap_verb) { "find_companies" }
137
- let(:client) { described_class.new(username: username, password: password) }
138
- let(:country_code) { "GB" }
139
- let(:registration_number) { "RN123" }
140
- let(:city) { nil }
141
- let(:postal_code) { nil }
142
- let(:search_criteria) do
143
- {
144
- country_code: country_code,
145
- registration_number: registration_number,
146
- city: city,
147
- postal_code: postal_code,
148
- }.reject { |_, v| v.nil? }
149
- end
150
-
151
- let(:find_company) { client.find_company(search_criteria) }
152
- let(:method_call) { find_company }
153
-
154
- before do
155
- stub_request(:post, URL).to_return(
156
- body: load_fixture("find-companies-successful.xml"),
157
- status: 200,
158
- )
159
- end
160
-
161
- it { is_expected.to_not raise_error }
162
-
163
- context "without a country_code" do
164
- let(:country_code) { nil }
165
-
166
- it { is_expected.to raise_error(ArgumentError) }
167
- end
168
-
169
- context "without a registration_number" do
170
- let(:registration_number) { nil }
171
-
172
- it { is_expected.to raise_error(ArgumentError) }
173
- end
174
-
175
- context "with a city" do
176
- let(:city) { "Berlin" }
177
-
178
- it { is_expected.to raise_error(ArgumentError) }
179
-
180
- context "in Germany" do
181
- let(:country_code) { "DE" }
182
-
183
- it { is_expected.to_not raise_error }
184
- end
185
- end
186
-
187
- context "with a postal_code" do
188
- let(:postal_code) { "41199" }
189
-
190
- it { is_expected.to raise_error(ArgumentError) }
191
-
192
- context "in Germany" do
193
- let(:country_code) { "DE" }
194
-
195
- it { is_expected.to_not raise_error }
196
- end
197
- end
198
-
199
- context "with a company name" do
200
- let(:search_criteria) { { country_code: "FR", company_name: "Mimes Inc" } }
201
-
202
- it { is_expected.to_not raise_error }
203
-
204
- it "selects a valid match type for the country code" do
205
- find_company
206
-
207
- request = a_request(:post, URL).with do |req|
208
- body = Nokogiri::XML(req.body)
209
- expect(body.xpath("//dat:Name").first.attributes["MatchType"].value).
210
- to eq("MatchBeginning")
211
- end
212
-
213
- expect(request).to have_been_made
214
- end
215
- end
216
-
217
- it "requests the company deatils" do
218
- find_company
219
- expect(a_request(:post, URL).with do |req|
220
- expect(CompareXML.equivalent?(
221
- Nokogiri::XML(req.body),
222
- load_xml_fixture("find-companies-request.xml"),
223
- verbose: true,
224
- )).to eq([])
225
- end).to have_been_made
226
- end
227
-
228
- it "returns the company details" do
229
- expect(find_company).
230
- to eq(:name => "GOCARDLESS LTD",
231
- :type => "Ltd",
232
- :status => "Active",
233
- :registration_number => "07495895",
234
- :address => {
235
- simple_value: "338-346, GOSWELL, LONDON",
236
- postal_code: "EC1V7LQ",
237
- },
238
- :available_report_types => { available_report_type: "Full" },
239
- :available_languages => { available_language: "EN" },
240
- :@date_of_latest_accounts => "2014-01-31T00:00:00Z",
241
- :@online_reports => "true",
242
- :@monitoring => "false",
243
- :@country => "GB",
244
- :@id => "GB003/0/07495895")
245
- end
246
-
247
- include_examples "sends notifications"
248
- include_examples "handles api errors"
249
-
250
- context "when no companies are found" do
251
- before do
252
- stub_request(:post, URL).to_return(
253
- body: load_fixture("find-companies-none-found.xml"),
254
- status: 200,
255
- )
256
- end
257
-
258
- it "returns nil" do
259
- expect(find_company).to be_nil
260
- end
261
-
262
- it "records a nil payload" do
263
- find_company
264
- expect(notifications).to match([have_attributes(
265
- payload: {
266
- request: be_truthy,
267
- response: {
268
- find_companies_response: include(
269
- find_companies_result: include(
270
- messages: {
271
- message: include(
272
- "There are no results matching specified criteria.",
273
- ),
274
- },
275
- companies: be_nil,
276
- ),
277
- ),
278
- },
279
- },
280
- )])
281
- end
282
- end
283
-
284
- context "when an error occurs with further details" do
285
- before do
286
- stub_request(:post, URL).to_return(
287
- body: load_fixture("find-companies-error.xml"),
288
- status: 200,
289
- )
290
- end
291
-
292
- it "gives a useful error, with the specific error in the response" do
293
- expect { method_call }.to raise_error(
294
- Creditsafe::RequestError,
295
- "Invalid operation parameters (Invalid countries list specified.)",
296
- )
297
- end
298
-
299
- context "with further details provided in the response" do
300
- before do
301
- stub_request(:post, URL).to_return(
302
- body: load_fixture("find-companies-error-no-text.xml"),
303
- status: 200,
304
- )
305
- end
306
-
307
- it "gives a useful error, with the specific error in the response" do
308
- expect { method_call }.to raise_error(
309
- Creditsafe::RequestError,
310
- "Invalid operation parameters",
311
- )
312
- end
313
- end
314
- end
315
- end
316
-
317
- describe "#company_report" do
318
- before do
319
- stub_request(:post, URL).to_return(
320
- body: load_fixture("company-report-successful.xml"),
321
- status: 200,
322
- )
323
- end
324
-
325
- let(:soap_verb) { "retrieve_company_online_report" }
326
- let(:client) { described_class.new(username: username, password: password) }
327
- let(:custom_data) { { foo: "bar", bar: "baz" } }
328
- let(:company_report) do
329
- client.company_report("GB003/0/07495895", custom_data: custom_data)
330
- end
331
- let(:method_call) { company_report }
332
-
333
- it "requests the company details" do
334
- company_report
335
- request = a_request(:post, URL).with do |req|
336
- expect(
337
- CompareXML.equivalent?(
338
- Nokogiri::XML(req.body),
339
- load_xml_fixture("company-report-request.xml"),
340
- verbose: true,
341
- ),
342
- ).to eq([])
343
- end
344
-
345
- expect(request).to have_been_made
346
- end
347
-
348
- it "returns the company details" do
349
- expect(company_report).to include(:company_summary)
350
- end
351
-
352
- include_examples "sends notifications"
353
- include_examples "handles api errors"
354
-
355
- context "when a report is unavailable" do
356
- before do
357
- stub_request(:post, URL).
358
- to_return(body: load_fixture("company-report-not-found.xml"))
359
- end
360
-
361
- it "raises an error" do
362
- expect { company_report }.to raise_error(Creditsafe::DataError)
363
- end
364
-
365
- it "gives a useful error message" do
366
- expect { company_report }.to raise_error(
367
- Creditsafe::DataError, /Report unavailable/
368
- )
369
- end
370
- end
371
- end
372
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "creditsafe/client"
5
+ require "timecop"
6
+
7
+ URL = "https://webservices.creditsafe.com/GlobalData/1.3/"\
8
+ "MainServiceBasic.svc"
9
+
10
+ RSpec.describe(Creditsafe::Client) do
11
+ notifications = []
12
+ let(:username) { "AzureDiamond" }
13
+ let(:password) { "hunter2" }
14
+
15
+ # rubocop:disable RSpec/BeforeAfterAll
16
+ before(:all) do
17
+ ActiveSupport::Notifications.subscribe do |*args|
18
+ notifications << ActiveSupport::Notifications::Event.new(*args)
19
+ end
20
+ end
21
+ # rubocop:enable RSpec/BeforeAfterAll
22
+
23
+ before { notifications = [] }
24
+
25
+ shared_examples_for "sends notifications" do
26
+ let(:time) { Time.local(1990) }
27
+
28
+ it "records a SOAP event" do
29
+ Timecop.freeze(time) { method_call }
30
+
31
+ expect(notifications).to match(
32
+ [
33
+ have_attributes(
34
+ name: "creditsafe.#{soap_verb}",
35
+ transaction_id: match(/\A.{20}\Z/),
36
+ time: time,
37
+ end: time,
38
+ payload: {
39
+ request: be_truthy,
40
+ response: be_truthy,
41
+ },
42
+ ),
43
+ ],
44
+ )
45
+ end
46
+ end
47
+
48
+ shared_examples_for "handles api errors" do
49
+ context "when an error occurs due to invalid credentials" do
50
+ before do
51
+ stub_request(:post, URL).to_return(
52
+ body: load_fixture("error-invalid-credentials.html"),
53
+ status: 401,
54
+ )
55
+ end
56
+
57
+ it "raises an AccountError" do
58
+ expect { method_call }.to raise_error(
59
+ Creditsafe::AccountError, /invalid credentials/
60
+ ) do |error|
61
+ expect(notifications).to match(
62
+ [
63
+ have_attributes(
64
+ name: "creditsafe.#{soap_verb}",
65
+ payload: {
66
+ request: be_truthy,
67
+ error: error,
68
+ },
69
+ ),
70
+ ],
71
+ )
72
+ end
73
+ end
74
+ end
75
+
76
+ context "when an error occurs due to a fault" do
77
+ before do
78
+ stub_request(:post, URL).
79
+ to_return(body: load_fixture("error-fault.xml"))
80
+ end
81
+
82
+ it "raises an UnknownApiError" do
83
+ expect { method_call }.to raise_error(Creditsafe::UnknownApiError) do |error|
84
+ expect(notifications).to match(
85
+ [
86
+ have_attributes(
87
+ name: "creditsafe.#{soap_verb}",
88
+ payload: {
89
+ request: be_truthy,
90
+ error: error,
91
+ },
92
+ ),
93
+ ],
94
+ )
95
+ end
96
+ end
97
+ end
98
+
99
+ context "when a timeout occurs" do
100
+ before { stub_request(:post, URL).to_timeout }
101
+
102
+ it "raises a TimeoutError" do
103
+ expect { method_call }.to raise_error(Creditsafe::TimeoutError)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "#new" do
109
+ subject do
110
+ -> { described_class.new(username: username, password: password) }
111
+ end
112
+
113
+ it { is_expected.to_not raise_error }
114
+
115
+ context "without a username" do
116
+ let(:username) { nil }
117
+
118
+ it { is_expected.to raise_error(ArgumentError) }
119
+ end
120
+ end
121
+
122
+ describe "#inspect" do
123
+ subject { client.inspect }
124
+
125
+ let(:client) { described_class.new(username: username, password: password) }
126
+
127
+ it { is_expected.to_not include(password) }
128
+ end
129
+
130
+ describe "#find_company" do
131
+ subject { -> { method_call } }
132
+
133
+ let(:soap_verb) { "find_companies" }
134
+ let(:client) { described_class.new(username: username, password: password) }
135
+ let(:country_code) { "GB" }
136
+ let(:registration_number) { "RN123" }
137
+ let(:city) { nil }
138
+ let(:postal_code) { nil }
139
+ let(:search_criteria) do
140
+ {
141
+ country_code: country_code,
142
+ registration_number: registration_number,
143
+ city: city,
144
+ postal_code: postal_code,
145
+ }.reject { |_, v| v.nil? }
146
+ end
147
+
148
+ let(:find_company) { client.find_company(search_criteria) }
149
+ let(:method_call) { find_company }
150
+
151
+ before do
152
+ stub_request(:post, URL).to_return(
153
+ body: load_fixture("find-companies-successful.xml"),
154
+ status: 200,
155
+ )
156
+ end
157
+
158
+ it { is_expected.to_not raise_error }
159
+
160
+ context "without a country_code" do
161
+ let(:country_code) { nil }
162
+
163
+ it { is_expected.to raise_error(ArgumentError) }
164
+ end
165
+
166
+ context "without a registration_number" do
167
+ let(:registration_number) { nil }
168
+
169
+ it { is_expected.to raise_error(ArgumentError) }
170
+ end
171
+
172
+ context "with a city" do
173
+ let(:city) { "Berlin" }
174
+
175
+ it { is_expected.to raise_error(ArgumentError) }
176
+
177
+ context "in Germany" do
178
+ let(:country_code) { "DE" }
179
+
180
+ it { is_expected.to_not raise_error }
181
+ end
182
+ end
183
+
184
+ context "with a postal_code" do
185
+ let(:postal_code) { "41199" }
186
+
187
+ it { is_expected.to raise_error(ArgumentError) }
188
+
189
+ context "in Germany" do
190
+ let(:country_code) { "DE" }
191
+
192
+ it { is_expected.to_not raise_error }
193
+ end
194
+ end
195
+
196
+ context "with a company name" do
197
+ let(:search_criteria) { { country_code: "FR", company_name: "Mimes Inc" } }
198
+
199
+ it { is_expected.to_not raise_error }
200
+
201
+ it "selects a valid match type for the country code" do
202
+ find_company
203
+
204
+ request = a_request(:post, URL).with do |req|
205
+ body = Nokogiri::XML(req.body)
206
+ expect(body.xpath("//dat:Name").first.attributes["MatchType"].value).
207
+ to eq("MatchBeginning")
208
+ end
209
+
210
+ expect(request).to have_been_made
211
+ end
212
+ end
213
+
214
+ it "requests the company deatils" do
215
+ find_company
216
+ expect(a_request(:post, URL).with do |req|
217
+ expect(CompareXML.equivalent?(
218
+ Nokogiri::XML(req.body),
219
+ load_xml_fixture("find-companies-request.xml"),
220
+ verbose: true,
221
+ )).to eq([])
222
+ end).to have_been_made
223
+ end
224
+
225
+ it "returns the company details" do
226
+ expect(find_company).
227
+ to eq(:name => "GOCARDLESS LTD",
228
+ :type => "Ltd",
229
+ :status => "Active",
230
+ :registration_number => "07495895",
231
+ :address => {
232
+ simple_value: "338-346, GOSWELL, LONDON",
233
+ postal_code: "EC1V7LQ",
234
+ },
235
+ :available_report_types => { available_report_type: "Full" },
236
+ :available_languages => { available_language: "EN" },
237
+ :@date_of_latest_accounts => "2014-01-31T00:00:00Z",
238
+ :@online_reports => "true",
239
+ :@monitoring => "false",
240
+ :@country => "GB",
241
+ :@id => "GB003/0/07495895")
242
+ end
243
+
244
+ include_examples "sends notifications"
245
+ include_examples "handles api errors"
246
+
247
+ context "when no companies are found" do
248
+ before do
249
+ stub_request(:post, URL).to_return(
250
+ body: load_fixture("find-companies-none-found.xml"),
251
+ status: 200,
252
+ )
253
+ end
254
+
255
+ it "returns nil" do
256
+ expect(find_company).to be_nil
257
+ end
258
+
259
+ it "records a nil payload" do
260
+ find_company
261
+ expect(notifications).to match([have_attributes(
262
+ payload: {
263
+ request: be_truthy,
264
+ response: {
265
+ find_companies_response: include(
266
+ find_companies_result: include(
267
+ messages: {
268
+ message: include(
269
+ "There are no results matching specified criteria.",
270
+ ),
271
+ },
272
+ companies: be_nil,
273
+ ),
274
+ ),
275
+ },
276
+ },
277
+ )])
278
+ end
279
+ end
280
+
281
+ context "when an error occurs with further details" do
282
+ before do
283
+ stub_request(:post, URL).to_return(
284
+ body: load_fixture("find-companies-error.xml"),
285
+ status: 200,
286
+ )
287
+ end
288
+
289
+ it "gives a useful error, with the specific error in the response" do
290
+ expect { method_call }.to raise_error(
291
+ Creditsafe::RequestError,
292
+ "Invalid operation parameters (Invalid countries list specified.)",
293
+ )
294
+ end
295
+
296
+ context "with further details provided in the response" do
297
+ before do
298
+ stub_request(:post, URL).to_return(
299
+ body: load_fixture("find-companies-error-no-text.xml"),
300
+ status: 200,
301
+ )
302
+ end
303
+
304
+ it "gives a useful error, with the specific error in the response" do
305
+ expect { method_call }.to raise_error(
306
+ Creditsafe::RequestError,
307
+ "Invalid operation parameters",
308
+ )
309
+ end
310
+ end
311
+ end
312
+ end
313
+
314
+ describe "#company_report" do
315
+ before do
316
+ stub_request(:post, URL).to_return(
317
+ body: load_fixture("company-report-successful.xml"),
318
+ status: 200,
319
+ )
320
+ end
321
+
322
+ let(:soap_verb) { "retrieve_company_online_report" }
323
+ let(:client) { described_class.new(username: username, password: password) }
324
+ let(:custom_data) { { foo: "bar", bar: "baz" } }
325
+ let(:company_report) do
326
+ client.company_report("GB003/0/07495895", custom_data: custom_data)
327
+ end
328
+ let(:method_call) { company_report }
329
+
330
+ it "requests the company details" do
331
+ company_report
332
+ request = a_request(:post, URL).with do |req|
333
+ expect(
334
+ CompareXML.equivalent?(
335
+ Nokogiri::XML(req.body),
336
+ load_xml_fixture("company-report-request.xml"),
337
+ verbose: true,
338
+ ),
339
+ ).to eq([])
340
+ end
341
+
342
+ expect(request).to have_been_made
343
+ end
344
+
345
+ it "returns the company details" do
346
+ expect(company_report).to include(:company_summary)
347
+ end
348
+
349
+ include_examples "sends notifications"
350
+ include_examples "handles api errors"
351
+
352
+ context "when a report is unavailable" do
353
+ before do
354
+ stub_request(:post, URL).
355
+ to_return(body: load_fixture("company-report-not-found.xml"))
356
+ end
357
+
358
+ it "raises an error" do
359
+ expect { company_report }.to raise_error(Creditsafe::DataError)
360
+ end
361
+
362
+ it "gives a useful error message" do
363
+ expect { company_report }.to raise_error(
364
+ Creditsafe::DataError, /Report unavailable/
365
+ )
366
+ end
367
+ end
368
+ end
369
+ end