Class: SmartyStreets::USEnrichment::Client
- Inherits:
-
Object
- Object
- SmartyStreets::USEnrichment::Client
- Defined in:
- lib/smartystreets_ruby_sdk/us_enrichment/client.rb
Instance Method Summary collapse
- #__send(lookup) ⇒ Object
- #add_parameter(request, key, value) ⇒ Object
-
#initialize(sender, serializer) ⇒ Client
constructor
A new instance of Client.
- #send_generic_lookup(lookup, data_set, data_sub_set = nil) ⇒ Object
- #send_geo_reference_lookup(lookup) ⇒ Object
- #send_property_financial_lookup(lookup) ⇒ Object
- #send_property_principal_lookup(lookup) ⇒ Object
- #send_risk_lookup(lookup) ⇒ Object
- #send_secondary_count_lookup(lookup) ⇒ Object
- #send_secondary_lookup(lookup) ⇒ Object
Constructor Details
#initialize(sender, serializer) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 13 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#__send(lookup) ⇒ Object
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 88 def __send(lookup) smarty_request = Request.new return if lookup.nil? if (!lookup.etag.nil?) smarty_request.header["ETAG"] = lookup.etag end if (!lookup.features.nil?) add_parameter(smarty_request, 'features', lookup.features) end if (lookup.smarty_key.nil?) if (lookup.data_sub_set.nil?) smarty_request.url_components = '/search/' + lookup.data_set else smarty_request.url_components = '/search/' + lookup.data_set + '/' + lookup.data_sub_set end add_parameter(smarty_request, 'freeform', lookup.freeform) add_parameter(smarty_request, 'street', lookup.street) add_parameter(smarty_request, 'city', lookup.city) add_parameter(smarty_request, 'state', lookup.state) add_parameter(smarty_request, 'zipcode', lookup.zipcode) else if (lookup.data_sub_set.nil?) smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set else smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set end end for key in lookup.custom_param_hash.keys do add_parameter(smarty_request, key, lookup.custom_param_hash[key]) end 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, response.header['etag']) end if lookup.data_sub_set == "principal" result = USEnrichment::Property::Principal::Response.new(raw_result, response.header['etag']) end if lookup.data_set == "geo-reference" result = USEnrichment::GeoReference::Response.new(raw_result, response.header['etag']) end if lookup.data_set == "risk" result = USEnrichment::Risk::Response.new(raw_result, response.header['etag']) end if lookup.data_set == "secondary" if lookup.data_sub_set == "count" result = USEnrichment::Secondary::Count::Response.new(raw_result, response.header['etag']) elsif lookup.data_sub_set.nil? result = USEnrichment::Secondary::Response.new(raw_result, response.header['etag']) end end output << result end output end |
#add_parameter(request, key, value) ⇒ Object
156 157 158 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 156 def add_parameter(request, key, value) request.parameters[key] = value unless value.nil? or value.empty? end |
#send_generic_lookup(lookup, data_set, data_sub_set = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 78 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
38 39 40 41 42 43 44 45 46 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 38 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_financial_lookup(lookup) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 18 def send_property_financial_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Lookup.new(lookup,'property','financial')) elsif (lookup.instance_of? USEnrichment::Lookup) lookup.data_set = 'property' lookup.data_sub_set = 'financial' __send(lookup) end end |
#send_property_principal_lookup(lookup) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 28 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 48 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
68 69 70 71 72 73 74 75 76 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 68 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
58 59 60 61 62 63 64 65 66 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 58 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 |