Class: Onebusaway
- Inherits:
-
Object
- Object
- Onebusaway
- Defined in:
- lib/onebusaway_updated.rb
Instance Attribute Summary collapse
-
#api_base ⇒ Object
Returns the value of attribute api_base.
Instance Method Summary collapse
- #arrivals_and_departures_for_stop(agency_id, stop_id) ⇒ Object
-
#initialize(api_key) ⇒ Onebusaway
constructor
A new instance of Onebusaway.
- #make_id(agency_id, sub_id) ⇒ Object
- #route_by_id(agency_id, route_id) ⇒ Object
- #routes_for_location(lat, lon) ⇒ Object
- #stop_by_id(agency_id, stop_id) ⇒ Object
- #stops_for_location(lat, lon) ⇒ Object
- #stops_for_route(agency_id, route_id) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Onebusaway
Returns a new instance of Onebusaway.
8 9 10 11 |
# File 'lib/onebusaway_updated.rb', line 8 def initialize api_key @api_key = api_key @api_base = URI 'http://api.onebusaway.org/api/where/' end |
Instance Attribute Details
#api_base ⇒ Object
Returns the value of attribute api_base.
6 7 8 |
# File 'lib/onebusaway_updated.rb', line 6 def api_base @api_base end |
Instance Method Details
#arrivals_and_departures_for_stop(agency_id, stop_id) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/onebusaway_updated.rb', line 57 def arrivals_and_departures_for_stop agency_id, stop_id result = request 'arrivals-and-departures-for-stop', id: make_id(agency_id, stop_id) result['arrivalsAndDepartures'].map do |arr_dep| ArrivalAndDeparture.new arr_dep end end |
#make_id(agency_id, sub_id) ⇒ Object
13 14 15 |
# File 'lib/onebusaway_updated.rb', line 13 def make_id agency_id, sub_id "#{agency_id}_#{sub_id}" end |
#route_by_id(agency_id, route_id) ⇒ Object
27 28 29 30 31 |
# File 'lib/onebusaway_updated.rb', line 27 def route_by_id agency_id, route_id result = request 'route', id: make_id(agency_id, route_id) Route.new result end |
#routes_for_location(lat, lon) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/onebusaway_updated.rb', line 41 def routes_for_location lat, lon result = request 'routes-for-location', lat: lat, lon: lon result['routes'].map do |route| Route.new route end end |
#stop_by_id(agency_id, stop_id) ⇒ Object
21 22 23 24 25 |
# File 'lib/onebusaway_updated.rb', line 21 def stop_by_id agency_id, stop_id result = request 'stop', id: make_id(agency_id, stop_id) Stop.new result end |
#stops_for_location(lat, lon) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/onebusaway_updated.rb', line 33 def stops_for_location lat, lon result = request 'stops-for-location', lat: lat, lon: lon result['stops'].map do |stop| Stop.new stop end end |
#stops_for_route(agency_id, route_id) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/onebusaway_updated.rb', line 49 def stops_for_route agency_id, route_id result = request 'stops-for-route', id: make_id(agency_id, route_id) result['stops'].map do |stop| Stop.new stop end end |