creditsafe 0.6.0 → 0.6.1

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 (39) hide show
  1. checksums.yaml +5 -5
  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 +49 -45
  8. data/Gemfile +5 -5
  9. data/Gemfile.lock +129 -129
  10. data/LICENSE.txt +22 -22
  11. data/README.md +175 -175
  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 -158
  17. data/lib/creditsafe/constants.rb +49 -49
  18. data/lib/creditsafe/errors.rb +16 -16
  19. data/lib/creditsafe/match_type.rb +115 -115
  20. data/lib/creditsafe/messages.rb +97 -97
  21. data/lib/creditsafe/namespace.rb +20 -20
  22. data/lib/creditsafe/request/company_report.rb +42 -42
  23. data/lib/creditsafe/request/find_company.rb +120 -120
  24. data/lib/creditsafe/version.rb +5 -5
  25. data/spec/creditsafe/client_spec.rb +423 -423
  26. data/spec/creditsafe/messages_spec.rb +76 -76
  27. data/spec/fixtures/company-report-not-found.xml +13 -13
  28. data/spec/fixtures/company-report-request.xml +1 -1
  29. data/spec/fixtures/company-report-successful.xml +582 -582
  30. data/spec/fixtures/error-fault.xml +8 -8
  31. data/spec/fixtures/error-invalid-credentials.html +31 -31
  32. data/spec/fixtures/find-companies-error-no-text.xml +11 -11
  33. data/spec/fixtures/find-companies-error.xml +11 -11
  34. data/spec/fixtures/find-companies-none-found.xml +13 -13
  35. data/spec/fixtures/find-companies-request.xml +1 -1
  36. data/spec/fixtures/find-companies-successful-multi.xml +493 -493
  37. data/spec/fixtures/find-companies-successful.xml +29 -29
  38. data/spec/spec_helper.rb +14 -14
  39. metadata +3 -3
@@ -1,115 +1,115 @@
1
- # frozen_string_literal: true
2
-
3
- module Creditsafe
4
- module MatchType
5
- MATCH_BEGINNING = "MatchBeginning"
6
- MATCH_BLOCK = "MatchBlock"
7
- EXACT_VALUE = "ExactValue"
8
- MATCH_WORDS = "MatchWords"
9
- CLOSEST_KEYWORDS = "ClosestKeywords"
10
- MATCH_BLOCK_OR_WORDS = "MatchBlockOrWords"
11
- MATCH_ANY_PARTS = "MatchAnyParts"
12
-
13
- ALLOWED = {
14
- DE: [MATCH_BEGINNING, MATCH_BLOCK, EXACT_VALUE, MATCH_WORDS],
15
- FR: [MATCH_BEGINNING, CLOSEST_KEYWORDS, EXACT_VALUE],
16
- GB: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, EXACT_VALUE],
17
- IE: [MATCH_BEGINNING, MATCH_BLOCK, MATCH_WORDS],
18
- GL: [MATCH_BEGINNING],
19
- CH: [CLOSEST_KEYWORDS],
20
- LI: [CLOSEST_KEYWORDS],
21
- NL: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, MATCH_WORDS],
22
- CZ: [MATCH_BLOCK_OR_WORDS],
23
- IS: [MATCH_BEGINNING],
24
- LT: [MATCH_ANY_PARTS],
25
- MT: [MATCH_BEGINNING, MATCH_BLOCK],
26
- SK: [MATCH_BLOCK_OR_WORDS],
27
- BE: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, MATCH_WORDS],
28
- SE: [MATCH_BLOCK_OR_WORDS, CLOSEST_KEYWORDS],
29
- PL: [CLOSEST_KEYWORDS],
30
- NO: [CLOSEST_KEYWORDS],
31
- PT: [MATCH_BEGINNING],
32
- LU: [MATCH_BEGINNING, MATCH_BLOCK, EXACT_VALUE],
33
- CA: [MATCH_BEGINNING],
34
- ES: [EXACT_VALUE, CLOSEST_KEYWORDS],
35
- US: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
36
- PR: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
37
- AS: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
38
- FM: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
39
- GU: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
40
- MH: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
41
- MP: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
42
- PW: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
43
- VI: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
44
- SI: [MATCH_BLOCK_OR_WORDS],
45
- AL: [MATCH_BLOCK_OR_WORDS],
46
- BA: [MATCH_BLOCK_OR_WORDS],
47
- HR: [MATCH_BLOCK_OR_WORDS],
48
- MK: [MATCH_BLOCK_OR_WORDS],
49
- BG: [MATCH_BLOCK_OR_WORDS],
50
- RO: [MATCH_BLOCK_OR_WORDS],
51
- ME: [MATCH_BLOCK_OR_WORDS],
52
- RS: [MATCH_BLOCK_OR_WORDS],
53
- LV: [MATCH_BLOCK_OR_WORDS],
54
- EE: [MATCH_BLOCK_OR_WORDS],
55
- UA: [MATCH_BLOCK_OR_WORDS],
56
- MD: [MATCH_BLOCK_OR_WORDS],
57
- RU: [MATCH_BLOCK_OR_WORDS],
58
- AM: [MATCH_BLOCK_OR_WORDS],
59
- AZ: [MATCH_BLOCK_OR_WORDS],
60
- BY: [MATCH_BLOCK_OR_WORDS],
61
- GE: [MATCH_BLOCK_OR_WORDS],
62
- KZ: [MATCH_BLOCK_OR_WORDS],
63
- UZ: [MATCH_BLOCK_OR_WORDS],
64
- TJ: [MATCH_BLOCK_OR_WORDS],
65
- TM: [MATCH_BLOCK_OR_WORDS],
66
- KG: [MATCH_BLOCK_OR_WORDS],
67
- KM: [MATCH_BLOCK_OR_WORDS],
68
- HK: [MATCH_BLOCK_OR_WORDS],
69
- AT: [MATCH_WORDS],
70
- IT: [CLOSEST_KEYWORDS, EXACT_VALUE],
71
- BR: [CLOSEST_KEYWORDS],
72
- HU: [MATCH_BEGINNING],
73
- TW: [MATCH_BEGINNING],
74
- KR: [MATCH_BLOCK_OR_WORDS],
75
- FI: [CLOSEST_KEYWORDS],
76
- MX: [CLOSEST_KEYWORDS],
77
- DK: [MATCH_BEGINNING],
78
- AU: [CLOSEST_KEYWORDS],
79
- CN: [CLOSEST_KEYWORDS],
80
- IN: [CLOSEST_KEYWORDS],
81
- BD: [CLOSEST_KEYWORDS],
82
- LK: [CLOSEST_KEYWORDS],
83
- PK: [CLOSEST_KEYWORDS],
84
- NP: [CLOSEST_KEYWORDS],
85
- TH: [CLOSEST_KEYWORDS],
86
- MY: [CLOSEST_KEYWORDS],
87
- VN: [CLOSEST_KEYWORDS],
88
- KH: [CLOSEST_KEYWORDS],
89
- MM: [CLOSEST_KEYWORDS],
90
- LA: [CLOSEST_KEYWORDS],
91
- AF: [CLOSEST_KEYWORDS],
92
- ID: [CLOSEST_KEYWORDS],
93
- NZ: [CLOSEST_KEYWORDS],
94
- SG: [CLOSEST_KEYWORDS],
95
- BH: [CLOSEST_KEYWORDS],
96
- BJ: [CLOSEST_KEYWORDS],
97
- BF: [CLOSEST_KEYWORDS],
98
- CD: [CLOSEST_KEYWORDS],
99
- EG: [CLOSEST_KEYWORDS],
100
- JO: [CLOSEST_KEYWORDS],
101
- KW: [CLOSEST_KEYWORDS],
102
- LB: [CLOSEST_KEYWORDS],
103
- OM: [CLOSEST_KEYWORDS],
104
- PS: [CLOSEST_KEYWORDS],
105
- QA: [CLOSEST_KEYWORDS],
106
- SA: [CLOSEST_KEYWORDS],
107
- SD: [CLOSEST_KEYWORDS],
108
- SY: [CLOSEST_KEYWORDS],
109
- AE: [CLOSEST_KEYWORDS],
110
- EH: [CLOSEST_KEYWORDS],
111
- YE: [CLOSEST_KEYWORDS],
112
- GR: [MATCH_BLOCK_OR_WORDS, CLOSEST_KEYWORDS],
113
- }.freeze
114
- end
115
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ module MatchType
5
+ MATCH_BEGINNING = "MatchBeginning"
6
+ MATCH_BLOCK = "MatchBlock"
7
+ EXACT_VALUE = "ExactValue"
8
+ MATCH_WORDS = "MatchWords"
9
+ CLOSEST_KEYWORDS = "ClosestKeywords"
10
+ MATCH_BLOCK_OR_WORDS = "MatchBlockOrWords"
11
+ MATCH_ANY_PARTS = "MatchAnyParts"
12
+
13
+ ALLOWED = {
14
+ DE: [MATCH_BEGINNING, MATCH_BLOCK, EXACT_VALUE, MATCH_WORDS],
15
+ FR: [MATCH_BEGINNING, CLOSEST_KEYWORDS, EXACT_VALUE],
16
+ GB: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, EXACT_VALUE],
17
+ IE: [MATCH_BEGINNING, MATCH_BLOCK, MATCH_WORDS],
18
+ GL: [MATCH_BEGINNING],
19
+ CH: [CLOSEST_KEYWORDS],
20
+ LI: [CLOSEST_KEYWORDS],
21
+ NL: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, MATCH_WORDS],
22
+ CZ: [MATCH_BLOCK_OR_WORDS],
23
+ IS: [MATCH_BEGINNING],
24
+ LT: [MATCH_ANY_PARTS],
25
+ MT: [MATCH_BEGINNING, MATCH_BLOCK],
26
+ SK: [MATCH_BLOCK_OR_WORDS],
27
+ BE: [MATCH_BEGINNING, MATCH_BLOCK_OR_WORDS, MATCH_WORDS],
28
+ SE: [MATCH_BLOCK_OR_WORDS, CLOSEST_KEYWORDS],
29
+ PL: [CLOSEST_KEYWORDS],
30
+ NO: [CLOSEST_KEYWORDS],
31
+ PT: [MATCH_BEGINNING],
32
+ LU: [MATCH_BEGINNING, MATCH_BLOCK, EXACT_VALUE],
33
+ CA: [MATCH_BEGINNING],
34
+ ES: [EXACT_VALUE, CLOSEST_KEYWORDS],
35
+ US: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
36
+ PR: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
37
+ AS: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
38
+ FM: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
39
+ GU: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
40
+ MH: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
41
+ MP: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
42
+ PW: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
43
+ VI: [MATCH_BEGINNING, CLOSEST_KEYWORDS],
44
+ SI: [MATCH_BLOCK_OR_WORDS],
45
+ AL: [MATCH_BLOCK_OR_WORDS],
46
+ BA: [MATCH_BLOCK_OR_WORDS],
47
+ HR: [MATCH_BLOCK_OR_WORDS],
48
+ MK: [MATCH_BLOCK_OR_WORDS],
49
+ BG: [MATCH_BLOCK_OR_WORDS],
50
+ RO: [MATCH_BLOCK_OR_WORDS],
51
+ ME: [MATCH_BLOCK_OR_WORDS],
52
+ RS: [MATCH_BLOCK_OR_WORDS],
53
+ LV: [MATCH_BLOCK_OR_WORDS],
54
+ EE: [MATCH_BLOCK_OR_WORDS],
55
+ UA: [MATCH_BLOCK_OR_WORDS],
56
+ MD: [MATCH_BLOCK_OR_WORDS],
57
+ RU: [MATCH_BLOCK_OR_WORDS],
58
+ AM: [MATCH_BLOCK_OR_WORDS],
59
+ AZ: [MATCH_BLOCK_OR_WORDS],
60
+ BY: [MATCH_BLOCK_OR_WORDS],
61
+ GE: [MATCH_BLOCK_OR_WORDS],
62
+ KZ: [MATCH_BLOCK_OR_WORDS],
63
+ UZ: [MATCH_BLOCK_OR_WORDS],
64
+ TJ: [MATCH_BLOCK_OR_WORDS],
65
+ TM: [MATCH_BLOCK_OR_WORDS],
66
+ KG: [MATCH_BLOCK_OR_WORDS],
67
+ KM: [MATCH_BLOCK_OR_WORDS],
68
+ HK: [MATCH_BLOCK_OR_WORDS],
69
+ AT: [MATCH_WORDS],
70
+ IT: [CLOSEST_KEYWORDS, EXACT_VALUE],
71
+ BR: [CLOSEST_KEYWORDS],
72
+ HU: [MATCH_BEGINNING],
73
+ TW: [MATCH_BEGINNING],
74
+ KR: [MATCH_BLOCK_OR_WORDS],
75
+ FI: [CLOSEST_KEYWORDS],
76
+ MX: [CLOSEST_KEYWORDS],
77
+ DK: [MATCH_BEGINNING],
78
+ AU: [CLOSEST_KEYWORDS],
79
+ CN: [CLOSEST_KEYWORDS],
80
+ IN: [CLOSEST_KEYWORDS],
81
+ BD: [CLOSEST_KEYWORDS],
82
+ LK: [CLOSEST_KEYWORDS],
83
+ PK: [CLOSEST_KEYWORDS],
84
+ NP: [CLOSEST_KEYWORDS],
85
+ TH: [CLOSEST_KEYWORDS],
86
+ MY: [CLOSEST_KEYWORDS],
87
+ VN: [CLOSEST_KEYWORDS],
88
+ KH: [CLOSEST_KEYWORDS],
89
+ MM: [CLOSEST_KEYWORDS],
90
+ LA: [CLOSEST_KEYWORDS],
91
+ AF: [CLOSEST_KEYWORDS],
92
+ ID: [CLOSEST_KEYWORDS],
93
+ NZ: [CLOSEST_KEYWORDS],
94
+ SG: [CLOSEST_KEYWORDS],
95
+ BH: [CLOSEST_KEYWORDS],
96
+ BJ: [CLOSEST_KEYWORDS],
97
+ BF: [CLOSEST_KEYWORDS],
98
+ CD: [CLOSEST_KEYWORDS],
99
+ EG: [CLOSEST_KEYWORDS],
100
+ JO: [CLOSEST_KEYWORDS],
101
+ KW: [CLOSEST_KEYWORDS],
102
+ LB: [CLOSEST_KEYWORDS],
103
+ OM: [CLOSEST_KEYWORDS],
104
+ PS: [CLOSEST_KEYWORDS],
105
+ QA: [CLOSEST_KEYWORDS],
106
+ SA: [CLOSEST_KEYWORDS],
107
+ SD: [CLOSEST_KEYWORDS],
108
+ SY: [CLOSEST_KEYWORDS],
109
+ AE: [CLOSEST_KEYWORDS],
110
+ EH: [CLOSEST_KEYWORDS],
111
+ YE: [CLOSEST_KEYWORDS],
112
+ GR: [MATCH_BLOCK_OR_WORDS, CLOSEST_KEYWORDS],
113
+ }.freeze
114
+ end
115
+ end
@@ -1,97 +1,97 @@
1
- # frozen_string_literal: true
2
-
3
- require "creditsafe/errors"
4
-
5
- module Creditsafe
6
- module Messages
7
- class Message
8
- attr_reader :code, :message, :error
9
-
10
- def initialize(code: nil, message: nil, error: false)
11
- raise ArgumentError, "Parameters 'code' and 'message' are mandatory" \
12
- unless code && message
13
- @code = code
14
- @message = message
15
- @error = error
16
- end
17
-
18
- alias_method :error?, :error
19
-
20
- def error_class
21
- return unless error?
22
-
23
- case code[1].to_i
24
- when 1 then Creditsafe::DataError
25
- when 2 then Creditsafe::AccountError
26
- when 3 then Creditsafe::RequestError
27
- when 4 then Creditsafe::ProcessingError
28
- else Creditsafe::UnknownApiError
29
- end
30
- end
31
- end
32
-
33
- # rubocop:disable Metrics/LineLength
34
- NO_RESULTS = Message.new(code: "010101", message: "No results")
35
- TOO_MANY_RESULTS = Message.new(code: "010102", message: "Too many results")
36
- REPORT_UNAVAILABLE = Message.new(code: "010103", message: "Report unavailable", error: true)
37
- REPORT_UNAVAILABLE_LEGAL = Message.new(code: "010104", message: "Report unavailable due to legal causes", error: true)
38
- REPORT_UNAVAILABLE_ONLINE = Message.new(code: "010105", message: "Report unavailable online", error: true)
39
- LEGAL_NOTICE = Message.new(code: "010106", message: "Legal notice")
40
- INVALID_CREDENTIALS = Message.new(code: "020101", message: "Invalid credentials", error: true)
41
- ACCESS_RESTRICTED = Message.new(code: "020102", message: "Access restricted", error: true)
42
- ACCESS_LIMITS_NEARING = Message.new(code: "020103", message: "Access limits nearing")
43
- REPORTBOX_ALMOST_FULL = Message.new(code: "020201", message: "Reportbox almost full", error: true)
44
- REPORTBOX_FULL = Message.new(code: "020202", message: "Reportbox full", error: true)
45
- INVALID_REQUEST_XML = Message.new(code: "030101", message: "Invalid request XML", error: true)
46
- INVALID_OPERATION_PARAMS = Message.new(code: "030102", message: "Invalid operation parameters", error: true)
47
- OPERATION_NOT_SUPPORTED = Message.new(code: "030103", message: "Operation not supported", error: true)
48
- INVALID_CUSTOM_DATA_SPECIFIED = Message.new(code: "030104", message: "Invalid custom data specified", error: true)
49
- CHANGE_NOTIFICATION = Message.new(code: "030201", message: "Change notification")
50
- TEMPORARY_SYSTEM_PROBLEM = Message.new(code: "030202", message: "Temporary system problem", error: true)
51
- ENDPOINT_SHUTDOWN = Message.new(code: "030203", message: "Endpoint shutdown", error: true)
52
- UNEXPECTED_INTERNAL_ERROR = Message.new(code: "040101", message: "Unexpected internal error", error: true)
53
- OTHER_ERROR = Message.new(code: "040102", message: "Other", error: true)
54
- DATA_SERVICE_PROBLEMS = Message.new(code: "040103", message: "Data service access problems", error: true)
55
- DATA_SERVICE_INVALID_RESPONSE = Message.new(code: "040104", message: "Data service invalid response", error: true)
56
- # rubocop:enable Metrics/LineLength
57
-
58
- ALL = [
59
- NO_RESULTS,
60
- TOO_MANY_RESULTS,
61
- REPORT_UNAVAILABLE,
62
- REPORT_UNAVAILABLE_LEGAL,
63
- REPORT_UNAVAILABLE_ONLINE,
64
- LEGAL_NOTICE,
65
- INVALID_CREDENTIALS,
66
- ACCESS_RESTRICTED,
67
- ACCESS_LIMITS_NEARING,
68
- REPORTBOX_ALMOST_FULL,
69
- REPORTBOX_FULL,
70
- INVALID_REQUEST_XML,
71
- INVALID_OPERATION_PARAMS,
72
- OPERATION_NOT_SUPPORTED,
73
- INVALID_CUSTOM_DATA_SPECIFIED,
74
- CHANGE_NOTIFICATION,
75
- TEMPORARY_SYSTEM_PROBLEM,
76
- ENDPOINT_SHUTDOWN,
77
- UNEXPECTED_INTERNAL_ERROR,
78
- OTHER_ERROR,
79
- DATA_SERVICE_PROBLEMS,
80
- DATA_SERVICE_INVALID_RESPONSE,
81
- ].freeze
82
-
83
- # Creditsafe documentation shows a 6 digit error code, however their API
84
- # strips the leading 0. To comply with the docs, we pad the API code here to
85
- # ensure we find the right match
86
- def self.for_code(code)
87
- padded_code = code.rjust(6, "0")
88
- message = ALL.find { |msg| msg.code == padded_code }
89
-
90
- if message.nil?
91
- message = Message.new(code: code, message: "Unknown error", error: true)
92
- end
93
-
94
- message
95
- end
96
- end
97
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "creditsafe/errors"
4
+
5
+ module Creditsafe
6
+ module Messages
7
+ class Message
8
+ attr_reader :code, :message, :error
9
+
10
+ def initialize(code: nil, message: nil, error: false)
11
+ raise ArgumentError, "Parameters 'code' and 'message' are mandatory" \
12
+ unless code && message
13
+ @code = code
14
+ @message = message
15
+ @error = error
16
+ end
17
+
18
+ alias_method :error?, :error
19
+
20
+ def error_class
21
+ return unless error?
22
+
23
+ case code[1].to_i
24
+ when 1 then Creditsafe::DataError
25
+ when 2 then Creditsafe::AccountError
26
+ when 3 then Creditsafe::RequestError
27
+ when 4 then Creditsafe::ProcessingError
28
+ else Creditsafe::UnknownApiError
29
+ end
30
+ end
31
+ end
32
+
33
+ # rubocop:disable Metrics/LineLength
34
+ NO_RESULTS = Message.new(code: "010101", message: "No results")
35
+ TOO_MANY_RESULTS = Message.new(code: "010102", message: "Too many results")
36
+ REPORT_UNAVAILABLE = Message.new(code: "010103", message: "Report unavailable", error: true)
37
+ REPORT_UNAVAILABLE_LEGAL = Message.new(code: "010104", message: "Report unavailable due to legal causes", error: true)
38
+ REPORT_UNAVAILABLE_ONLINE = Message.new(code: "010105", message: "Report unavailable online", error: true)
39
+ LEGAL_NOTICE = Message.new(code: "010106", message: "Legal notice")
40
+ INVALID_CREDENTIALS = Message.new(code: "020101", message: "Invalid credentials", error: true)
41
+ ACCESS_RESTRICTED = Message.new(code: "020102", message: "Access restricted", error: true)
42
+ ACCESS_LIMITS_NEARING = Message.new(code: "020103", message: "Access limits nearing")
43
+ REPORTBOX_ALMOST_FULL = Message.new(code: "020201", message: "Reportbox almost full", error: true)
44
+ REPORTBOX_FULL = Message.new(code: "020202", message: "Reportbox full", error: true)
45
+ INVALID_REQUEST_XML = Message.new(code: "030101", message: "Invalid request XML", error: true)
46
+ INVALID_OPERATION_PARAMS = Message.new(code: "030102", message: "Invalid operation parameters", error: true)
47
+ OPERATION_NOT_SUPPORTED = Message.new(code: "030103", message: "Operation not supported", error: true)
48
+ INVALID_CUSTOM_DATA_SPECIFIED = Message.new(code: "030104", message: "Invalid custom data specified", error: true)
49
+ CHANGE_NOTIFICATION = Message.new(code: "030201", message: "Change notification")
50
+ TEMPORARY_SYSTEM_PROBLEM = Message.new(code: "030202", message: "Temporary system problem", error: true)
51
+ ENDPOINT_SHUTDOWN = Message.new(code: "030203", message: "Endpoint shutdown", error: true)
52
+ UNEXPECTED_INTERNAL_ERROR = Message.new(code: "040101", message: "Unexpected internal error", error: true)
53
+ OTHER_ERROR = Message.new(code: "040102", message: "Other", error: true)
54
+ DATA_SERVICE_PROBLEMS = Message.new(code: "040103", message: "Data service access problems", error: true)
55
+ DATA_SERVICE_INVALID_RESPONSE = Message.new(code: "040104", message: "Data service invalid response", error: true)
56
+ # rubocop:enable Metrics/LineLength
57
+
58
+ ALL = [
59
+ NO_RESULTS,
60
+ TOO_MANY_RESULTS,
61
+ REPORT_UNAVAILABLE,
62
+ REPORT_UNAVAILABLE_LEGAL,
63
+ REPORT_UNAVAILABLE_ONLINE,
64
+ LEGAL_NOTICE,
65
+ INVALID_CREDENTIALS,
66
+ ACCESS_RESTRICTED,
67
+ ACCESS_LIMITS_NEARING,
68
+ REPORTBOX_ALMOST_FULL,
69
+ REPORTBOX_FULL,
70
+ INVALID_REQUEST_XML,
71
+ INVALID_OPERATION_PARAMS,
72
+ OPERATION_NOT_SUPPORTED,
73
+ INVALID_CUSTOM_DATA_SPECIFIED,
74
+ CHANGE_NOTIFICATION,
75
+ TEMPORARY_SYSTEM_PROBLEM,
76
+ ENDPOINT_SHUTDOWN,
77
+ UNEXPECTED_INTERNAL_ERROR,
78
+ OTHER_ERROR,
79
+ DATA_SERVICE_PROBLEMS,
80
+ DATA_SERVICE_INVALID_RESPONSE,
81
+ ].freeze
82
+
83
+ # Creditsafe documentation shows a 6 digit error code, however their API
84
+ # strips the leading 0. To comply with the docs, we pad the API code here to
85
+ # ensure we find the right match
86
+ def self.for_code(code)
87
+ padded_code = code.rjust(6, "0")
88
+ message = ALL.find { |msg| msg.code == padded_code }
89
+
90
+ if message.nil?
91
+ message = Message.new(code: code, message: "Unknown error", error: true)
92
+ end
93
+
94
+ message
95
+ end
96
+ end
97
+ end
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
- module Creditsafe
4
- module Namespace
5
- OPER = "oper"
6
- OPER_VAL = "http://www.creditsafe.com/globaldata/operations"
7
-
8
- DAT = "dat"
9
- DAT_VAL = "http://www.creditsafe.com/globaldata/datatypes"
10
-
11
- CRED = "cred"
12
- CRED_VAL = "http://schemas.datacontract.org/2004/07/Creditsafe.GlobalData"
13
-
14
- ALL = {
15
- "xmlns:#{Creditsafe::Namespace::OPER}" => Creditsafe::Namespace::OPER_VAL,
16
- "xmlns:#{Creditsafe::Namespace::DAT}" => Creditsafe::Namespace::DAT_VAL,
17
- "xmlns:#{Creditsafe::Namespace::CRED}" => Creditsafe::Namespace::CRED_VAL,
18
- }.freeze
19
- end
20
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ module Namespace
5
+ OPER = "oper"
6
+ OPER_VAL = "http://www.creditsafe.com/globaldata/operations"
7
+
8
+ DAT = "dat"
9
+ DAT_VAL = "http://www.creditsafe.com/globaldata/datatypes"
10
+
11
+ CRED = "cred"
12
+ CRED_VAL = "http://schemas.datacontract.org/2004/07/Creditsafe.GlobalData"
13
+
14
+ ALL = {
15
+ "xmlns:#{Creditsafe::Namespace::OPER}" => Creditsafe::Namespace::OPER_VAL,
16
+ "xmlns:#{Creditsafe::Namespace::DAT}" => Creditsafe::Namespace::DAT_VAL,
17
+ "xmlns:#{Creditsafe::Namespace::CRED}" => Creditsafe::Namespace::CRED_VAL,
18
+ }.freeze
19
+ end
20
+ end