Class: SmartyStreets::USReverseGeo::Client
- Inherits:
-
Object
- Object
- SmartyStreets::USReverseGeo::Client
- Defined in:
- lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb
Overview
It is recommended to instantiate this class using ClientBuilder.build_us_reverse_geo_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 Reverse Geo API and stores the result in the Lookup’s response field.
Constructor Details
#initialize(sender, serializer) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb', line 8 def initialize(sender, serializer) @sender = sender @serializer = serializer end |
Instance Method Details
#add_parameter(request, key, value) ⇒ Object
34 35 36 |
# File 'lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb', line 34 def add_parameter(request, key, value) request.parameters[key] = value unless value.nil? or value.empty? end |
#build_request(lookup) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb', line 24 def build_request(lookup) request = SmartyStreets::Request.new add_parameter(request, 'latitude', lookup.latitude) add_parameter(request, 'longitude', lookup.longitude) add_parameter(request, 'source', lookup.source) request end |
#send(lookup) ⇒ Object
Sends a Lookup object to the US Reverse Geo API and stores the result in the Lookup’s response field.
14 15 16 17 18 19 20 21 22 |
# File 'lib/smartystreets_ruby_sdk/us_reverse_geo/client.rb', line 14 def send(lookup) request = build_request(lookup) response = @sender.send(request) raise response.error if response.error lookup.response = Response.new(@serializer.deserialize(response.payload)) end |