class MapboxDirections::Client

Constants

BASE_URL
PATH

Public Class Methods

new(options) click to toggle source
# File lib/mapbox_directions/client.rb, line 11
def initialize(options)
  @options = options
end

Public Instance Methods

directions() click to toggle source
# File lib/mapbox_directions/client.rb, line 15
def directions
  response = Faraday.get(directions_url, parametizer.params_hash)
  parse_response(response)
end

Private Instance Methods

directions_url() click to toggle source
# File lib/mapbox_directions/client.rb, line 35
def directions_url
  "#{BASE_URL}#{PATH}/#{parametizer.profile}/#{parametizer.waypoints}.json"
end
parametizer() click to toggle source
# File lib/mapbox_directions/client.rb, line 39
def parametizer
  @parametizer ||= Parametizer.new(@options)
end
parse_response(response) click to toggle source
# File lib/mapbox_directions/client.rb, line 22
def parse_response(response)
  body = JSON.parse(response.body)

  case response.status
  when 200
    ResponseParser.directions(body)
  when 401
    raise InvalidAccessTokenError
  else
    Response.new(message: body["message"], error: body["error"])
  end
end