Comparing version 1.2.5 to 2.0.0
132
index.js
@@ -9,3 +9,3 @@ /** | ||
var q = require('q'); | ||
var url = require('url'); | ||
@@ -65,25 +65,47 @@ var http = require('http'); | ||
* @param {Object} request_query The current query object | ||
* @param {Function} cb The callback function for the returned data | ||
* @return {void} | ||
* @param {Function=} cb The callback function for the returned data | ||
* @return {Promise|void} | ||
*/ | ||
Bitly.prototype._doRequest = function(request_query, cb) { | ||
var deferred; | ||
if (!cb || typeof !cb === 'function') { | ||
deferred = q.defer(); | ||
} | ||
// Pass the requested URL as an object to the get request | ||
http.get(request_query, function(res) { | ||
var data = []; | ||
res | ||
var data = []; | ||
res | ||
.on('data', function(chunk) { data.push(chunk); }) | ||
.on('end', function() { | ||
var urldata = data.join('').trim(); | ||
var result; | ||
try { | ||
result = JSON.parse(urldata); | ||
} catch (exp) { | ||
result = {'status_code': 500, 'status_text': 'JSON Parse Failed'}; | ||
} | ||
cb(null, result); | ||
var urldata = data.join('').trim(); | ||
var result; | ||
try { | ||
result = JSON.parse(urldata); | ||
} catch (exp) { | ||
result = {'status_code': 500, 'status_text': 'JSON Parse Failed'}; | ||
} | ||
if (result.status_code !== 200) { | ||
var error = new Error(result.status_txt); | ||
error.code = result.status_code; | ||
return deferred ? deferred.reject(error) : cb(error); | ||
} | ||
return deferred ? deferred.resolve(result) : cb(null, result); | ||
}); | ||
}) | ||
.on('error', function(e) { | ||
cb(e); | ||
if (deferred) { | ||
return deferred.reject(e); | ||
} | ||
return cb(e); | ||
}); | ||
if (deferred) { | ||
return deferred.promise; | ||
} | ||
}; | ||
@@ -127,5 +149,5 @@ | ||
* @param {String} longUrl The URL to be shortened | ||
* @param {String} domain The domain to use (optional) | ||
* @param {Function} cb The callback function with the results | ||
* @return {void} | ||
* @param {String=} domain The domain to use (optional) | ||
* @param {Function=} cb The callback function with the results | ||
* @return {Promise|void} | ||
*/ | ||
@@ -149,3 +171,3 @@ Bitly.prototype.shorten = function(longUrl, domain, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'shorten'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'shorten'), cb); | ||
}; | ||
@@ -155,5 +177,5 @@ | ||
* Request to expand a single short url, short hash or mixed array or items | ||
* @param {Mixed} items The string or array of short urls and/or hashes to expand | ||
* @param {Function} cb The callback function with the results | ||
* @return {void} | ||
* @param {String|Array} items The string or array of short urls and/or hashes to expand | ||
* @param {Function=} cb The callback function with the results | ||
* @return {Promise|void} | ||
*/ | ||
@@ -175,3 +197,3 @@ Bitly.prototype.expand = function(items, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'expand'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'expand'), cb); | ||
}; | ||
@@ -181,5 +203,5 @@ | ||
* Request to get clicks for a single short url, short hash or mixed array or items | ||
* @param {Mixed} items The string or array of short urls and/or hashes to expand | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {String|Array} items The string or array of short urls and/or hashes to expand | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -201,3 +223,3 @@ Bitly.prototype.clicks = function(items, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'clicks'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'clicks'), cb); | ||
}; | ||
@@ -207,5 +229,5 @@ | ||
* Request to get clicks by minute for a single short url, short hash or mixed array or items | ||
* @param {Mixed} items The string or array of short urls and/or hashes to expand | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {String|Array} items The string or array of short urls and/or hashes to expand | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -227,3 +249,3 @@ Bitly.prototype.clicksByMinute = function(items, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'clicks_by_minute'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'clicks_by_minute'), cb); | ||
@@ -234,5 +256,5 @@ }; | ||
* Request to get clicks by day for a single short url, short hash or mixed array or items | ||
* @param {Mixed} items The string or array of short urls and/or hashes to expand | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {String|Array} items The string or array of short urls and/or hashes to expand | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -254,3 +276,3 @@ Bitly.prototype.clicksByDay = function(items, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'clicks_by_day'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'clicks_by_day'), cb); | ||
}; | ||
@@ -260,5 +282,5 @@ | ||
* Request to get look up an existing bitly link for a long url or array of urls | ||
* @param {Mixed} items The string or array of long urls | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {String|Array} links The string or array of long urls | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -274,3 +296,3 @@ Bitly.prototype.lookup = function(links, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'lookup'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'lookup'), cb); | ||
@@ -281,5 +303,5 @@ }; | ||
* Request to get clicks by day for a single short url, short hash or mixed array or items | ||
* @param {Mixed} items The string or array of short urls and/or hashes to expand | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {String|Array} items The string or array of short urls and/or hashes to expand | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -301,3 +323,3 @@ Bitly.prototype.info = function(items, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'info'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'info'), cb); | ||
}; | ||
@@ -311,4 +333,4 @@ | ||
* @param {String} link The link be checked | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -325,3 +347,3 @@ Bitly.prototype.referrers = function(link, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'referrers'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'referrers'), cb); | ||
}; | ||
@@ -332,4 +354,4 @@ | ||
* accepts one url (as per the limit of the bitly API) | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -346,3 +368,3 @@ Bitly.prototype.countries = function(link, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'countries'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'countries'), cb); | ||
}; | ||
@@ -353,4 +375,4 @@ | ||
* @param {String} domain The domain to be checked | ||
* @param {Function} cb The callback function | ||
* @return {void} | ||
* @param {Function=} cb The callback function | ||
* @return {Promise|void} | ||
*/ | ||
@@ -365,3 +387,3 @@ Bitly.prototype.bitlyProDomain = function(domain, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'bitly_pro_domain'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'bitly_pro_domain'), cb); | ||
}; | ||
@@ -373,4 +395,4 @@ | ||
* @param {String} x_apiKey The API key to be validated | ||
* @param {Function} cb The callback | ||
* @return {void} | ||
* @param {Function=} cb The callback | ||
* @return {Promise|void} | ||
*/ | ||
@@ -386,6 +408,6 @@ Bitly.prototype.validate = function(x_login, x_apiKey, cb) { | ||
this._doRequest(this._generateNiceUrl(query, 'validate'), cb); | ||
return this._doRequest(this._generateNiceUrl(query, 'validate'), cb); | ||
}; | ||
// Export as main entry point in this module | ||
module.exports = Bitly; | ||
module.exports = Bitly; |
{ | ||
"name": "bitly", | ||
"description": "A Bit.ly API library for Node.JS", | ||
"tags": ["url", "bitly", "shortner", "util"], | ||
"version": "1.2.5", | ||
"tags": [ | ||
"url", | ||
"bitly", | ||
"shortner", | ||
"util" | ||
], | ||
"version": "2.0.0", | ||
"author": "Tane Piper <piper.tane@gmail.com>", | ||
"contributors": [ | ||
{ "name": "Tane Piper", "email": "piper.tane@gmail.com" }, | ||
{ "name": "François de Metz", "email": "francois@2metz.fr" }, | ||
{ "name": "zephrax"}, | ||
{ "name": "jessefulton" } | ||
{ | ||
"name": "Tane Piper", | ||
"email": "piper.tane@gmail.com" | ||
}, | ||
{ | ||
"name": "François de Metz", | ||
"email": "francois@2metz.fr" | ||
}, | ||
{ | ||
"name": "zephrax" | ||
}, | ||
{ | ||
"name": "jessefulton" | ||
} | ||
], | ||
@@ -17,3 +32,5 @@ "repository": { | ||
}, | ||
"engines": { "node": ">= 0.4.0" }, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"scripts": { | ||
@@ -23,4 +40,7 @@ "test": "node_modules/.bin/nodeunit test" | ||
"devDependencies": { | ||
"nodeunit": ">=0.6.2" | ||
"nodeunit": "^0.9.1" | ||
}, | ||
"dependencies": { | ||
"q": "^1.4.1" | ||
} | ||
} |
@@ -21,6 +21,11 @@ node-bitly - Bitly API for nodejs | ||
var bitly = new Bitly('<YOUR USERNAME>', '<YOUR API KEY>'); | ||
/** | ||
* With callback | ||
*/ | ||
bitly.shorten('https://github.com/tanepiper/node-bitly', function(err, response) { | ||
if (err) throw err; | ||
// See http://code.google.com/p/bitly-api/wiki/ApiDocumentation for format of returned object | ||
// See http://dev.bitly.com/ for format of returned object | ||
var short_url = response.data.url | ||
@@ -30,3 +35,16 @@ | ||
}); | ||
/** | ||
* With promise | ||
*/ | ||
bitly.shorten('https://github.com/tanepiper/node-bitly') | ||
.then(function(response) { | ||
// See http://dev.bitly.com/ for format of returned object | ||
var short_url = response.data.url | ||
// Do something with data | ||
}, function(error) { | ||
throw error; | ||
}); | ||
Tests | ||
@@ -33,0 +51,0 @@ ----- |
@@ -14,3 +14,3 @@ var Bitly = require('../'); | ||
'shorten url': function(test) { | ||
'shorten url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
@@ -24,4 +24,15 @@ bitly.shorten('http://tanepiper.com', function(error, result) { | ||
'Check info on bitly pro-domain': function(test) { | ||
'shorten url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.shorten('http://tanepiper.com').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Check info on bitly pro-domain with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.bitlyProDomain('nyti.ms', function(error, result) { | ||
@@ -34,4 +45,15 @@ test.ifError(error); | ||
'Get info about single short url': function(test) { | ||
'Check info on bitly pro-domain with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.bitlyProDomain('nyti.ms').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get info about single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -44,4 +66,15 @@ test.ifError(error); | ||
'Get info about single hash': function(test) { | ||
'Get info about single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get info about single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info('6uBruH', function(error, result) { | ||
@@ -54,4 +87,15 @@ test.ifError(error); | ||
'Get info about mixed url and hash': function(test) { | ||
'Get info about single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get info about mixed url and hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info(['http://bit.ly/9lCnZ9', '6uBruH'], function(error, result) { | ||
@@ -64,4 +108,15 @@ test.ifError(error); | ||
'Get clicks for single short url': function(test) { | ||
'Get info about mixed url and hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.info(['http://bit.ly/9lCnZ9', '6uBruH']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -74,4 +129,15 @@ test.ifError(error); | ||
'Get clicks for single hash': function(test) { | ||
'Get clicks for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks('6uBruH', function(error, result) { | ||
@@ -84,4 +150,15 @@ test.ifError(error); | ||
'Get clicks for mixed url and hash': function(test) { | ||
'Get clicks for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks for mixed url and hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks(['http://bit.ly/9lCnZ9', '6uBruH'], function(error, result) { | ||
@@ -94,4 +171,15 @@ test.ifError(error); | ||
'Get clicks by minute for single short url': function(test) { | ||
'Get clicks for mixed url and hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicks(['http://bit.ly/9lCnZ9', '6uBruH']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by minute for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -104,4 +192,15 @@ test.ifError(error); | ||
'Get clicks by minute for single hash': function(test) { | ||
'Get clicks by minute for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by minute for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute('6uBruH', function(error, result) { | ||
@@ -114,4 +213,15 @@ test.ifError(error); | ||
'Get clicks by minute for mixed url and hash': function(test) { | ||
'Get clicks by minute for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by minute for mixed url and hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute(['http://bit.ly/9lCnZ9', '6uBruH'], function(error, result) { | ||
@@ -124,4 +234,15 @@ test.ifError(error); | ||
'Get clicks by day for single short url': function(test) { | ||
'Get clicks by minute for mixed url and hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByMinute(['http://bit.ly/9lCnZ9', '6uBruH']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by day for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -134,4 +255,15 @@ test.ifError(error); | ||
'Get clicks by day for single hash': function(test) { | ||
'Get clicks by day for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by day for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay('6uBruH', function(error, result) { | ||
@@ -144,4 +276,15 @@ test.ifError(error); | ||
'Get clicks by day for mixed url and hash': function(test) { | ||
'Get clicks by day for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get clicks by day for mixed url and hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay(['http://bit.ly/9lCnZ9', '6uBruH'], function(error, result) { | ||
@@ -154,4 +297,16 @@ test.ifError(error); | ||
'Get referrers for single short url': function(test) { | ||
'Get clicks by day for mixed url and hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.clicksByDay(['http://bit.ly/9lCnZ9', '6uBruH']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get referrers for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.referrers('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -164,4 +319,15 @@ test.ifError(error); | ||
'Get referrers for single hash': function(test) { | ||
'Get referrers for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.referrers('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get referrers for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.referrers('6uBruH', function(error, result) { | ||
@@ -174,4 +340,15 @@ test.ifError(error); | ||
'Get countries for single short url': function(test) { | ||
'Get referrers for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.referrers('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get countries for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.countries('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -184,4 +361,16 @@ test.ifError(error); | ||
'Get countries for single hash': function(test) { | ||
'Get countries for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.countries('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Get countries for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.countries('6uBruH', function(error, result) { | ||
@@ -194,4 +383,15 @@ test.ifError(error); | ||
'Look up information about 1 long url': function(test) { | ||
'Get countries for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.countries('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Look up information about 1 long url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.lookup('http://tanepiper.com', function(error, result) { | ||
@@ -204,4 +404,15 @@ test.ifError(error); | ||
'Look up information about multiple long url': function(test) { | ||
'Look up information about 1 long url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.lookup('http://tanepiper.com').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Look up information about multiple long url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.lookup(['http://tanepiper.com', 'http://nodejs.org'], function(error, result) { | ||
@@ -214,4 +425,15 @@ test.ifError(error); | ||
'Expand for single short url': function(test) { | ||
'Look up information about multiple long url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.lookup(['http://tanepiper.com', 'http://nodejs.org']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Expand for single short url with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand('http://bit.ly/9lCnZ9', function(error, result) { | ||
@@ -224,4 +446,16 @@ test.ifError(error); | ||
'Expand for single hash': function(test) { | ||
'Expand for single short url with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand('http://bit.ly/9lCnZ9').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Expand for single hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand('6uBruH', function(error, result) { | ||
@@ -234,4 +468,15 @@ test.ifError(error); | ||
'Expand for mixed url and hash': function(test) { | ||
'Expand for single hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand('6uBruH').then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Expand for mixed url and hash with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand(['http://bit.ly/9lCnZ9', '6uBruH'], function(error, result) { | ||
@@ -244,4 +489,16 @@ test.ifError(error); | ||
'Validate any bitly user and API key': function(test) { | ||
'Expand for mixed url and hash with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.expand(['http://bit.ly/9lCnZ9', '6uBruH']).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Validate any bitly user and API key with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.validate(bitly_user, bitly_key, function(error, result) { | ||
@@ -252,4 +509,33 @@ test.ifError(error); | ||
}); | ||
}, | ||
'Validate any bitly user and API key with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, bitly_key); | ||
bitly.validate(bitly_user, bitly_key).then(function(result) { | ||
test.deepEqual(result.status_code, 200); | ||
test.done(); | ||
}, function(error) { | ||
test.ifError(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Return error on invalid API key with callback': function(test) { | ||
var bitly = new Bitly(bitly_user, 'xxxxxx'); | ||
bitly.validate(bitly_user, bitly_key, function(error, result) { | ||
test.throws(error); | ||
test.done(); | ||
}); | ||
}, | ||
'Return error on invalid API key with promise': function(test) { | ||
var bitly = new Bitly(bitly_user, 'xxxxxx'); | ||
bitly.validate(bitly_user, bitly_key).then(function(result) { | ||
// None | ||
}, function(error) { | ||
test.throws(error); | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
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
30563
796
66
1