Class: SmartyStreets::USExtract::Client
- Inherits:
-
Object
- Object
- SmartyStreets::USExtract::Client
- Defined in:
- lib/smartystreets_ruby_sdk/us_extract/client.rb
Overview
It is recommended to instantiate this class using ClientBuilder.build_us_extract_api_client()
Instance Method Summary collapse
- #add_parameter(request, key, value) ⇒ Object
- #build_request(lookup) ⇒ Object
-
#initialize(sender, serializer) ⇒ Client
constructor
A new instance of Client.
-
#send(lookup) ⇒ Object
Sends a Lookup object to the US Extract Code API and stores the result in the Lookup’s result field.
Constructor Details
#initialize(sender, serializer) ⇒ Client
Returns a new instance of Client.
9 10 11 12 |
# File 'lib/smartystreets_ruby_sdk/us_extract/client.rb', line 9 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#add_parameter(request, key, value) ⇒ Object
41 42 43 44 45 |
# File 'lib/smartystreets_ruby_sdk/us_extract/client.rb', line 41 def add_parameter(request, key, value) if value and not value.empty? request.parameters[key] = value end end |
#build_request(lookup) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smartystreets_ruby_sdk/us_extract/client.rb', line 28 def build_request(lookup) request = Request.new request.content_type = 'text/plain' request.payload = lookup.text add_parameter(request, 'html', lookup.html.to_s) add_parameter(request, 'aggressive', lookup.aggressive.to_s) add_parameter(request, 'addr_line_breaks', lookup.addresses_have_line_breaks.to_s) add_parameter(request, 'addr_per_line', lookup.addresses_per_line.to_s) request end |
#send(lookup) ⇒ Object
Sends a Lookup object to the US Extract Code API and stores the result in the Lookup’s result field. It also returns the result directly.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/smartystreets_ruby_sdk/us_extract/client.rb', line 16 def send(lookup) if lookup.nil? or lookup.text.nil? or not lookup.text.is_a? String or lookup.text.empty? raise SmartyError, 'Client.send() requires a Lookup with the "text" field set' end request = build_request(lookup) response = @sender.send(request) result = USExtract::Result.new(@serializer.deserialize(response.payload)) lookup.result = result end |