creditsafe 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e29e350fc4b5fe1cd81b1855d7cfc43fa35afc4
4
- data.tar.gz: 36bb660af1c51a7e2dde56443cfbba02e2c22b1f
3
+ metadata.gz: 8da2890acd61ed7db41e62b44682b13cf9963203
4
+ data.tar.gz: 03bdc4029107f5c89556dd0f44b1892ca1d64dc1
5
5
  SHA512:
6
- metadata.gz: 81d10c8255127c3f1bad547ea4beaed8573de038b01188846c4e0ed3a7771ce54e446d7e931681d33dc9df2a6be59f9e5825f2602f1ed98423c2a51ae47b2feb
7
- data.tar.gz: 7c4c938c09a66213c0267172d1e16c9b169dc8dfff24f3acb342f9ae2998c89d3cc1613b7694714d6848b1bd64fee13985a5d8fe7fad3a5458844c720ec570cd
6
+ metadata.gz: 90ae7bd7b7dddfc87b7b7868dcae3696e324b0e5d15ac1a5f924f915a8c1b74c60a60ca0a5e1d4a095fbe63a52dd9cfaf1834a84dcf9d6a991bbb3af3894c3c0
7
+ data.tar.gz: bb9c7e7e14efd24014efc9270a31a788511f1e1fa9f4b4cf9fe26ab89988f74c9da9c0e4dcfb641e7cb0530a0a91c12f65e360f989e61460006f7e389bd09bcb
@@ -1,3 +1,9 @@
1
+ ## v0.2.0, 16 March 2016
2
+
3
+ - Subclass `ApiError` to distinguish between different Creditsafe error types
4
+ (patch by [greysteil](https://github.com/greysteil))
5
+
6
+
1
7
  ## v0.1.1, 15 February 2016
2
8
 
3
9
  - Allow `city` parameter in `find_company` for German company lookups
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- creditsafe (0.1.1)
4
+ creditsafe (0.2.0)
5
5
  excon (~> 0.45)
6
6
  savon (~> 2.8)
7
7
 
@@ -123,7 +123,7 @@ module Creditsafe
123
123
  api_error_message = api_message.message
124
124
  api_error_message += " (#{message.text})" unless message.text.blank?
125
125
 
126
- raise ApiError, api_error_message if api_message.error?
126
+ raise api_message.error_class, api_error_message if api_message.error?
127
127
  end
128
128
  end
129
129
 
@@ -141,12 +141,12 @@ module Creditsafe
141
141
  def handle_error(error)
142
142
  raise error
143
143
  rescue Savon::SOAPFault => error
144
- raise ApiError, error.message
144
+ raise UnknownApiError, error.message
145
145
  rescue Savon::HTTPError => error
146
146
  if error.to_hash[:code] == 401
147
- raise ApiError, 'Unauthorized: invalid credentials'
147
+ raise AccountError, 'Unauthorized: invalid credentials'
148
148
  end
149
- raise ApiError, error.message
149
+ raise UnknownApiError, error.message
150
150
  rescue Excon::Errors::Error => err
151
151
  raise HttpError, "Error making HTTP request: #{err.message}"
152
152
  end
@@ -1,6 +1,12 @@
1
1
  module Creditsafe
2
2
  class Error < StandardError; end
3
3
 
4
- class ApiError < Error; end
5
4
  class HttpError < Error; end
5
+ class ApiError < Error; end
6
+
7
+ class DataError < ApiError; end
8
+ class AccountError < ApiError; end
9
+ class RequestError < ApiError; end
10
+ class ProcessingError < ApiError; end
11
+ class UnknownApiError < ApiError; end
6
12
  end
@@ -1,3 +1,5 @@
1
+ require 'creditsafe/errors'
2
+
1
3
  module Creditsafe
2
4
  module Messages
3
5
  class Message
@@ -12,6 +14,18 @@ module Creditsafe
12
14
  end
13
15
 
14
16
  alias error? error
17
+
18
+ def error_class
19
+ return unless error?
20
+
21
+ case code[1].to_i
22
+ when 1 then Creditsafe::DataError
23
+ when 2 then Creditsafe::AccountError
24
+ when 3 then Creditsafe::RequestError
25
+ when 4 then Creditsafe::ProcessingError
26
+ else Creditsafe::UnknownApiError
27
+ end
28
+ end
15
29
  end
16
30
 
17
31
  # rubocop:disable Metrics/LineLength
@@ -1,3 +1,3 @@
1
1
  module Creditsafe
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -17,14 +17,14 @@ RSpec.describe(Creditsafe::Client) do
17
17
  )
18
18
  end
19
19
 
20
- it 'raises an ApiError' do
21
- expect { method_call }.to raise_error(Creditsafe::ApiError)
20
+ it 'raises an AccountError' do
21
+ expect { method_call }.to raise_error(Creditsafe::AccountError)
22
22
  end
23
23
 
24
24
  it 'gives a useful error message' do
25
25
  begin
26
26
  method_call
27
- rescue Creditsafe::ApiError => err
27
+ rescue Creditsafe::AccountError => err
28
28
  expect(err.message).to include 'invalid credentials'
29
29
  end
30
30
  end
@@ -36,8 +36,8 @@ RSpec.describe(Creditsafe::Client) do
36
36
  to_return(body: load_fixture('error-fault.xml'))
37
37
  end
38
38
 
39
- it 'raises an ApiError' do
40
- expect { method_call }.to raise_error(Creditsafe::ApiError)
39
+ it 'raises an UnknownApiError' do
40
+ expect { method_call }.to raise_error(Creditsafe::UnknownApiError)
41
41
  end
42
42
  end
43
43
 
@@ -170,7 +170,7 @@ RSpec.describe(Creditsafe::Client) do
170
170
  it 'gives a useful error, with the specific error in the response' do
171
171
  begin
172
172
  method_call
173
- rescue Creditsafe::ApiError => err
173
+ rescue Creditsafe::RequestError => err
174
174
  expect(err.message).to eq 'Invalid operation parameters ' \
175
175
  '(Invalid countries list specified.)'
176
176
  end
@@ -187,7 +187,7 @@ RSpec.describe(Creditsafe::Client) do
187
187
  it 'gives a useful error, with the specific error in the response' do
188
188
  begin
189
189
  method_call
190
- rescue Creditsafe::ApiError => err
190
+ rescue Creditsafe::RequestError => err
191
191
  expect(err.message).to eq 'Invalid operation parameters'
192
192
  end
193
193
  end
@@ -221,14 +221,14 @@ RSpec.describe(Creditsafe::Client) do
221
221
  to_return(body: load_fixture('company-report-not-found.xml'))
222
222
  end
223
223
 
224
- it 'returns nil' do
225
- expect { company_report }.to raise_error(Creditsafe::ApiError)
224
+ it 'raises an error' do
225
+ expect { company_report }.to raise_error(Creditsafe::DataError)
226
226
  end
227
227
 
228
228
  it 'gives a useful error message' do
229
229
  begin
230
230
  company_report
231
- rescue Creditsafe::ApiError => err
231
+ rescue Creditsafe::DataError => err
232
232
  expect(err.message).to include 'Report unavailable'
233
233
  end
234
234
  end
@@ -2,25 +2,28 @@ require 'spec_helper'
2
2
  require 'creditsafe/messages'
3
3
 
4
4
  RSpec.describe(Creditsafe::Messages) do
5
- describe "#for_code" do
5
+ describe ".for_code" do
6
6
  subject(:message) { described_class.for_code(code) }
7
7
 
8
8
  context "for a valid code" do
9
9
  let(:code) { "020101" }
10
10
  its(:code) { is_expected.to eq(code) }
11
11
  its(:message) { is_expected.to eq('Invalid credentials') }
12
+ its(:error_class) { is_expected.to eq(Creditsafe::AccountError) }
12
13
  end
13
14
 
14
15
  context "for a code without leading zero" do
15
16
  let(:code) { "20101" }
16
17
  its(:code) { is_expected.to eq("0#{code}") }
17
18
  its(:message) { is_expected.to eq('Invalid credentials') }
19
+ its(:error_class) { is_expected.to eq(Creditsafe::AccountError) }
18
20
  end
19
21
 
20
22
  context "for an unknown code" do
21
23
  let(:code) { "999999" }
22
24
  its(:code) { is_expected.to eq(code) }
23
25
  its(:message) { is_expected.to eq('Unknown error') }
26
+ its(:error_class) { is_expected.to eq(Creditsafe::UnknownApiError) }
24
27
  end
25
28
 
26
29
  context "for an empty code" do
@@ -30,4 +33,36 @@ RSpec.describe(Creditsafe::Messages) do
30
33
  end
31
34
  end
32
35
  end
36
+
37
+ describe(Creditsafe::Messages::Message) do
38
+ subject(:message) do
39
+ described_class.new(code: code, message: text, error: error)
40
+ end
41
+ let(:text) { "Error message" }
42
+ let(:code) { "020101" }
43
+ let(:error) { true }
44
+
45
+ describe "#error_class" do
46
+ subject { message.error_class }
47
+
48
+ context "when there is no error" do
49
+ let(:error) { false }
50
+ it { is_expected.to be_nil }
51
+ end
52
+
53
+ context "when there is an error" do
54
+ let(:error) { true }
55
+
56
+ context "for a processing error code" do
57
+ let(:code) { "040102" }
58
+ it { is_expected.to eq(Creditsafe::ProcessingError) }
59
+ end
60
+
61
+ context "for an unknown error code" do
62
+ let(:code) { "060102" }
63
+ it { is_expected.to eq(Creditsafe::UnknownApiError) }
64
+ end
65
+ end
66
+ end
67
+ end
33
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creditsafe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Hamilton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon