Sha256: 1ba240d52d29b279e479895e0889f9abc1878df7947a287db2f573905ef0c8ca

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

require_relative "property/financial/response"
require_relative "property/principal/response"
require_relative "property/financial/lookup"
require_relative "property/principal/lookup"
require_relative '../request'

module SmartyStreets
    module USEnrichment
        class Client
            def initialize(sender, serializer)
                @sender = sender
                @serializer = serializer
            end

            def send_property_financial_lookup(smarty_key)
                __send(USEnrichment::Property::Financial::Lookup.new(smarty_key))
            end

            def send_property_principal_lookup(smarty_key)
                __send(USEnrichment::Property::Principal::Lookup.new(smarty_key))
            end

            def __send(lookup)
                smarty_request = Request.new

                return if lookup.nil?

                smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set

                response = @sender.send(smarty_request)
                results = @serializer.deserialize(response.payload)
                
                results = [] if results.nil?
                raise response.error if response.error
                
                output = []
                results.each do |raw_result|
                    result = nil
                    if lookup.data_sub_set == "financial"
                        result = USEnrichment::Property::Financial::Response.new(raw_result)
                    end
                    if lookup.data_sub_set == "principal"
                        result = USEnrichment::Property::Principal::Response.new(raw_result)
                    end
                    output << result
                end
                output
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smartystreets_ruby_sdk-5.18.1 lib/smartystreets_ruby_sdk/us_enrichment/client.rb
smartystreets_ruby_sdk-5.18.0 lib/smartystreets_ruby_sdk/us_enrichment/client.rb
smartystreets_ruby_sdk-5.17.2 lib/smartystreets_ruby_sdk/us_enrichment/client.rb