Comparing version 1.0.0 to 2.0.0
@@ -1,33 +0,25 @@ | ||
/** | ||
"use strict"; | ||
/*! | ||
* CitibikeNYC API node.js library | ||
* Author: Kevin Coughlin @kevintcoughlin | ||
* Version: 0.0.1 | ||
* Last Modified: 6/7/13 | ||
* MIT Licensed | ||
*/ | ||
var VERSION = '0.0.1', | ||
http = require('http'), | ||
querystring = require('querystring'); | ||
/** | ||
* Merge default options with user passed options | ||
/** | ||
* Module Dependencies | ||
*/ | ||
function merge( 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; | ||
} | ||
var http = require('http') | ||
, utils = require('./utils') | ||
/** | ||
* Citibike API Object | ||
* Class for handling communications with Citibike's API. | ||
* | ||
* @param {Options} options The Client's options object. | ||
*/ | ||
function Citibike( options ) { | ||
if (!(this instanceof Citibike)) return new Citibike(options); | ||
if (!(this instanceof Citibike)) | ||
return new Citibike(options); | ||
// Default Client Options | ||
var defaults = { | ||
@@ -39,3 +31,3 @@ api_key: null, | ||
'Connection': 'close', | ||
'User-Agent': 'node-Citibike/' + VERSION | ||
'User-Agent': 'node-Citibike/' | ||
}, | ||
@@ -50,7 +42,12 @@ | ||
}; | ||
this.options = merge(defaults, options); | ||
this.options = utils.merge(defaults, options); | ||
} | ||
/** | ||
* GET: | ||
* Issues an HTTP Get request. | ||
* | ||
* @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. | ||
*/ | ||
@@ -71,60 +68,46 @@ Citibike.prototype.get = function( url, params, callback ) { | ||
return this; | ||
} | ||
// Holds data from HTTP response body | ||
var body = [] | ||
, req = http.get(url, function(res){ | ||
res.on('data', function (chunk){ | ||
body += chunk; | ||
}); | ||
/** | ||
* POST: | ||
* TODO: No use right now | ||
Citibike.prototype.post = function( url, content, content_type, callback ) { | ||
if (typeof content === 'function') { | ||
callback = content; | ||
content = null; | ||
content_type = null; | ||
} else if (typeof content_type === 'function') { | ||
callback = content_type; | ||
content_type = null; | ||
} | ||
res.on('end',function(){ | ||
callback(JSON.parse(body)); | ||
}); | ||
}) | ||
req.on('error', function(e) { | ||
console.log("ERROR: " + e.message); | ||
}); | ||
if ( typeof callback !== 'function' ) { | ||
throw "ERROR: Invalid callback function."; | ||
return this; | ||
} | ||
// Forgot base url, add it | ||
if (url.charAt(0) == '/') | ||
url = this.options.rest_base + url; | ||
return this; | ||
} | ||
*/ | ||
/** | ||
* Stream | ||
* TODO: Stream | ||
Citibike.prototype.streamStations = function( method, params, callback ) { | ||
if (typeof params === 'function') { | ||
callback = params; | ||
params = null; | ||
} | ||
if ( typeof callback === 'function' ) callback(stream); | ||
return this; | ||
} | ||
*/ | ||
/** */ | ||
/** | ||
* Function for requesting and returning Citibike Stations data in JSON form. | ||
* | ||
* @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 + stations_url; | ||
this.get(url, params, callback); | ||
var url = this.options.rest_base + this.options.stations_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* GET: Citi Branches | ||
/** | ||
* Function for requesting and returning Citibike Branch data in JSON form. | ||
* | ||
* @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 + branch_url; | ||
this.get(url, params, callback); | ||
var url = this.options.rest_base + this.options.branch_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
@@ -134,11 +117,15 @@ } | ||
/** | ||
* GET: Citibike Helmets | ||
* Function for requesting and returning Citibike Helmets data in JSON form. | ||
* | ||
* @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 + helmet_url; | ||
this.get(url, params, callback); | ||
var url = this.options.rest_base + this.options.helmet_url; | ||
this.get(url, params, function(data) { | ||
callback(data); | ||
}); | ||
return this; | ||
} | ||
Citibike.VERSION = VERSION; | ||
module.exports = Citibike; |
{ | ||
"name": "citibike", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Citibike API Client Library for node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
8591
8
222
2