Class: TravelTimeAPI
- Inherits:
-
Object
- Object
- TravelTimeAPI
- Defined in:
- lib/traveltime_api.rb
Overview
Class for using TravelTime API service. Learn more about TravelTime at www.traveltimeapp.com
## Defined types ##
-
TransportationMode - string with one of following values:
“walking”, “driving”, “walking_train”, “walking_bus”, “public_transport”
-
EdgeType - describes type of the edge. String with one of following values:
“car”, “walk”, “train”, “bus”, “cable_car”, “plane”, “ship”
## Thrown errors ##
Each method that does a call to the server can raise TravelTimeAPI::BadRequest or TravelTimeAPI::ServerError errors.
Defined Under Namespace
Classes: BadRequest, NoData, RoutesResult, ServerError, TimeFilterResult, TimeMapResult
Constant Summary collapse
- DEFAULT_URL =
"http://api.traveltimeapp.com"
Instance Method Summary collapse
-
#initialize(api_key, url = DEFAULT_URL) ⇒ TravelTimeAPI
constructor
Initializes API.
-
#routes(start_time, travel_time, mode, origin, points) ⇒ TravelTimeAPI::RoutesResult
Takes input parameters and returns routes to each of the points within travel_time.
-
#time_filter(start_time, travel_time, mode, origin, points, properties = [:time]) ⇒ TravelTimeAPI::TimeFilterResult
Takes input parameters and returns how long does it take to reach each point in chosen mode of transportation (in seconds).
-
#time_map(start_time, travel_time, mode, origin, smooth) ⇒ TravelTimeAPI::TimeMapResult
Takes input parameters and returns polylines for each cluster that you can reach by given time.
Constructor Details
#initialize(api_key, url = DEFAULT_URL) ⇒ TravelTimeAPI
Initializes API. You need to specify your API key here.
93 94 95 96 |
# File 'lib/traveltime_api.rb', line 93 def initialize(api_key, url=DEFAULT_URL) @api_key = api_key @url = url end |
Instance Method Details
#routes(start_time, travel_time, mode, origin, points) ⇒ TravelTimeAPI::RoutesResult
Takes input parameters and returns routes to each of the points within travel_time.
Input parameters are the same as #travel_time.
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/traveltime_api.rb', line 154 def routes(start_time, travel_time, mode, origin, points) request = { :start_time => format_time(start_time), :travel_time => travel_time, :mode => mode, :origin => origin, :points => points } response = post("/v2/routes", request) RoutesResult.new(response) end |
#time_filter(start_time, travel_time, mode, origin, points, properties = [:time]) ⇒ TravelTimeAPI::TimeFilterResult
Takes input parameters and returns how long does it take to reach each point in chosen mode of transportation (in seconds).
Points whose travel times which exceed travel_time are not included in the result.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/traveltime_api.rb', line 113 def time_filter(start_time, travel_time, mode, origin, points, properties=[:time]) request = { :start_time => format_time(start_time), :travel_time => travel_time, :mode => mode, :origin => origin, :points => points, :properties => properties } response = post("/v2/time_filter", request) TimeFilterResult.new(response["times"], response["accuracy"].to_sym) end |
#time_map(start_time, travel_time, mode, origin, smooth) ⇒ TravelTimeAPI::TimeMapResult
Takes input parameters and returns polylines for each cluster that you can reach by given time.
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/traveltime_api.rb', line 136 def time_map(start_time, travel_time, mode, origin, smooth) request = { :start_time => format_time(start_time), :travel_time => travel_time, :mode => mode, :origin => origin, :smooth => smooth } response = post("/v2/time_map", request) TimeMapResult.new(response["shape"], response["accuracy"].to_sym) end |