Class: Loqate::Geocoding::Gateway
- Inherits:
-
Object
- Object
- Loqate::Geocoding::Gateway
- Includes:
- Result::Mixin
- Defined in:
- lib/loqate/geocoding/gateway.rb
Overview
Performs API requests to the geocoding services.
Constant Summary collapse
- DIRECTIONS_ENDPOINT =
'/DistancesAndDirections/Interactive/Directions/v2.00/json3.ws'.freeze
- GEOCODE_ENDPOINT =
'/Geocoding/International/Geocode/v1.10/json3.ws'.freeze
- POSITION_TO_COUNTRY_ENDPOINT =
'/Geocoding/International/PositionToCountry/v1.00/json3.ws'.freeze
- NEAREST_PLACES_ENDPOINT =
'/Geocoding/International/RetrieveNearestPlaces/v1.00/json3.ws'.freeze
Constants included from Result::Mixin
Result::Mixin::Failure, Result::Mixin::Success
Instance Method Summary collapse
-
#directions(options) ⇒ Result
Returns the directions between two or more points.
-
#directions!(options) ⇒ Array<Direction>
Returns the directions between two or more points.
-
#geocode(options) ⇒ Result
Returns the WGS84 latitude and longitude for the given location.
-
#geocode!(options) ⇒ Location
Returns the WGS84 latitude and longitude for the given location.
-
#initialize(client) ⇒ Gateway
constructor
Creates a geocoding gateway.
-
#position_to_country(options) ⇒ Result
Returns the country based on the WGS84 latitude and longitude supplied.
-
#position_to_country!(options) ⇒ Country
Returns the country based on the WGS84 latitude and longitude supplied.
-
#retrieve_nearest_places(options) ⇒ Result
Calculates the nearest places of interest of a given category to a given location.
-
#retrieve_nearest_places!(options) ⇒ Array<Place>
Calculates the nearest places of interest of a given category to a given location.
Methods included from Result::Mixin
#Failure, #Success, #unwrap_result_or_raise
Constructor Details
#initialize(client) ⇒ Gateway
Creates a geocoding gateway.
25 26 27 28 29 |
# File 'lib/loqate/geocoding/gateway.rb', line 25 def initialize(client) @client = client @mapper = Mappers::GenericMapper.new @error_mapper = Mappers::ErrorMapper.new end |
Instance Method Details
#directions(options) ⇒ Result
Returns the directions between two or more points.
84 85 86 87 88 89 90 91 92 |
# File 'lib/loqate/geocoding/gateway.rb', line 84 def directions() %i[start finish way_points].each do |key| [key] = [key].join(',') if [key].respond_to?(:join) end response = client.get(DIRECTIONS_ENDPOINT, ) response.errors? && build_error_from(response.items.first) || build_directions_from(response.items) end |
#directions!(options) ⇒ Array<Direction>
Returns the directions between two or more points.
102 103 104 |
# File 'lib/loqate/geocoding/gateway.rb', line 102 def directions!() unwrap_result_or_raise { directions() } end |
#geocode(options) ⇒ Result
Returns the WGS84 latitude and longitude for the given location. Supports most international locations.
118 119 120 121 122 |
# File 'lib/loqate/geocoding/gateway.rb', line 118 def geocode() response = client.get(GEOCODE_ENDPOINT, ) response.errors? && build_error_from(response.items.first) || build_location_from(response.items.first) end |
#geocode!(options) ⇒ Location
Returns the WGS84 latitude and longitude for the given location. Supports most international locations.
132 133 134 |
# File 'lib/loqate/geocoding/gateway.rb', line 132 def geocode!() unwrap_result_or_raise { geocode() } end |
#position_to_country(options) ⇒ Result
Returns the country based on the WGS84 latitude and longitude supplied. No result is returned if the coordinates are in international waters.
148 149 150 151 152 153 154 |
# File 'lib/loqate/geocoding/gateway.rb', line 148 def position_to_country() response = client.get(POSITION_TO_COUNTRY_ENDPOINT, ) return Success(nil) if response.items.empty? response.errors? && build_error_from(response.items.first) || build_country_from(response.items.first) end |
#position_to_country!(options) ⇒ Country
Returns the country based on the WGS84 latitude and longitude supplied. No result is returned if the coordinates are in international waters.
165 166 167 |
# File 'lib/loqate/geocoding/gateway.rb', line 165 def position_to_country!() unwrap_result_or_raise { position_to_country() } end |
#retrieve_nearest_places(options) ⇒ Result
Calculates the nearest places of interest of a given category to a given location.
197 198 199 200 201 |
# File 'lib/loqate/geocoding/gateway.rb', line 197 def retrieve_nearest_places() response = client.get(NEAREST_PLACES_ENDPOINT, ) response.errors? && build_error_from(response.items.first) || build_places_from(response.items) end |
#retrieve_nearest_places!(options) ⇒ Array<Place>
Calculates the nearest places of interest of a given category to a given location.
211 212 213 |
# File 'lib/loqate/geocoding/gateway.rb', line 211 def retrieve_nearest_places!() unwrap_result_or_raise { retrieve_nearest_places() } end |