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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +17 -17
- data/.gitignore +2 -2
- data/.rspec +1 -1
- data/.rubocop.yml +11 -11
- data/.ruby-version +1 -1
- data/CHANGELOG.md +41 -37
- data/Gemfile +5 -5
- data/Gemfile.lock +127 -125
- data/LICENSE.txt +22 -22
- data/README.md +138 -138
- data/creditsafe.gemspec +35 -35
- data/data/creditsafe-live.xml +342 -342
- data/data/creditsafe-test.xml +342 -342
- data/lib/creditsafe.rb +4 -4
- data/lib/creditsafe/client.rb +158 -156
- data/lib/creditsafe/errors.rb +16 -14
- data/lib/creditsafe/match_type.rb +115 -115
- data/lib/creditsafe/messages.rb +97 -97
- data/lib/creditsafe/namespace.rb +20 -20
- data/lib/creditsafe/request/company_report.rb +42 -42
- data/lib/creditsafe/request/find_company.rb +98 -98
- data/lib/creditsafe/version.rb +5 -5
- data/spec/creditsafe/client_spec.rb +369 -372
- data/spec/creditsafe/messages_spec.rb +76 -76
- data/spec/fixtures/company-report-not-found.xml +13 -13
- data/spec/fixtures/company-report-request.xml +1 -1
- data/spec/fixtures/company-report-successful.xml +582 -582
- data/spec/fixtures/error-fault.xml +8 -8
- data/spec/fixtures/error-invalid-credentials.html +31 -31
- data/spec/fixtures/find-companies-error-no-text.xml +11 -11
- data/spec/fixtures/find-companies-error.xml +11 -11
- data/spec/fixtures/find-companies-none-found.xml +13 -13
- data/spec/fixtures/find-companies-request.xml +1 -1
- data/spec/fixtures/find-companies-successful-multi.xml +493 -493
- data/spec/fixtures/find-companies-successful.xml +29 -29
- data/spec/spec_helper.rb +14 -14
- metadata +4 -4
data/lib/creditsafe/messages.rb
CHANGED
@@ -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
|
data/lib/creditsafe/namespace.rb
CHANGED
@@ -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
|
@@ -1,42 +1,42 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "creditsafe/namespace"
|
4
|
-
|
5
|
-
module Creditsafe
|
6
|
-
module Request
|
7
|
-
class CompanyReport
|
8
|
-
def initialize(company_id, custom_data)
|
9
|
-
@company_id = company_id
|
10
|
-
@custom_data = custom_data
|
11
|
-
end
|
12
|
-
|
13
|
-
# rubocop:disable Metrics/MethodLength
|
14
|
-
def message
|
15
|
-
message = {
|
16
|
-
"#{Creditsafe::Namespace::OPER}:companyId" => company_id.to_s,
|
17
|
-
"#{Creditsafe::Namespace::OPER}:reportType" => "Full",
|
18
|
-
"#{Creditsafe::Namespace::OPER}:language" => "EN",
|
19
|
-
}
|
20
|
-
|
21
|
-
unless custom_data.nil?
|
22
|
-
message["#{Creditsafe::Namespace::OPER}:customData"] = {
|
23
|
-
"#{Creditsafe::Namespace::DAT}:Entries" => {
|
24
|
-
"#{Creditsafe::Namespace::DAT}:Entry" => custom_data_entries,
|
25
|
-
},
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
message
|
30
|
-
end
|
31
|
-
# rubocop:enable Metrics/MethodLength
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def custom_data_entries
|
36
|
-
custom_data.map { |key, value| { :@key => key, :content! => value } }
|
37
|
-
end
|
38
|
-
|
39
|
-
attr_reader :company_id, :custom_data
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "creditsafe/namespace"
|
4
|
+
|
5
|
+
module Creditsafe
|
6
|
+
module Request
|
7
|
+
class CompanyReport
|
8
|
+
def initialize(company_id, custom_data)
|
9
|
+
@company_id = company_id
|
10
|
+
@custom_data = custom_data
|
11
|
+
end
|
12
|
+
|
13
|
+
# rubocop:disable Metrics/MethodLength
|
14
|
+
def message
|
15
|
+
message = {
|
16
|
+
"#{Creditsafe::Namespace::OPER}:companyId" => company_id.to_s,
|
17
|
+
"#{Creditsafe::Namespace::OPER}:reportType" => "Full",
|
18
|
+
"#{Creditsafe::Namespace::OPER}:language" => "EN",
|
19
|
+
}
|
20
|
+
|
21
|
+
unless custom_data.nil?
|
22
|
+
message["#{Creditsafe::Namespace::OPER}:customData"] = {
|
23
|
+
"#{Creditsafe::Namespace::DAT}:Entries" => {
|
24
|
+
"#{Creditsafe::Namespace::DAT}:Entry" => custom_data_entries,
|
25
|
+
},
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
message
|
30
|
+
end
|
31
|
+
# rubocop:enable Metrics/MethodLength
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def custom_data_entries
|
36
|
+
custom_data.map { |key, value| { :@key => key, :content! => value } }
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :company_id, :custom_data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,98 +1,98 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "creditsafe/match_type"
|
4
|
-
require "creditsafe/namespace"
|
5
|
-
|
6
|
-
module Creditsafe
|
7
|
-
module Request
|
8
|
-
class FindCompany
|
9
|
-
def initialize(search_criteria)
|
10
|
-
check_search_criteria(search_criteria)
|
11
|
-
@country_code = search_criteria[:country_code]
|
12
|
-
@registration_number = search_criteria[:registration_number]
|
13
|
-
@company_name = search_criteria[:company_name]
|
14
|
-
@city = search_criteria[:city]
|
15
|
-
@postal_code = search_criteria[:postal_code]
|
16
|
-
end
|
17
|
-
|
18
|
-
# rubocop:disable Metrics/MethodLength
|
19
|
-
# rubocop:disable Metrics/AbcSize
|
20
|
-
def message
|
21
|
-
search_criteria = {}
|
22
|
-
|
23
|
-
unless company_name.nil?
|
24
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
|
25
|
-
"@MatchType" => match_type,
|
26
|
-
:content! => company_name,
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
unless registration_number.nil?
|
31
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
|
32
|
-
registration_number
|
33
|
-
end
|
34
|
-
|
35
|
-
unless city.nil?
|
36
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
37
|
-
"#{Creditsafe::Namespace::DAT}:City" => city,
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
unless postal_code.nil?
|
42
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
43
|
-
"#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
build_message(search_criteria)
|
48
|
-
end
|
49
|
-
# rubocop:enable Metrics/AbcSize
|
50
|
-
# rubocop:enable Metrics/MethodLength
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
attr_reader :country_code, :registration_number, :city, :company_name, :postal_code
|
55
|
-
|
56
|
-
def match_type
|
57
|
-
Creditsafe::MatchType::ALLOWED[country_code.upcase.to_sym]&.first ||
|
58
|
-
Creditsafe::MatchType::MATCH_BLOCK
|
59
|
-
end
|
60
|
-
|
61
|
-
def build_message(search_criteria)
|
62
|
-
{
|
63
|
-
"#{Creditsafe::Namespace::OPER}:countries" => {
|
64
|
-
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
|
65
|
-
},
|
66
|
-
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
71
|
-
# rubocop:disable Metrics/MethodLength
|
72
|
-
def check_search_criteria(search_criteria)
|
73
|
-
if search_criteria[:country_code].nil?
|
74
|
-
raise ArgumentError, "country_code is a required search criteria"
|
75
|
-
end
|
76
|
-
|
77
|
-
unless only_registration_number_or_company_name_provided?(search_criteria)
|
78
|
-
raise ArgumentError, "registration_number or company_name (not both) are " \
|
79
|
-
"required search criteria"
|
80
|
-
end
|
81
|
-
|
82
|
-
if search_criteria[:city] && search_criteria[:country_code] != "DE"
|
83
|
-
raise ArgumentError, "city is only supported for German searches"
|
84
|
-
end
|
85
|
-
|
86
|
-
if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
|
87
|
-
raise ArgumentError, "Postal code is only supported for German searches"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
# rubocop:enable Metrics/MethodLength
|
91
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
92
|
-
|
93
|
-
def only_registration_number_or_company_name_provided?(search_criteria)
|
94
|
-
search_criteria[:registration_number].nil? ^ search_criteria[:company_name].nil?
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "creditsafe/match_type"
|
4
|
+
require "creditsafe/namespace"
|
5
|
+
|
6
|
+
module Creditsafe
|
7
|
+
module Request
|
8
|
+
class FindCompany
|
9
|
+
def initialize(search_criteria)
|
10
|
+
check_search_criteria(search_criteria)
|
11
|
+
@country_code = search_criteria[:country_code]
|
12
|
+
@registration_number = search_criteria[:registration_number]
|
13
|
+
@company_name = search_criteria[:company_name]
|
14
|
+
@city = search_criteria[:city]
|
15
|
+
@postal_code = search_criteria[:postal_code]
|
16
|
+
end
|
17
|
+
|
18
|
+
# rubocop:disable Metrics/MethodLength
|
19
|
+
# rubocop:disable Metrics/AbcSize
|
20
|
+
def message
|
21
|
+
search_criteria = {}
|
22
|
+
|
23
|
+
unless company_name.nil?
|
24
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
|
25
|
+
"@MatchType" => match_type,
|
26
|
+
:content! => company_name,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
unless registration_number.nil?
|
31
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
|
32
|
+
registration_number
|
33
|
+
end
|
34
|
+
|
35
|
+
unless city.nil?
|
36
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
37
|
+
"#{Creditsafe::Namespace::DAT}:City" => city,
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
unless postal_code.nil?
|
42
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
43
|
+
"#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
build_message(search_criteria)
|
48
|
+
end
|
49
|
+
# rubocop:enable Metrics/AbcSize
|
50
|
+
# rubocop:enable Metrics/MethodLength
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
attr_reader :country_code, :registration_number, :city, :company_name, :postal_code
|
55
|
+
|
56
|
+
def match_type
|
57
|
+
Creditsafe::MatchType::ALLOWED[country_code.upcase.to_sym]&.first ||
|
58
|
+
Creditsafe::MatchType::MATCH_BLOCK
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_message(search_criteria)
|
62
|
+
{
|
63
|
+
"#{Creditsafe::Namespace::OPER}:countries" => {
|
64
|
+
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
|
65
|
+
},
|
66
|
+
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
71
|
+
# rubocop:disable Metrics/MethodLength
|
72
|
+
def check_search_criteria(search_criteria)
|
73
|
+
if search_criteria[:country_code].nil?
|
74
|
+
raise ArgumentError, "country_code is a required search criteria"
|
75
|
+
end
|
76
|
+
|
77
|
+
unless only_registration_number_or_company_name_provided?(search_criteria)
|
78
|
+
raise ArgumentError, "registration_number or company_name (not both) are " \
|
79
|
+
"required search criteria"
|
80
|
+
end
|
81
|
+
|
82
|
+
if search_criteria[:city] && search_criteria[:country_code] != "DE"
|
83
|
+
raise ArgumentError, "city is only supported for German searches"
|
84
|
+
end
|
85
|
+
|
86
|
+
if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
|
87
|
+
raise ArgumentError, "Postal code is only supported for German searches"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
# rubocop:enable Metrics/MethodLength
|
91
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
92
|
+
|
93
|
+
def only_registration_number_or_company_name_provided?(search_criteria)
|
94
|
+
search_criteria[:registration_number].nil? ^ search_criteria[:company_name].nil?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|