Sha256: 59678170208943d427e628c98ae630221e2275d4e86ca1128ac05976895b75a1

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'creditsafe/namespace'

module Creditsafe
  module Request
    class FindCompany
      def initialize(search_criteria)
        check_search_criteria(search_criteria)

        @country_code = search_criteria[:country_code]
        @registration_number = search_criteria[:registration_number]
        @city = search_criteria[:city]
      end

      def message
        search_criteria = {
          "#{Creditsafe::Namespace::DAT}:RegistrationNumber" =>
            registration_number
        }

        unless city.nil?
          search_criteria["#{Creditsafe::Namespace::DAT}:Address"] =
            { "#{Creditsafe::Namespace::DAT}:City" => city }
        end

        {
          "#{Creditsafe::Namespace::OPER}:countries" => {
            "#{Creditsafe::Namespace::CRED}:CountryCode" => country_code
          },
          "#{Creditsafe::Namespace::OPER}:searchCriteria" => search_criteria
        }
      end

      private

      attr_reader :country_code, :registration_number, :city

      def check_search_criteria(search_criteria)
        if search_criteria[:country_code].nil?
          raise ArgumentError, "country_code is a required search criteria"
        end

        if search_criteria[:registration_number].nil?
          raise ArgumentError,
                "registration_number is a required search criteria"
        end

        if search_criteria[:city] && search_criteria[:country_code] != 'DE'
          raise ArgumentError, "city is only supported for German searches"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
creditsafe-0.3.1 lib/creditsafe/request/find_company.rb