Comparing version 0.1.1 to 0.1.2
33
index.js
@@ -18,3 +18,3 @@ var urlFormat = require('url').format; | ||
function createSignature(url, args) { | ||
function createSignature(key, url, args) { | ||
return crypto.createHmac('sha1', key) | ||
@@ -28,2 +28,3 @@ .update(urlFormat({pathname: '/v2' + url, query: args})) | ||
this.key = opts.key; | ||
this._activeReqs = 0; | ||
} | ||
@@ -36,4 +37,6 @@ | ||
query.for_utc = utc.toISOString(); | ||
var signature = createSignature(url, query); | ||
var signature = createSignature(this.key, url, query); | ||
query.signature = signature; | ||
this._activeReqs++; | ||
var ptv = this; | ||
request({ | ||
@@ -43,9 +46,10 @@ url: endpoint + '/v2' + url, | ||
}, function(error, response, body) { | ||
ptv._activeReqs--; | ||
if (!error && response.statusCode == 200) { | ||
try { | ||
result = JSON.parse(body); | ||
cb(null, result); | ||
} catch(e) { | ||
cb(e); | ||
return cb(e); | ||
} | ||
cb(null, result); | ||
} else { | ||
@@ -67,3 +71,6 @@ if (error) | ||
util.format('/nearme/latitude/%d/longitude/%d', latitude, longitude), | ||
cb | ||
function(err, res) { | ||
if (err) return cb(err); | ||
return cb(null, res.map(function(s) { return s.result; })); | ||
} | ||
); | ||
@@ -96,2 +103,4 @@ }; | ||
PTV.modeName = ['train', 'tram', 'bus', 'vline', 'nightrider']; | ||
PTV.prototype.broadNextDepartures = function(mode, stop, limit, date, cb) { | ||
@@ -106,2 +115,4 @@ if (!date) | ||
if (err) return cb(err); | ||
//if (!res || !res.values) | ||
// console.log(res); | ||
cb(null, res.values); | ||
@@ -120,3 +131,8 @@ } | ||
date, | ||
cb | ||
function(err, res) { | ||
if (err) return cb(err); | ||
//if (!res || !res.values) | ||
// console.log(res); | ||
cb(null, res.values); | ||
} | ||
); | ||
@@ -132,3 +148,6 @@ }; | ||
date, | ||
cb | ||
function(err, res) { | ||
if (err) return cb(err); | ||
cb(null, res.values); | ||
} | ||
); | ||
@@ -135,0 +154,0 @@ }; |
{ | ||
"name": "ptv", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Public Transport Victoria API client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6856
143