creditsafe 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +66 -17
  3. data/.github/dependabot.yml +17 -0
  4. data/.gitignore +4 -2
  5. data/.rspec +1 -1
  6. data/.rubocop.yml +18 -11
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +64 -45
  9. data/Gemfile +5 -5
  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/client.rb +165 -158
  16. data/lib/creditsafe/{constants.rb → country.rb} +49 -49
  17. data/lib/creditsafe/errors.rb +23 -16
  18. data/lib/creditsafe/match_type.rb +115 -115
  19. data/lib/creditsafe/messages.rb +98 -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 +118 -120
  23. data/lib/creditsafe/version.rb +5 -5
  24. data/lib/creditsafe.rb +4 -4
  25. data/spec/creditsafe/client_spec.rb +431 -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 +46 -46
  40. 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/constants"
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/PerceivedComplexity
81
- # rubocop:disable Metrics/AbcSize
82
- def check_search_criteria(search_criteria)
83
- if search_criteria[:country_code].nil?
84
- raise ArgumentError, "country_code is a required search criteria"
85
- end
86
-
87
- unless only_one_required_criteria?(search_criteria)
88
- raise ArgumentError, "only one of registration_number, company_name or " \
89
- "vat number is required search criteria"
90
- end
91
-
92
- if search_criteria[:city] && search_criteria[:country_code] != "DE"
93
- raise ArgumentError, "city is only supported for German searches"
94
- end
95
-
96
- if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
97
- raise ArgumentError, "Postal code is only supported for German searches"
98
- end
99
-
100
- if search_criteria[:vat_number] && !Constants::Country::VAT_NUMBER_SUPPORTED.
101
- include?(search_criteria[:country_code])
102
- raise ArgumentError, "VAT number is not supported in this country"
103
- end
104
- end
105
- # rubocop:enable Metrics/AbcSize
106
- # rubocop:enable Metrics/PerceivedComplexity
107
- # rubocop:enable Metrics/MethodLength
108
- # rubocop:enable Metrics/CyclomaticComplexity
109
-
110
- def only_one_required_criteria?(search_criteria)
111
- by_registration_number = !search_criteria[:registration_number].nil?
112
- by_company_name = !search_criteria[:company_name].nil?
113
- by_vat_number = !search_criteria[:vat_number].nil?
114
-
115
- (by_registration_number ^ by_company_name ^ by_vat_number) &&
116
- !(by_registration_number && by_company_name && by_vat_number)
117
- end
118
- end
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
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Creditsafe
4
- VERSION = "0.6.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"