citibike
Advanced tools
Comparing version 2.1.0 to 2.1.1
"use strict"; | ||
/*! | ||
* CitibikeNYC API node.js library | ||
* CitibikeNYC API Node.js library | ||
* Author: Kevin Coughlin @kevintcoughlin | ||
@@ -12,3 +12,3 @@ * MIT Licensed | ||
*/ | ||
var http = require('http') | ||
var http = require('http') | ||
, utils = require('./utils') | ||
@@ -22,24 +22,24 @@ | ||
function Citibike( options ) { | ||
if (!(this instanceof Citibike)) | ||
return new Citibike(options); | ||
if (!(this instanceof Citibike)) | ||
return new Citibike(options); | ||
// Default Client Options | ||
this.defaults = { | ||
api_key: null, | ||
// Default Client Options | ||
this.defaults = { | ||
api_key: null, | ||
headers: { | ||
'Accept': '*/*', | ||
'Connection': 'close', | ||
'User-Agent': 'node-Citibike/' | ||
}, | ||
headers: { | ||
'Accept': '*/*', | ||
'Connection': 'close', | ||
'User-Agent': 'node-citibike/' | ||
}, | ||
rest_base: 'http://appservices.citibikenyc.com/', | ||
helmet_url: 'v1/helmet/list', | ||
branch_url: 'v1/branch/list', | ||
stations_url: 'data2/stations.php', | ||
stations_stream_url: 'data2/stations.php?updateOnly=true', // TODO : make param not separate url | ||
rest_base: 'http://appservices.citibikenyc.com/', | ||
helmet_url: 'v1/helmet/list', | ||
branch_url: 'v1/branch/list', | ||
stations_url: 'data2/stations.php', | ||
stations_stream_url: 'data2/stations.php?updateOnly=true', // TODO : make param not separate url | ||
}; | ||
}; | ||
this.options = utils.merge(this.defaults, options); | ||
this.options = utils.merge(this.defaults, options); | ||
} | ||
@@ -50,37 +50,37 @@ | ||
* | ||
* @param {String} url String of the URL to issue the request to. | ||
* @param {Object} params Object containing query string parameters to issue in the Get request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
* @param {String} url String of the URL to issue the request to. | ||
* @param {Object} params Object containing query string parameters to issue in the Get request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
*/ | ||
Citibike.prototype.get = function( url, params, callback ) { | ||
if (typeof params === 'function') { | ||
callback = params; | ||
params = null; | ||
} | ||
if (typeof params === 'function') { | ||
callback = params; | ||
params = null; | ||
} | ||
if ( typeof callback !== 'function' ) { | ||
throw "ERROR: Invalid callback function."; | ||
return this; | ||
} | ||
if ( typeof callback !== 'function' ) { | ||
throw "ERROR: Invalid callback function."; | ||
return this; | ||
} | ||
if (url.charAt(0) == '/') | ||
url = this.options.rest_base + url; | ||
if (url.charAt(0) == '/') | ||
url = this.options.rest_base + url; | ||
// Holds data from HTTP response body | ||
var body = [] | ||
, req = http.get(url, function(res){ | ||
// Holds data from HTTP response body | ||
var body = [] | ||
, req = http.get(url, function(res){ | ||
res.on('data', function (chunk){ | ||
body += chunk; | ||
}); | ||
res.on('data', function (chunk){ | ||
body += chunk; | ||
}); | ||
res.on('end',function(){ | ||
callback(JSON.parse(body)); | ||
}); | ||
}) | ||
req.on('error', function(e) { | ||
console.log("ERROR: " + e.message); | ||
}); | ||
res.on('end',function(){ | ||
callback(JSON.parse(body)); | ||
}); | ||
}) | ||
req.on('error', function(e) { | ||
console.log("ERROR: " + e.message); | ||
}); | ||
return this; | ||
return this; | ||
} | ||
@@ -91,11 +91,11 @@ | ||
* | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
*/ | ||
Citibike.prototype.getStations = function( params, callback ) { | ||
var url = this.options.rest_base + this.options.stations_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
var url = this.options.rest_base + this.options.stations_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
} | ||
@@ -106,11 +106,11 @@ | ||
* | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
*/ | ||
Citibike.prototype.getBranches = function( params, callback ) { | ||
var url = this.options.rest_base + this.options.branch_url; | ||
this.get(url, params, function(data) { | ||
var url = this.options.rest_base + this.options.branch_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
}); | ||
return this; | ||
} | ||
@@ -121,13 +121,13 @@ | ||
* | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
* @param {Object} params Object containing query string parameters to issue in the request. | ||
* @param {Function} callback Callback function that will be called when the processing is done. | ||
*/ | ||
Citibike.prototype.getHelmets = function( params, callback ) { | ||
var url = this.options.rest_base + this.options.helmet_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
var url = this.options.rest_base + this.options.helmet_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
} | ||
module.exports = Citibike; |
@@ -15,11 +15,11 @@ "use strict"; | ||
exports.merge = function(defaults, options) { | ||
defaults = defaults || {}; | ||
if (options && typeof options === 'object') { | ||
var keys = Object.keys(options); | ||
for (var i = 0, len = keys.length; i < len; i++) { | ||
var k = keys[i]; | ||
if (options[k] !== undefined) defaults[k] = options[k]; | ||
} | ||
} | ||
return defaults; | ||
defaults = defaults || {}; | ||
if (options && typeof options === 'object') { | ||
var keys = Object.keys(options); | ||
for (var i = 0, len = keys.length; i < len; i++) { | ||
var k = keys[i]; | ||
if (options[k] !== undefined) defaults[k] = options[k]; | ||
} | ||
} | ||
return defaults; | ||
} | ||
@@ -26,0 +26,0 @@ |
{ | ||
"name": "citibike", | ||
"description": "Citibike API Client Library for node.js", | ||
"description": "Citibike API Client Library for Node.js", | ||
"homepage": "https://github.com/KevinTCoughlin/citibike", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
], | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"author": "Kevin Coughlin <kevintcoughlin@gmail.com>", | ||
@@ -23,3 +23,3 @@ "contributors": [ | ||
}, | ||
"bugs": "https://github.com/LearnBoost/knox/issues", | ||
"bugs": "https://github.com/KevinTCoughlin/citibike/issues", | ||
"scripts": { | ||
@@ -36,5 +36,5 @@ "test": "mocha" | ||
"engines": { | ||
"node": ">= 0.8" | ||
"node": ">= 0.6" | ||
}, | ||
"main": "./lib/citibike" | ||
} |
@@ -1,4 +0,4 @@ | ||
# CitibikeNYC API Client Library for node.js | ||
# Citibike [![Build Status](https://travis-ci.org/KevinTCoughlin/citibike.png)](https://travis-ci.org/KevinTCoughlin/citibike) | ||
A node.js module, which provides an object oriented wrapper for the CitibikeNYC API. | ||
A [node.js](http://nodejs.org/) wrapper for [Citibike](http://citibikenyc.com/)'s REST API. | ||
@@ -10,5 +10,5 @@ ## Installation | ||
$ npm install citibike | ||
Or... | ||
or | ||
Install via git clone: | ||
@@ -20,38 +20,77 @@ | ||
## Documentation | ||
## Requirements | ||
You can find the docs for the API of this client at [https://github.com/KevinTCoughlin/citibike](https://github.com/KevinTCoughlin/citibike) | ||
You can install citibike and its dependencies with npm: | ||
$ npm install citibike | ||
Dependencies | ||
* [node](http://nodejs.org/) v0.6 + | ||
## Example Usage | ||
## Notes | ||
## Implemented API Endpoints | ||
* **Parameters (Not Currently Supported)** | ||
Since Citibike has not released their Official API the module does not support parameters. | ||
Once either the supported query string parameters are discovered or the official API is released | ||
the module will support params. | ||
* Stations: | ||
* Stations Streaming: 0% | ||
* Helmets: | ||
* Branches: | ||
If you discover supported parameters please post an issue or fork the code so that they can be implemented. | ||
## Examples | ||
Demos of the citibike module are located in: [./examples](https://github.com/KevinTCoughlin/citibike/tree/master/examples) | ||
## API Documentation | ||
* **Stations - .getStations( params, callback )** | ||
citibike.getStations(null, function(data) { | ||
console.log(data); | ||
}); | ||
* **Branches - .getBranches( params, callback )** | ||
citibike.getBranches(null, function(data) { | ||
console.log(data); | ||
}); | ||
* **Helmets - .getHelmets( params, callback )** | ||
citibike.getHelmets(null, function(data) { | ||
console.log(data); | ||
}); | ||
## Testing | ||
## LICENSE | ||
Issue the following Make command in the top directory to run the mocha.js test cases: | ||
$ make test | ||
Citibike: Copyright (c) 2013 Kevin Coughlin | ||
## Contributors | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
* [Brad Dickason](https://github.com/bdickason) | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
## LICENSE | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
Citibike: Copyright (c) 2013 Kevin Coughlin | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
34798
95