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.
19 20 21 22 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 19 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#__send(lookup) ⇒ Object
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 155 156 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 94 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 == "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
158 159 160 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 158 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
84 85 86 87 88 89 90 91 92 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 84 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 44 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
24 25 26 27 28 29 30 31 32 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 24 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
34 35 36 37 38 39 40 41 42 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 34 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_risk_lookup(lookup) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 54 def send_risk_lookup(lookup) if (lookup.instance_of? String) __send(USEnrichment::Risk::Lookup.new(lookup)) 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
74 75 76 77 78 79 80 81 82 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 74 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
64 65 66 67 68 69 70 71 72 |
# File 'lib/smartystreets_ruby_sdk/us_enrichment/client.rb', line 64 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 |