creditsafe 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +66 -17
- data/.github/dependabot.yml +17 -0
- data/.gitignore +4 -2
- data/.rspec +1 -1
- data/.rubocop.yml +18 -11
- data/.ruby-version +1 -1
- data/CHANGELOG.md +64 -45
- data/Gemfile +5 -5
- data/LICENSE.txt +22 -22
- data/README.md +175 -175
- data/creditsafe.gemspec +35 -35
- data/data/creditsafe-live.xml +342 -342
- data/data/creditsafe-test.xml +342 -342
- data/lib/creditsafe/client.rb +165 -158
- data/lib/creditsafe/{constants.rb → country.rb} +49 -49
- data/lib/creditsafe/errors.rb +23 -16
- data/lib/creditsafe/match_type.rb +115 -115
- data/lib/creditsafe/messages.rb +98 -97
- data/lib/creditsafe/namespace.rb +20 -20
- data/lib/creditsafe/request/company_report.rb +42 -42
- data/lib/creditsafe/request/find_company.rb +118 -120
- data/lib/creditsafe/version.rb +5 -5
- data/lib/creditsafe.rb +4 -4
- data/spec/creditsafe/client_spec.rb +431 -423
- 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 +46 -46
- data/Gemfile.lock +0 -129
@@ -1,120 +1,118 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "creditsafe/match_type"
|
4
|
-
require "creditsafe/namespace"
|
5
|
-
require "creditsafe/
|
6
|
-
|
7
|
-
module Creditsafe
|
8
|
-
module Request
|
9
|
-
class FindCompany
|
10
|
-
def initialize(search_criteria)
|
11
|
-
check_search_criteria(search_criteria)
|
12
|
-
@country_code = search_criteria[:country_code]
|
13
|
-
@registration_number = search_criteria[:registration_number]
|
14
|
-
@company_name = search_criteria[:company_name]
|
15
|
-
@vat_number = search_criteria[:vat_number]
|
16
|
-
@city = search_criteria[:city]
|
17
|
-
@postal_code = search_criteria[:postal_code]
|
18
|
-
end
|
19
|
-
|
20
|
-
# rubocop:disable Metrics/MethodLength
|
21
|
-
# rubocop:disable Metrics/AbcSize
|
22
|
-
def message
|
23
|
-
search_criteria = {}
|
24
|
-
|
25
|
-
unless company_name.nil?
|
26
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
|
27
|
-
"@MatchType" => match_type,
|
28
|
-
:content! => company_name,
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
unless registration_number.nil?
|
33
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
|
34
|
-
registration_number
|
35
|
-
end
|
36
|
-
|
37
|
-
unless vat_number.nil?
|
38
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:VatNumber"] =
|
39
|
-
vat_number
|
40
|
-
end
|
41
|
-
|
42
|
-
unless city.nil?
|
43
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
44
|
-
"#{Creditsafe::Namespace::DAT}:City" => city,
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
unless postal_code.nil?
|
49
|
-
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
50
|
-
"#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
build_message(search_criteria)
|
55
|
-
end
|
56
|
-
# rubocop:enable Metrics/AbcSize
|
57
|
-
# rubocop:enable Metrics/MethodLength
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
attr_reader :country_code, :registration_number, :city, :company_name, :postal_code,
|
62
|
-
:vat_number
|
63
|
-
|
64
|
-
def match_type
|
65
|
-
Creditsafe::MatchType::ALLOWED[country_code.upcase.to_sym]&.first ||
|
66
|
-
Creditsafe::MatchType::MATCH_BLOCK
|
67
|
-
end
|
68
|
-
|
69
|
-
def build_message(search_criteria)
|
70
|
-
{
|
71
|
-
"#{Creditsafe::Namespace::OPER}:countries" => {
|
72
|
-
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
|
73
|
-
},
|
74
|
-
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
79
|
-
# rubocop:disable Metrics/MethodLength
|
80
|
-
# rubocop:disable Metrics/
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# rubocop:enable Metrics/
|
106
|
-
# rubocop:enable Metrics/
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
by_vat_number
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "creditsafe/match_type"
|
4
|
+
require "creditsafe/namespace"
|
5
|
+
require "creditsafe/country"
|
6
|
+
|
7
|
+
module Creditsafe
|
8
|
+
module Request
|
9
|
+
class FindCompany
|
10
|
+
def initialize(search_criteria)
|
11
|
+
check_search_criteria(search_criteria)
|
12
|
+
@country_code = search_criteria[:country_code]
|
13
|
+
@registration_number = search_criteria[:registration_number]
|
14
|
+
@company_name = search_criteria[:company_name]
|
15
|
+
@vat_number = search_criteria[:vat_number]
|
16
|
+
@city = search_criteria[:city]
|
17
|
+
@postal_code = search_criteria[:postal_code]
|
18
|
+
end
|
19
|
+
|
20
|
+
# rubocop:disable Metrics/MethodLength
|
21
|
+
# rubocop:disable Metrics/AbcSize
|
22
|
+
def message
|
23
|
+
search_criteria = {}
|
24
|
+
|
25
|
+
unless company_name.nil?
|
26
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
|
27
|
+
"@MatchType" => match_type,
|
28
|
+
:content! => company_name,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
unless registration_number.nil?
|
33
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
|
34
|
+
registration_number
|
35
|
+
end
|
36
|
+
|
37
|
+
unless vat_number.nil?
|
38
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:VatNumber"] =
|
39
|
+
vat_number
|
40
|
+
end
|
41
|
+
|
42
|
+
unless city.nil?
|
43
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
44
|
+
"#{Creditsafe::Namespace::DAT}:City" => city,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
unless postal_code.nil?
|
49
|
+
search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
|
50
|
+
"#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
build_message(search_criteria)
|
55
|
+
end
|
56
|
+
# rubocop:enable Metrics/AbcSize
|
57
|
+
# rubocop:enable Metrics/MethodLength
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_reader :country_code, :registration_number, :city, :company_name, :postal_code,
|
62
|
+
:vat_number
|
63
|
+
|
64
|
+
def match_type
|
65
|
+
Creditsafe::MatchType::ALLOWED[country_code.upcase.to_sym]&.first ||
|
66
|
+
Creditsafe::MatchType::MATCH_BLOCK
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_message(search_criteria)
|
70
|
+
{
|
71
|
+
"#{Creditsafe::Namespace::OPER}:countries" => {
|
72
|
+
"#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
|
73
|
+
},
|
74
|
+
"#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
79
|
+
# rubocop:disable Metrics/MethodLength
|
80
|
+
# rubocop:disable Metrics/AbcSize
|
81
|
+
def check_search_criteria(search_criteria)
|
82
|
+
if search_criteria[:country_code].nil?
|
83
|
+
raise ArgumentError, "country_code is a required search criteria"
|
84
|
+
end
|
85
|
+
|
86
|
+
unless only_one_required_criteria?(search_criteria)
|
87
|
+
raise ArgumentError, "only one of registration_number, company_name or " \
|
88
|
+
"vat number is required search criteria"
|
89
|
+
end
|
90
|
+
|
91
|
+
if search_criteria[:city] && search_criteria[:country_code] != "DE"
|
92
|
+
raise ArgumentError, "city is only supported for German searches"
|
93
|
+
end
|
94
|
+
|
95
|
+
if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
|
96
|
+
raise ArgumentError, "Postal code is only supported for German searches"
|
97
|
+
end
|
98
|
+
|
99
|
+
if search_criteria[:vat_number] && !Creditsafe::Country::VAT_NUMBER_SUPPORTED.
|
100
|
+
include?(search_criteria[:country_code])
|
101
|
+
raise ArgumentError, "VAT number is not supported in this country"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
# rubocop:enable Metrics/AbcSize
|
105
|
+
# rubocop:enable Metrics/MethodLength
|
106
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
107
|
+
|
108
|
+
def only_one_required_criteria?(search_criteria)
|
109
|
+
by_registration_number = !search_criteria[:registration_number].nil?
|
110
|
+
by_company_name = !search_criteria[:company_name].nil?
|
111
|
+
by_vat_number = !search_criteria[:vat_number].nil?
|
112
|
+
|
113
|
+
(by_registration_number ^ by_company_name ^ by_vat_number) &&
|
114
|
+
!(by_registration_number && by_company_name && by_vat_number)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/creditsafe/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Creditsafe
|
4
|
-
VERSION = "0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Creditsafe
|
4
|
+
VERSION = "0.7.0"
|
5
|
+
end
|
data/lib/creditsafe.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "creditsafe/errors"
|
4
|
-
require "creditsafe/client"
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "creditsafe/errors"
|
4
|
+
require "creditsafe/client"
|