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_secondary_count_lookup(lookup) ⇒ Object
- #send_secondary_lookup(lookup) ⇒ Object
Constructor Details
#initialize(sender, serializer) ⇒ Client
Returns a new instance of Client.
17 18 19 20 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 17 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#__send(lookup) ⇒ Object
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 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 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 82 def __send(lookup) smarty_request = Request.new return if lookup.nil? if (!lookup.etag.nil?) smarty_request.header["ETAG"] = lookup.etag 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 == "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
143 144 145 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 143 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
72 73 74 75 76 77 78 79 80 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 72 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
42 43 44 45 46 47 48 49 50 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 42 def send_geo_reference_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::GeoReference::Lookup.new(lookup)) 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
22 23 24 25 26 27 28 29 30 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 22 def send_property_financial_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Property::Financial::Lookup.new(lookup)) 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
32 33 34 35 36 37 38 39 40 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 32 def send_property_principal_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Property::Principal::Lookup.new(lookup)) 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
62 63 64 65 66 67 68 69 70 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 62 def send_secondary_count_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Secondary::Count::Lookup.new(lookup)) elsif (lookup.instance_of? USEnrichment::Lookup) lookup.data_set = 'secondary' lookup.data_sub_set = 'count' __send(lookup) end end |
#send_secondary_lookup(lookup) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 52 def send_secondary_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Secondary::Lookup.new(lookup)) elsif (lookup.instance_of? USEnrichment::Lookup) lookup.data_set = 'secondary' lookup.data_sub_set = nil __send(lookup) end end |