Class: IRail::API::NMBS

Inherits:
Object
  • Object
show all
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

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, options = {})
  options = build_arrivals_option_hash(station_id, options)
  get_resource(:arrivals, options)
end

#call_api(url, options = {}) ⇒ Object



41
42
43
44
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 41

def call_api(url, options = {})
  options = build_query_options_hash(options)
  IRail::Request.get(url, options)
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, options = {})
  options = build_connections_option_hash(origin_station, destination_station, options)
  get_resource(:connections, options)
end

#departures(station_id, options = {}) ⇒ Object



24
25
26
27
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 24

def departures(station_id, options = {})
  options = build_departures_option_hash(station_id, options)
  get_resource(:departures, options)
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, options)
  uri = IRail::API::NMBS.const_get("#{resource.upcase}_URI")
  url = build_url(uri)
  xml = call_api(url, options)
  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(options = {})
  get_resource(:stations, options)
end

#vehicle(vehicle_id, options = {}) ⇒ Object



19
20
21
22
# File 'lib/ruby-irail/packages/nmbs/api.rb', line 19

def vehicle(vehicle_id, options = {})
  options = build_vehicle_option_hash(vehicle_id, options)
  get_resource(:vehicle, options)
end