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.



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

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

Instance Method Details

#send_business_detail_lookup(lookup) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 81

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



71
72
73
74
75
76
77
78
79
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 71

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



115
116
117
118
119
120
121
122
123
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 115

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



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

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



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

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_risk_lookup(lookup) ⇒ Object



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

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

#send_secondary_count_lookup(lookup) ⇒ Object



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

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



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

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