Comparing version 0.1.3 to 3.0.0
582
main.js
@@ -10,5 +10,5 @@ /** | ||
"use strict"; | ||
var https = require('https'); | ||
var https = require('https'), | ||
_ = require('underscore'); | ||
@@ -37,334 +37,388 @@ /** | ||
module.exports = function(key) { | ||
// Require API key | ||
if (!key) return; | ||
var apiKey = key; | ||
// Require API key | ||
if (!key) { | ||
return; | ||
} | ||
var apiKey = key; | ||
/** | ||
* Performs an API request. | ||
* @param {string} method The HTTP method. | ||
* @param {string} path The HTTP path to append to the AfterShip default. | ||
* @param {Object} data Body for POST requests. | ||
* @param {function(?string, object=)} callback | ||
* @private | ||
*/ | ||
function request(method, path, data, callback) { | ||
/** | ||
* Performs an API request. | ||
* @param {string} method The HTTP method. | ||
* @param {string} path The HTTP path to append to the AfterShip default. | ||
* @param {Object} data Body for POST requests. | ||
* @param {function(?string, object=)} callback | ||
* @private | ||
*/ | ||
function request(method, path, data, callback) { | ||
// Make sure path starts with a slash | ||
if (path.substr(0, 1) != '/') path = '/' + path; | ||
// Make sure path starts with a slash | ||
if (path.substr(0, 1) != '/') { | ||
path = '/' + path; | ||
} | ||
data = JSON.stringify(data); | ||
data = JSON.stringify(data); | ||
// console.log(data); | ||
// console.log(data); | ||
var asReq = https.request({ | ||
hostname: REQUEST_HOSTNAME, | ||
path: API_PATH + path, | ||
method: method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': data.length, | ||
'aftership-api-key': apiKey | ||
} | ||
}, function(asRes) { | ||
var body = ''; | ||
var asReq = https.request({ | ||
hostname: REQUEST_HOSTNAME, | ||
path: API_PATH + path, | ||
method: method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': data.length, | ||
'aftership-api-key': apiKey | ||
} | ||
}, function(asRes) { | ||
var body = ''; | ||
// Capture the response chunks | ||
asRes.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
// Capture the response chunks | ||
asRes.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
// Called when request is complete | ||
asRes.on('end', function() { | ||
body = JSON.parse(body); | ||
// Called when request is complete | ||
asRes.on('end', function() { | ||
body = JSON.parse(body); | ||
if (!body || !body.meta) { | ||
callback('Could not parse response'); | ||
return; | ||
} | ||
if (!body || !body.meta) { | ||
callback('Could not parse response'); | ||
return; | ||
} | ||
callback(null, body); | ||
}); | ||
}); | ||
callback(null, body); | ||
}); | ||
}); | ||
// Capture any errors | ||
asReq.on('error', function(e) { | ||
callback(e.message); | ||
}); | ||
// Capture any errors | ||
asReq.on('error', function(e) { | ||
callback(e.message); | ||
}); | ||
asReq.write(data); | ||
asReq.end(); | ||
} | ||
asReq.write(data); | ||
asReq.end(); | ||
} | ||
return { | ||
/** | ||
* create a new tracking_number. | ||
* @param {string} tracking_number The number to track. Default: DHL. | ||
* @param {Object=} options Additional options to attach. | ||
* @param {function(?string, string=, Array=)} callback | ||
*/ | ||
'createTracking': function(tracking_number, options, callback) { | ||
return { | ||
/** | ||
* create a new tracking_number. | ||
* @param {string} tracking_number The number to track. Default: DHL. | ||
* @param {Object=} options Additional options to attach. | ||
* @param {function(?string, string=, Array=)} callback | ||
*/ | ||
'createTracking': function(tracking_number, options, callback) { | ||
options = options || {}; | ||
options = options || {}; | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
options.tracking_number = tracking_number; | ||
options.tracking_number = tracking_number; | ||
request('POST', '/trackings', {tracking: options}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
request('POST', '/trackings', {tracking: options}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 201) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 201) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check that it was activated | ||
if (!body.data.tracking.active) { | ||
callback('Tracking not active'); | ||
return; | ||
} | ||
// Check that it was activated | ||
if (!body.data.tracking.active) { | ||
callback('Tracking not active'); | ||
return; | ||
} | ||
// Return the tracking number and data | ||
callback(null, body.data.tracking.tracking_number, body.data.tracking); | ||
}); | ||
}, | ||
// Return the tracking number and data | ||
callback(null, body.data); | ||
}); | ||
}, | ||
/** | ||
* Tracks a specific tracking number. | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to return: https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'tracking': function(slug, tracking_number, fields, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
/** | ||
* Tracks a specific tracking number. | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to return: https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'tracking': function(slug, tracking_number, fields, callback) { | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
// Default to all fields if none are provided | ||
fields = fields || []; | ||
if (Array.isArray(fields)) fields = fields.join(','); | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
request('GET', '/trackings/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
// Default to all fields if none are provided | ||
fields = fields || []; | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
request('GET', '/trackings/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
// Return the time and checkpoints | ||
callback(null, body.data.tracking); | ||
}); | ||
}, | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
/** | ||
* Updates the tracking for an existing number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array} options Fields to update: | ||
* https://www.aftership.com/docs/api/3.0/tracking/put-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'updateTracking': function(slug, tracking_number, options, callback) { | ||
// Return the time and checkpoints | ||
callback(null, body.data); | ||
}); | ||
}, | ||
/** | ||
* Gets all trackings in account. | ||
* @param {object} options Defined here: https://www.aftership.com/docs/api/3.0/tracking/get-trackings | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'trackings': function(options, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
options = options || {}; | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
request('GET', '/trackings', options, function(err, body) { | ||
options = options || {}; | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
request('PUT', '/trackings/' + slug + '/' + tracking_number, | ||
{tracking: options}, function(err, body) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
// Return the time and checkpoints | ||
callback(null, body.data); | ||
}); | ||
}, | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
callback(null, body.data.tracking); | ||
}); | ||
}, | ||
/** | ||
* Updates the tracking for an existing number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array} options Fields to update: | ||
* https://www.aftership.com/docs/api/3.0/tracking/put-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'updateTracking': function(slug, tracking_number, options, callback) { | ||
/** | ||
* Gets all trackings in account. | ||
* @param {object} options Defined here: https://www.aftership.com/docs/api/3.0/tracking/get-trackings | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'trackings': function(options, callback) { | ||
options = options || {}; | ||
options = options || {}; | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
request('GET', '/trackings', options, function(err, body) { | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
request('PUT', '/trackings/' + slug + '/' + tracking_number, | ||
{tracking: options}, function(err, body) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
var trackings = body.data.trackings; | ||
delete body.data.trackings; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Return the time and checkpoints | ||
callback(null, body.data, trackings); | ||
}); | ||
}, | ||
callback(null, body.data); | ||
}); | ||
}, | ||
/** | ||
* Gets all available couriers. | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'couriers': function(callback) { | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
/** | ||
* Delete a specific tracking number. | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to return: https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'deleteTracking': function(slug, tracking_number, callback) { | ||
request('GET', '/couriers', {}, function(err, body) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
request('DELETE', '/trackings/' + slug + '/' + tracking_number, | ||
{}, function(err, body) { | ||
callback(null, body.data.total, body.data.couriers); | ||
}); | ||
}, | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
/** | ||
* Get the last checkpoint information of a tracking number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to update: https://www.aftership.com/docs/api/3.0/last_checkpoint | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'last_checkpoint': function(slug, tracking_number, fields, callback) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
// Return the tracking number and slug | ||
callback(null, body.data); | ||
}); | ||
}, | ||
if (typeof callback != 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
fields = fields || []; | ||
if (Array.isArray(fields)) fields = fields.join(','); | ||
/** | ||
* Gets all available couriers. | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'couriers': function(callback) { | ||
request('GET', '/last_checkpoint/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
request('GET', '/couriers', {}, function(err, body) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
callback(null, body.data.tag, body.data.checkpoint); | ||
}); | ||
} | ||
}; | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
}, | ||
/** | ||
* Get the last checkpoint information of a tracking number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to update: https://www.aftership.com/docs/api/3.0/last_checkpoint | ||
* @param {function(?string, Object=)} callback | ||
*/ | ||
'last_checkpoint': function(slug, tracking_number, fields, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
if (!_.isFunction(callback)) { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
fields = fields || []; | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} | ||
request('GET', '/last_checkpoint/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint != 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
} | ||
}; | ||
}; | ||
101
package.json
{ | ||
"name": "aftership", | ||
"description": "AfterShip API Wrapper", | ||
"version": "0.1.3", | ||
"homepage": "https://github.com/AfterShip/aftership-nodejs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/AfterShip/aftership-nodejs.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.8" | ||
}, | ||
"main": "./main", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"nodeunit": "0.7.4", | ||
"optimist": "0.3.5" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/AfterShip/aftership-nodejs/issues" | ||
}, | ||
"scripts": { | ||
"test": "node test/tests.js -v" | ||
}, | ||
"files": [ | ||
"main.js", | ||
"test", | ||
"README.md", | ||
"LICENSE.md", | ||
"package.json" | ||
], | ||
"keywords": [ | ||
"aftership api", | ||
"aftership", | ||
"aftership-nodejs" | ||
], | ||
"author": "AfterShip", | ||
"contributors": [ | ||
{ | ||
"name": "Kirk Morales", | ||
"email": "kirk@intrakr.com", | ||
"url": "http://www.about.me/kirk.morales" | ||
} | ||
], | ||
"license": "GNU" | ||
"name": "aftership", | ||
"description": "AfterShip NodeJS API Wrapper", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/AfterShip/aftership-nodejs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/AfterShip/aftership-nodejs.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.8" | ||
}, | ||
"main": "./main", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
"underscore": "latest" | ||
}, | ||
"devDependencies": { | ||
"nodeunit": "0.7.4", | ||
"optimist": "0.3.5" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/AfterShip/aftership-nodejs/issues" | ||
}, | ||
"scripts": { | ||
"test": "node test/tests.js -v" | ||
}, | ||
"files": [ | ||
"main.js", | ||
"test", | ||
"README.md", | ||
"LICENSE.md", | ||
"package.json" | ||
], | ||
"keywords": [ | ||
"aftership api", | ||
"aftership", | ||
"aftership-nodejs" | ||
], | ||
"author": "AfterShip", | ||
"contributors": [ | ||
{ | ||
"name": "Kirk Morales", | ||
"email": "kirk@intrakr.com", | ||
"url": "http://www.about.me/kirk.morales" | ||
}, | ||
{ | ||
"name": "AfterShip", | ||
"email": "support@aftership.com", | ||
"url": "https://www.aftership.com" | ||
} | ||
], | ||
"license": "GNU" | ||
} |
@@ -162,3 +162,3 @@ Install | ||
Aftership.track('ups', '1Z21E98F0314447088', [], function(err, tracking) { | ||
Aftership.tracking('ups', '1Z21E98F0314447088', [], function(err, tracking) { | ||
if (err) { | ||
@@ -165,0 +165,0 @@ console.log(err); |
@@ -1,5 +0,4 @@ | ||
if (!GLOBAL.apiKey) { | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
} | ||
@@ -9,28 +8,21 @@ | ||
exports['Couriers'] = { | ||
exports.Couriers = { | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.couriers(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.couriers(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'OK': function(test) { | ||
test.expect(5); | ||
'OK': function(test) { | ||
test.expect(2); | ||
Aftership.couriers(function(err, length, couriers) { | ||
test.ok(!err); | ||
test.ok(Array.isArray(couriers)); | ||
test.equal(typeof length, 'number'); | ||
Aftership.couriers(function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
// Make sure trackings array was removed from meta data | ||
test.ok(!couriers.total); | ||
// We should have at least 1 entry, check it | ||
test.equal(typeof couriers[0].slug, 'string'); | ||
test.done(); | ||
}); | ||
} | ||
test.done(); | ||
}); | ||
} | ||
}; |
@@ -1,6 +0,5 @@ | ||
/****************************************** | ||
* Set your API key here for testing | ||
******************************************/ | ||
GLOBAL.apiKey = ''; | ||
GLOBAL.apiKey = 'e9f201df-91f2-4f13-9a64-3ad64826d47d'; // please use your AfterShip api key | ||
@@ -12,8 +11,8 @@ /****************************************** | ||
GLOBAL.tracking = { | ||
'dhl': '4681442382', | ||
'fedex': '573191403485', | ||
'tnt': '881232984', | ||
'toll-global-express': '813081390262', | ||
'ups': '1Z86392WYW91844988', | ||
'usps': '9449010200828835620973' | ||
'dhl': '4681442382', | ||
'fedex': '573191403485', | ||
'tnt': '881232984', | ||
'toll-global-express': '813081390262', | ||
'ups': '1Z5V572E0365305588', | ||
'usps': '9405509699937485290971' | ||
}; | ||
@@ -26,5 +25,6 @@ | ||
var tests = [ | ||
'track.js', | ||
'trackings.js', | ||
'couriers.js' | ||
'couriers.js', | ||
'track.js', | ||
'trackings.js', | ||
'delete_trackings.js' | ||
]; | ||
@@ -39,8 +39,8 @@ | ||
var argv = optimist.usage('\n./tests.js OPTIONS', { | ||
'verbose': { | ||
description: 'If set, shows verbose output', | ||
alias: 'v', | ||
default: false, | ||
boolean: true | ||
} | ||
'verbose': { | ||
description: 'If set, shows verbose output', | ||
alias: 'v', | ||
default: false, | ||
boolean: true | ||
} | ||
}).argv; | ||
@@ -51,23 +51,23 @@ | ||
if (argv.verbose) { | ||
reporter = require('nodeunit').reporters.default; | ||
reporter = require('nodeunit').reporters.default; | ||
// Add directory to each item | ||
for (var i=0;i<tests.length;i++) { | ||
tests[i] = 'test/' + tests[i]; | ||
} | ||
// Add directory to each item | ||
for (var i = 0; i < tests.length; i++) { | ||
tests[i] = 'test/' + tests[i]; | ||
} | ||
} else { | ||
reporter = require('nodeunit'); | ||
reporter = require('nodeunit'); | ||
// Add directory to each item | ||
for (var i=0;i<tests.length;i++) { | ||
tests[i] = __dirname + '/' + tests[i]; | ||
} | ||
// Add directory to each item | ||
for (var i = 0; i < tests.length; i++) { | ||
tests[i] = __dirname + '/' + tests[i]; | ||
} | ||
} | ||
if (argv.verbose) { | ||
reporter.run(tests, null); | ||
reporter.run(tests, null); | ||
} else { | ||
reporter.runFiles(tests); | ||
reporter.runFiles(tests); | ||
} |
@@ -1,5 +0,4 @@ | ||
if (!GLOBAL.apiKey) { | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
} | ||
@@ -10,121 +9,132 @@ | ||
exports['Track'] = { | ||
exports.Track = { | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.createTracking(), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking(), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.createTracking('foo'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking('foo'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.createTracking('foo', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking('foo', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Ok (no slug)': function(test) { | ||
test.expect(6); | ||
// UPS | ||
Aftership.createTracking(GLOBAL.tracking['ups'], {}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['ups']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
'Ok (no slug)': function(test) { | ||
test.expect(5); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
// Make sure it auto-detected the slug | ||
test.equal(result.tracking.slug, 'usps'); | ||
// Make sure it auto-detected the slug | ||
test.equal(result.slug, 'ups'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug tnt)': function(test) { | ||
test.expect(5); | ||
'Ok (w/ slug tnt)': function(test) { | ||
test.expect(6); | ||
// tnt | ||
Aftership.createTracking(GLOBAL.tracking.tnt, {slug: 'tnt'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.tnt); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'tnt'); | ||
// UPS | ||
Aftership.createTracking(GLOBAL.tracking['tnt'], {slug: 'tnt'}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['tnt']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
test.equal(result.slug, 'tnt'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug fedex)': function(test) { | ||
test.expect(5); | ||
'Ok (w/ slug fedex)': function(test) { | ||
test.expect(6); | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.fedex, {slug: 'fedex'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.fedex); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'fedex'); | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking['fedex'], {slug: 'fedex'}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['fedex']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
test.equal(result.slug, 'fedex'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug ups)': function(test) { | ||
test.expect(5); | ||
'Ok (w/ slug toll-global-express)': function(test) { | ||
test.expect(6); | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.ups, {slug: 'ups'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'ups'); | ||
// toll-global-express | ||
Aftership.createTracking(GLOBAL.tracking['toll-global-express'], {slug: 'toll-global-express'}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['toll-global-express']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
test.equal(result.slug, 'toll-global-express'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug toll-global-express)': function(test) { | ||
test.expect(5); | ||
'Ok (w/ slug usps)': function(test) { | ||
test.expect(6); | ||
// toll-global-express | ||
Aftership.createTracking(GLOBAL.tracking['toll-global-express'], {slug: 'toll-global-express'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking['toll-global-express']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'toll-global-express'); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking['usps'], {slug: 'usps'}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['usps']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
test.equal(result.slug, 'usps'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug dhl)': function(test) { | ||
test.expect(5); | ||
'Ok (w/ slug dhl)': function(test) { | ||
test.expect(6); | ||
// dhl | ||
Aftership.createTracking(GLOBAL.tracking.dhl, {slug: 'dhl'}, function(err, result) { | ||
test.ok(!err); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dhl); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'dhl'); | ||
// dhl | ||
Aftership.createTracking(GLOBAL.tracking['dhl'], {slug: 'dhl'}, function(err, trackingNumber, result) { | ||
test.ok(!err); | ||
test.equal(trackingNumber, GLOBAL.tracking['dhl']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.checkpoints); | ||
test.equal(result.active, true); | ||
test.equal(result.slug, 'dhl'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
} | ||
'Ok (w/ slug usps)': function(test) { | ||
test.expect(5); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {slug: 'usps'}, function(err, result) { | ||
// as the tracking is already created in w/o slug, there should be error return | ||
test.notEqual(err, ''); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(result.tracking.slug, 'usps'); | ||
test.done(); | ||
}); | ||
} | ||
}; |
@@ -1,2 +0,1 @@ | ||
if (!GLOBAL.apiKey) { | ||
@@ -10,3 +9,3 @@ console.log('No API Key Provided'); | ||
exports['Track'] = { | ||
exports.Track = { | ||
@@ -45,9 +44,9 @@ 'No Slug': function(test) { | ||
// UPS | ||
Aftership.tracking('ups', GLOBAL.tracking['ups'], null, function(err, tracking) { | ||
test.ok(!err); | ||
test.equal(typeof tracking, 'object'); | ||
test.equal(tracking.slug, 'ups'); | ||
test.equal(tracking.tracking_number, GLOBAL.tracking['ups']); | ||
test.ok(tracking.checkpoints); | ||
test.notEqual(typeof(tracking.active), 'undefined'); | ||
Aftership.tracking('ups', GLOBAL.tracking.ups, null, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.ok(result.tracking.checkpoints); | ||
test.notEqual(typeof(result.tracking.active), 'undefined'); | ||
@@ -60,3 +59,3 @@ test.done(); | ||
exports['Trackings'] = { | ||
exports.Trackings = { | ||
@@ -78,18 +77,14 @@ 'No Callback (no options)': function(test) { | ||
'OK': function(test) { | ||
test.expect(7); | ||
test.expect(5); | ||
Aftership.trackings({}, function(err, meta, trackings) { | ||
test.ok(!err); | ||
test.equal(typeof meta, 'object'); | ||
test.ok(Array.isArray(trackings)); | ||
Aftership.trackings({}, function(err, results) { | ||
test.equal(err, null); | ||
test.ok(Array.isArray(results.trackings)); | ||
// Make sure trackings array was removed from meta data | ||
test.ok(!meta.trackings); | ||
// Check for a few meta parameters | ||
test.equal(typeof meta.limit, 'number'); | ||
test.equal(typeof meta.slug, 'string'); | ||
test.equal(typeof results.limit, 'number'); | ||
test.equal(typeof results.slug, 'string'); | ||
// We should have at least 1 entry, check it | ||
test.equal(typeof trackings[0].tracking_number, 'string'); | ||
test.equal(typeof results.trackings[0].tracking_number, 'string'); | ||
@@ -105,3 +100,3 @@ test.done(); | ||
// Aftership.trackings({limit: 1}, function(err, meta, trackings) { | ||
// test.ok(!err); | ||
// test.equal(err, null); | ||
// test.equal(typeof meta, 'object'); | ||
@@ -162,8 +157,8 @@ // test.ok(Array.isArray(trackings)); | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking['ups'], null, function(err, tracking) { | ||
test.ok(!err); | ||
test.equal(typeof tracking, 'object'); | ||
test.equal(tracking.slug, 'ups'); | ||
test.equal(tracking.tracking_number, GLOBAL.tracking['ups']); | ||
test.notEqual(typeof(tracking.active), 'undefined'); | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.notEqual(typeof(result.tracking.active), 'undefined'); | ||
@@ -178,8 +173,8 @@ test.done(); | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking['ups'], {title: 'Foobar'}, function(err, tracking) { | ||
test.ok(!err); | ||
test.equal(typeof tracking, 'object'); | ||
test.equal(tracking.slug, 'ups'); | ||
test.equal(tracking.tracking_number, GLOBAL.tracking['ups']); | ||
test.equal(tracking.title, 'Foobar'); | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {title: 'Foobar'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(result.tracking.title, 'Foobar'); | ||
@@ -192,3 +187,3 @@ test.done(); | ||
exports['Checkpoint'] = { | ||
exports.Checkpoint = { | ||
@@ -224,10 +219,9 @@ 'No Slug': function(test) { | ||
'Ok': function(test) { | ||
test.expect(4); | ||
test.expect(3); | ||
// UPS | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking['ups'], null, function(err, tag, checkpoint) { | ||
test.ok(!err); | ||
test.equal(typeof tag, 'string'); | ||
test.equal(typeof checkpoint, 'object'); | ||
test.equal(typeof checkpoint.tag, 'string'); | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking.ups, null, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.equal(typeof result.checkpoint.tag, 'string'); | ||
@@ -234,0 +228,0 @@ test.done(); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30568
9
783
0
1
+ Addedunderscore@latest
+ Addedunderscore@1.13.7(transitive)