Class: USZipcode::Client
- Inherits:
-
Object
- Object
- USZipcode::Client
- Defined in:
- lib/smartystreets_ruby_sdk/us_zipcode/client.rb
Instance Method Summary collapse
- #assign_results_to_lookups(batch, results) ⇒ Object
-
#initialize(sender, serializer) ⇒ Client
constructor
A new instance of Client.
- #remap_keys(obj) ⇒ Object
- #send_batch(batch) ⇒ Object
- #send_lookup(lookup) ⇒ Object
Constructor Details
#initialize(sender, serializer) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/smartystreets_ruby_sdk/us_zipcode/client.rb', line 7 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#assign_results_to_lookups(batch, results) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/smartystreets_ruby_sdk/us_zipcode/client.rb', line 35 def assign_results_to_lookups(batch, results) results.each do |raw_result| result = Result.new(raw_result) batch[result.input_index].result = result end end |
#remap_keys(obj) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/smartystreets_ruby_sdk/us_zipcode/client.rb', line 42 def remap_keys(obj) converted_obj = [] obj.each do |lookup| converted_lookup = {} converted_lookup['city'] = lookup.city converted_lookup['state'] = lookup.state converted_lookup['zipcode'] = lookup.zipcode converted_obj.push(converted_lookup) end converted_obj end |
#send_batch(batch) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smartystreets_ruby_sdk/us_zipcode/client.rb', line 18 def send_batch(batch) smarty_request = Request.new return if batch.size == 0 converted_lookups = remap_keys(batch.all_lookups) smarty_request.payload = @serializer.serialize(converted_lookups) response = @sender.send(smarty_request) raise response.error if response.error results = @serializer.deserialize(response.payload) results = [] if results == nil assign_results_to_lookups(batch, results) end |
#send_lookup(lookup) ⇒ Object
12 13 14 15 16 |
# File 'lib/smartystreets_ruby_sdk/us_zipcode/client.rb', line 12 def send_lookup(lookup) batch = Batch.new batch.add(lookup) send_batch(batch) end |