Class: GeocoderClient
Overview
Class GeocoderClient represents server request of geocoding API (calculate the location to use for a posting based on location-specific details within the posting such as a street address or a latitude and longitude value).
Its methods are used to query API with appropriate requests: geocode(requests) - returns array of responses
Example:
client = GeocoderClient.new
request = GeocoderRequest.new
request.latitude = '37.77493'
request.longitude = '-122.41942'
response = client.geocode(request)
response.first.code # => "CAZ"
response.first.latitude # => 39.77493
response.first.longitude # => -122.41942
Constant Summary
Constants inherited from Client
Client::DEFAULT_API_PORT, Client::DEFAULT_URL, Client::TIMEOUT
Instance Method Summary collapse
-
#geocode(geocoder_requests) ⇒ Object
Method geocode sends geocode request to Geocode API.
Methods inherited from Client
#execute_get, #execute_post, #initialize
Constructor Details
This class inherits a constructor from Client
Instance Method Details
#geocode(geocoder_requests) ⇒ Object
Method geocode sends geocode request to Geocode API. Takes array of GeocoderRequest objects as requests
parameter.
Examples:
request = GeocoderRequest.new
client.geocode(request) # => [GeocoderResponse]
requests = [GeocoderRequest.new, GeocoderRequest.new]
client.geocode(requests) # => [GeocoderResponse, GeocoderResponse]
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/client/geocoder_client.rb', line 34 def geocode(geocoder_requests) geocoder_requests = [geocoder_requests] unless geocoder_requests.is_a? Array params = "data=[" params << geocoder_requests.collect{|request| "#{request.to_params}"}.join(',') params << "]" p params response = execute_post('geocoder/geocode', params) p response p decode(response) GeocoderResponse.from_array(decode(response)) end |