diff --git a/README.md b/README.md index 253e42c..698bfc2 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,13 @@ Usage var gitio = require('gitio'); // Pass a direct URL and get back a random URL - gitio('https://github.com/tanepiper/node-gitio', function(err, data) { - var url = data.url; + gitio('https://github.com/tanepiper/node-gitio', function(err, result) { + if (err) throw err; + console.log(result); }); // Pass an optional key to get the URL of your request - gitio('https://github.com/joyent/node', 'nodejs', function(err, data) { - var url = data.url; + gitio('https://github.com/joyent/node', 'nodejs', function(err, result) { + if (err) throw err; + console.log(result); }); diff --git a/index.js b/index.js index a6adf7e..2e63822 100644 --- a/index.js +++ b/index.js @@ -22,12 +22,13 @@ var getGitIoAddress = function(address, code, cb) { } }, function(res) { res.on('end', function() { - console.log(res); - var result = { - statusCode: res.statusCode, - url: res.headers.location || null + + var passed = (res.statusCode < 300 && res.statusCode >= 200); + if (passed) { + cb(null, res.headers.location); + } else { + cb(new Error('Git.io ' + res.headers.status)); } - cb(null, result); }); res.on('error', function(e) { diff --git a/package.json b/package.json index b1f4801..d0e1d6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,15 @@ { "name": "gitio", - "version": "1.0.0", + "version": "1.0.1", + "author" : "Tane Piper ", "description": "Library for nodejs to call the git.io URL shortner", - "main": "./index" + "main": "./index", + "repository" : { + "type" : "git", + "url" : "https://github.com/tanepiper/node-gitio.git" + }, + "bugs" : { + "url" : "http://github.com/tanepiper/node-gitio/issues" + }, + "engines" : ["node >= 0.4.0"] } diff --git a/test.js b/test.js index 726a7d1..8b169ab 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,6 @@ var gitio = require('./index'); -gitio('https://github.com/tanepiper/node-bitly', function(err, data) { - if (!err && data.statusCode === 200) { - console.log('Your URL is ' + data.url); - } else { - console.log(err, data) - } +gitio('https://github.com/tanepiper/node-gitio', function(err, result) { + if (err) throw err; + console.log(result); });