lib/creditsafe/request/find_company.rb in creditsafe-0.5.0 vs lib/creditsafe/request/find_company.rb in creditsafe-0.5.1
- old
+ new
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'creditsafe/namespace'
-require 'creditsafe/match_type'
+require "creditsafe/match_type"
+require "creditsafe/namespace"
module Creditsafe
module Request
class FindCompany
def initialize(search_criteria)
@@ -18,27 +18,33 @@
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def message
search_criteria = {}
- search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
- '@MatchType' => match_type,
- :content! => company_name
- } unless company_name.nil?
+ unless company_name.nil?
+ search_criteria["#{Creditsafe::Namespace::DAT}:Name"] = {
+ "@MatchType" => match_type,
+ :content! => company_name,
+ }
+ end
unless registration_number.nil?
search_criteria["#{Creditsafe::Namespace::DAT}:RegistrationNumber"] =
registration_number
end
- search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
- "#{Creditsafe::Namespace::DAT}:City" => city
- } unless city.nil?
+ unless city.nil?
+ search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
+ "#{Creditsafe::Namespace::DAT}:City" => city,
+ }
+ end
- search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
- "#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code
- } unless postal_code.nil?
+ unless postal_code.nil?
+ search_criteria["#{Creditsafe::Namespace::DAT}:Address"] = {
+ "#{Creditsafe::Namespace::DAT}:PostalCode" => postal_code,
+ }
+ end
build_message(search_criteria)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
@@ -53,34 +59,36 @@
end
def build_message(search_criteria)
{
"#{Creditsafe::Namespace::OPER}:countries" => {
- "#{Creditsafe::Namespace::CRED}:CountryCode" => country_code
+ "#{Creditsafe::Namespace::CRED}:CountryCode" => country_code,
},
- "#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria
+ "#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria,
}
end
# rubocop:disable Metrics/CyclomaticComplexity
+ # rubocop:disable Metrics/MethodLength
def check_search_criteria(search_criteria)
if search_criteria[:country_code].nil?
raise ArgumentError, "country_code is a required search criteria"
end
unless only_registration_number_or_company_name_provided?(search_criteria)
raise ArgumentError, "registration_number or company_name (not both) are " \
"required search criteria"
end
- if search_criteria[:city] && search_criteria[:country_code] != 'DE'
+ if search_criteria[:city] && search_criteria[:country_code] != "DE"
raise ArgumentError, "city is only supported for German searches"
end
- if search_criteria[:postal_code] && search_criteria[:country_code] != 'DE'
+ if search_criteria[:postal_code] && search_criteria[:country_code] != "DE"
raise ArgumentError, "Postal code is only supported for German searches"
end
end
+ # rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity
def only_registration_number_or_company_name_provided?(search_criteria)
search_criteria[:registration_number].nil? ^ search_criteria[:company_name].nil?
end