node-511
Version:
Lightweight node.js wrapper for the 511.org real time driving times and transit departure APIs
43 lines (30 loc) • 1.38 kB
text/coffeescript
url = require 'url'
class Client
: 'http://511.org/developer-resources_api-security-token_rtt.asp'
constructor: (options = {}) ->
= options.token ? throw new Error "No token specified - please see: #{ Client.tokenRegistrationURL }"
= options.host ? 'http://services.my511.org'
=
GetAgencies: '/Transit2.0/GetAgencies.aspx'
GetRoutesForAgencies: '/Transit2.0/GetRoutesForAgencies.aspx'
GetRoutesForAgency: '/Transit2.0/GetRoutesForAgency.aspx'
GetStopsForRoute: '/Transit2.0/GetStopsForRoute.aspx'
GetStopsForRoutes: '/Transit2.0/GetStopsForRoutes.aspx'
GetNextDeparturesByStopName: '/Transit2.0/GetNextDeparturesByStopName.aspx'
= []
for service, path of
try
urlObj = url.parse
urlObj.pathname = path
_service = new (require "./apis/#{ service }") url.format urlObj
bindInvoke = (s) ->
(callback, options = {}) ->
callback ?= () ->
options.token =
s.invoke options, callback
this[service] = bindInvoke _service
catch error
console.warn "Error loading service: #{ service }"
this[service] = (callback = () ->) ->
callback new Error "Service #{ service } was not loaded correctly"
module.exports = Client