Module: Onebusaway

Defined in:
lib/onebusaway.rb

Defined Under Namespace

Classes: Agency, ArrivalAndDeparture, Base, EncodedPolyline, Route, Stop

Constant Summary collapse

API_BASE =
"http://api.onebusaway.org/api/where/"

Class Method Summary collapse

Class Method Details

.api_key=(key) ⇒ Object



6
7
8
# File 'lib/onebusaway.rb', line 6

def api_key=(key)
  @api_key = key
end

.arrivals_and_departures_for_stop(params) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/onebusaway.rb', line 57

def arrivals_and_departures_for_stop(params)
  raise if params[:id].nil?

  doc = request('arrivals-and-departures-for-stop', params)
  arrivals = []
  doc.elements.each("arrivalsAndDepartures/arrivalAndDeparture") do |arrival_el|
    arrivals << ArrivalAndDeparture.from_xml(arrival_el)
  end
  arrivals
end

.route_by_id(params) ⇒ Object



17
18
19
20
21
22
# File 'lib/onebusaway.rb', line 17

def route_by_id(params)
  raise if params[:id].nil?

  xml = request('route', params)
  route = Route.from_xml(xml)
end

.routes_for_location(params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/onebusaway.rb', line 35

def routes_for_location(params)
  raise if params[:lat].nil? || params[:lon].nil?

  doc = request('routes-for-location', params)
  routes = []
  doc.elements.each("routes/route") do |route_el|
    routes << Route.from_xml(route_el)
  end
  routes
end

.stop_by_id(params) ⇒ Object



10
11
12
13
14
15
# File 'lib/onebusaway.rb', line 10

def stop_by_id(params)
  raise if params[:id].nil?

  xml = request('stop', params)
  stop = Stop.from_xml(xml)
end

.stops_for_location(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/onebusaway.rb', line 24

def stops_for_location(params)
  raise if params[:lat].nil? || params[:lon].nil?

  doc = request('stops-for-location', params)
  stops = []
  doc.elements.each("stops/stop") do |stop_el|
    stops << Stop.from_xml(stop_el)
  end
  stops
end

.stops_for_route(params) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/onebusaway.rb', line 46

def stops_for_route(params)
  raise if params[:id].nil?

  doc = request('stops-for-route', params)
  stops = []
  doc.elements.each("stops/stop") do |stop_el|
    stops << Stop.from_xml(stop_el)
  end
  stops
end