Class: SmartyStreets::USEnrichment::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/smartystreets_ruby_sdk/us_enrichment/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(sender, serializer) ⇒ Client

Returns a new instance of Client.



15
16
17
18
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 15

def initialize(sender, serializer)
    @sender = sender
    @serializer = serializer
end

Instance Method Details

#send_business_detail_lookup(lookup) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 70

def send_business_detail_lookup(lookup)
    if (lookup.instance_of? String)
        lookup = USEnrichment::BusinessDetailLookup.new(lookup)
    end
    unless lookup.instance_of? USEnrichment::BusinessDetailLookup
        raise SmartyError.new("Business detail lookup requires a non-empty 'business_id'")
    end
    if blank?(lookup.business_id)
        raise SmartyError.new("Business detail lookup requires a non-empty 'business_id'")
    end

    smarty_request = Request.new
    smarty_request.url_components = '/business/' + encode_path_segment(lookup.business_id)
    apply_common_request_fields(smarty_request, lookup)

    response = @sender.send(smarty_request)
    capture_response_etag(response, lookup)
    results = @serializer.deserialize(response.payload)

    results = [] if results.nil?
    raise response.error if response.error

    if results.length > 1
        raise SmartyError.new("Business detail response contained #{results.length} results; expected at most 1")
    end

    if results.empty?
        lookup.result = nil
    else
        lookup.result = USEnrichment::Business::Detail::Response.new(results[0])
    end
    lookup.result
end

#send_business_lookup(lookup) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 60

def send_business_lookup(lookup)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup,'business'))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = 'business'
        lookup.data_sub_set = nil
        __send(lookup)
    end
end

#send_generic_lookup(lookup, data_set, data_sub_set = nil) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 104

def send_generic_lookup(lookup, data_set, data_sub_set = nil)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup, data_set, data_sub_set))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = data_set
        lookup.data_sub_set = data_sub_set
        __send(lookup)
    end
end

#send_geo_reference_lookup(lookup) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 30

def send_geo_reference_lookup(lookup)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup,'geo-reference'))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = 'geo-reference'
        lookup.data_sub_set = nil
        __send(lookup)
    end
end

#send_property_principal_lookup(lookup) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 20

def send_property_principal_lookup(lookup)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup,'property','principal'))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = 'property'
        lookup.data_sub_set = 'principal'
        __send(lookup)
    end
end

#send_secondary_count_lookup(lookup) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 50

def send_secondary_count_lookup(lookup)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup,'secondary','count'))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = 'secondary'
        lookup.data_sub_set = 'count'
        __send(lookup)
    end
end

#send_secondary_lookup(lookup) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 40

def send_secondary_lookup(lookup)
    if (lookup.instance_of? String)
        __send(USEnrichment::Lookup.new(lookup,'secondary'))
    elsif (lookup.instance_of? USEnrichment::Lookup)
        lookup.data_set = 'secondary'
        lookup.data_sub_set = nil
        __send(lookup)
    end
end