Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated tests and some code cleanup

  • Loading branch information...
commit 649afc9109e838c4443551cc29c1991829ca220c 1 parent 5cf1ba0
@tanepiper authored
Showing with 15 additions and 10 deletions.
  1. +5 −5 bitly.js → index.js
  2. +1 −2  package.json
  3. +9 −3 test/index.js
View
10 bitly.js → index.js
@@ -76,7 +76,7 @@ Bitly.prototype._doRequest = function(request_query, cb) {
try {
result = JSON.parse(urldata);
} catch (exp) {
- result = {'status_code': 500, 'status_text': 'JSON Parse Failed'}
+ result = {'status_code': 500, 'status_text': 'JSON Parse Failed'};
}
cb(null, result);
});
@@ -93,7 +93,7 @@ Bitly.prototype._doRequest = function(request_query, cb) {
*/
Bitly.prototype._urlCheck = function(str) {
var v = new RegExp();
- v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
+ v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\\?\/.=]+$");
if (!v.test(str)) return false;
return true;
};
@@ -110,14 +110,14 @@ Bitly.prototype._sortUrlsAndHash = function(items, query) {
var i = 0, j = items.length;
for(; i < j; i++) {
if (this._urlCheck(items[i])) {
- shortUrl.push(items[i])
+ shortUrl.push(items[i]);
} else {
hash.push(items[i]);
}
}
if (shortUrl.length > 0) query.shortUrl = shortUrl;
if (hash.length > 0) query.hash = hash;
-}
+};
/**
* Request to shorten one long url
@@ -352,7 +352,7 @@ Bitly.prototype.validate = function(x_login, x_apiKey, cb) {
};
this._doRequest(this._generateNiceUrl(query, 'validate'), cb);
-}
+};
// Export as main entry point in this module
module.exports = Bitly;
View
3  package.json
@@ -2,14 +2,13 @@
"name": "bitly",
"description": "A Bit.ly API library for Node.JS",
"tags": ["url", "bitly", "shortner", "util"],
- "version": "1.2.3",
+ "version": "1.2.4",
"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"}
],
- "main": "./bitly",
"repository": {
"type": "git",
"url": "http://github.com/tanepiper/node-bitly.git"
View
12 test/index.js
@@ -1,10 +1,16 @@
-var Bitly = require('../bitly');
+var Bitly = require('../');
var bitly_user = 'bitlynodejs';
var bitly_key = 'R_8a2a91d31932dc7fda5468033dfe3c15';
module.exports = {
+ 'test valid url': function(test) {
+ var bitly = new Bitly(bitly_user, bitly_key);
+ test.ok(true, bitly._urlCheck('http://tanepiper.com/test?q=test'));
+ test.done();
+ },
+
'shorten url': function(test) {
var bitly = new Bitly(bitly_user, bitly_key);
bitly.shorten('http://tanepiper.com', function(error, result) {
@@ -218,7 +224,7 @@ module.exports = {
test.ifError(error);
test.deepEqual(result.status_code, 200);
test.done();
- })
+ });
}
-}
+};
Please sign in to comment.
Something went wrong with that request. Please try again.