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_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.
12 13 14 15 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 12 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#__send(lookup) ⇒ Object
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 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 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 77 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 == "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
142 143 144 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 142 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 67 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
27 28 29 30 31 32 33 34 35 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 27 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
17 18 19 20 21 22 23 24 25 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 17 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 37 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
57 58 59 60 61 62 63 64 65 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 57 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
47 48 49 50 51 52 53 54 55 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 47 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 |