Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Better error handling, got rid of object for direct url return
Browse files Browse the repository at this point in the history
  • Loading branch information
tanepiper committed Nov 16, 2011
1 parent ac0801d commit 91c8719
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -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);
});
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions package.json
@@ -1,6 +1,15 @@
{
"name": "gitio",
"version": "1.0.0",
"version": "1.0.1",
"author" : "Tane Piper <piper.tane@gmail.com>",
"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"]
}
9 changes: 3 additions & 6 deletions 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);
});

0 comments on commit 91c8719

Please sign in to comment.