Class: IRail::API::NMBS
- Inherits:
-
Object
- Object
- IRail::API::NMBS
- Defined in:
- lib/ruby-irail/packages/nmbs/api.rb
Constant Summary collapse
- API_URL =
"http://api.irail.be"
- STATIONS_URI =
"stations/"
- CONNECTIONS_URI =
"connections/"
- VEHICLE_URI =
"vehicle/"
- DEPARTURES_URI =
"liveboard/"
- ARRIVALS_URI =
"liveboard/"
Instance Method Summary collapse
- #arrivals(station_id, options = {}) ⇒ Object
- #call_api(url, options = {}) ⇒ Object
- #connections(origin_station, destination_station, options = {}) ⇒ Object
- #departures(station_id, options = {}) ⇒ Object
- #get_resource(resource, options) ⇒ Object
- #stations(options = {}) ⇒ Object
- #vehicle(vehicle_id, options = {}) ⇒ Object
Instance Method Details
#arrivals(station_id, options = {}) ⇒ Object
29 30 31 32 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 29 def arrivals(station_id, = {}) = build_arrivals_option_hash(station_id, ) get_resource(:arrivals, ) end |
#call_api(url, options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 41 def call_api(url, = {}) = () IRail::Request.get(url, ) end |
#connections(origin_station, destination_station, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 14 def connections(origin_station, destination_station, = {}) = build_connections_option_hash(origin_station, destination_station, ) get_resource(:connections, ) end |
#departures(station_id, options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 24 def departures(station_id, = {}) = build_departures_option_hash(station_id, ) get_resource(:departures, ) end |
#get_resource(resource, options) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 34 def get_resource(resource, ) uri = IRail::API::NMBS.const_get("#{resource.upcase}_URI") url = build_url(uri) xml = call_api(url, ) IRail::NMBS::XMLParser.send("parse_#{resource}", xml) end |
#stations(options = {}) ⇒ Object
10 11 12 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 10 def stations( = {}) get_resource(:stations, ) end |
#vehicle(vehicle_id, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 19 def vehicle(vehicle_id, = {}) = build_vehicle_option_hash(vehicle_id, ) get_resource(:vehicle, ) end |