class OSRM::Client
:nodoc
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(options = {})
click to toggle source
@return [OSRM::Client]
# File lib/osrm_api/client.rb, line 25 def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) end
Public Instance Methods
distance(*locations) { |request| ... }
click to toggle source
Return casting <Response::DistanceObject> @param [Array] locations @return [Response::DistanceObject]
# File lib/osrm_api/client.rb, line 53 def distance(*locations) request = Request::DistanceRequest.new(*locations) yield request if block_given? Response::DistanceObject.new execute request end
locate(location) { |request| ... }
click to toggle source
@return [Response::LocateObject]
# File lib/osrm_api/client.rb, line 30 def locate(location) request = Request::LocateRequest.new(location) request = yield request if block_given? Response::LocateObject.new execute request end
nearest(location) { |request| ... }
click to toggle source
@return [Response::NearestObject]
# File lib/osrm_api/client.rb, line 44 def nearest(location) request = Request::NearestRequest.new(location) yield request if block_given? Response::NearestObject.new execute request end
route(*locations) { |request| ... }
click to toggle source
@return [Response::RouteObject]
# File lib/osrm_api/client.rb, line 37 def route(*locations) request = Request::RouteRequest.new(*locations) yield request if block_given? Response::RouteObject.new execute request end
Private Instance Methods
execute(request)
click to toggle source
Method performs given request and returns body response @param [OSRM::Request::BaseRequest] request
# File lib/osrm_api/client.rb, line 63 def execute(request) uri = request.build_uri @options[:host], @options[:port] res = Net::HTTP.get_response uri JSON.parse(res.body) end