module KVVLiveAPI
Main module for accessing the KVV live API. All API functions can be called directly on the class object.
Constants
- API_BASE
Base URL for all API calls
- API_KEY
Publicly available key needed to access the API
- VERSION
Currently installed version of the Gem
Public Class Methods
depatures_by_route(route, stop_id)
click to toggle source
Retrieves a list of upcoming depatures for a specified rouute at a specified Stop
ID
-
route
- Route for which upcoming depatures should be retrieved -
stop_id
- ID of theStop
for which upcoming depatures should be retrieved
# File lib/kvvliveapi.rb, line 54 def depatures_by_route(route, stop_id) departures('departures/byroute/' + CGI.escape(route) + '/' + CGI.escape(stop_id)) end
depatures_by_stop(stop_id)
click to toggle source
stops_by_coordinates(lat, lon)
click to toggle source
Retrieves a list of stops close to a given set of coordinates
-
lat
- latitude -
long
- longitude
# File lib/kvvliveapi.rb, line 29 def stops_by_coordinates(lat, lon) stops('stops/bylatlon/' + ('%.6f' % lat) + '/' + ('%.6f' % lon)) end
stops_by_id(stop_id)
click to toggle source
Retrieves a single stop object by its ID
-
stop_id
- ID of theStop
to retrieve
# File lib/kvvliveapi.rb, line 36 def stops_by_id(stop_id) [Stop.from_json(query('stops/bystop/' + CGI.escape(stop_id)))] end
stops_by_name(name)
click to toggle source
Retrieves a list of stops whose names match a given string
-
name
- name or fragment of the name of theStop
that is searched
# File lib/kvvliveapi.rb, line 21 def stops_by_name(name) stops('stops/byname/' + CGI.escape(name)) end
Private Class Methods
departures(api_path)
click to toggle source
# File lib/kvvliveapi.rb, line 66 def departures(api_path) query(api_path)['departures'].map do |stop| Departure.from_json(stop) end end
query(path, params = {})
click to toggle source
# File lib/kvvliveapi.rb, line 72 def query(path, params = {}) params.merge!({ key: API_KEY }) uri = URI.parse(API_BASE + path).tap do |u| u.query = URI.encode_www_form(params) end response = Faraday.get(uri) JSON.parse!(response.body) end
stops(api_path)
click to toggle source
# File lib/kvvliveapi.rb, line 60 def stops(api_path) query(api_path)['stops'].map do |stop| Stop.from_json(stop) end end