Skip to content

Instantly share code, notes, and snippets.

@jimmyjacobson
Created September 17, 2011 16:24
Show Gist options
  • Save jimmyjacobson/1224098 to your computer and use it in GitHub Desktop.
Save jimmyjacobson/1224098 to your computer and use it in GitHub Desktop.
var params = {
login: this.login,
apiKey: this.apiKey,
longUrl: encodeURIComponent(longUrl)
};
var qs = [];
for(var key in params) {
qs.push(key + '=' + params[key]);
}
qs = qs.join('&');
var options = {
host: 'api.bitly.com',
port: 80,
path: '/v3/shorten?' + qs
}
http.get(options, function(response) {
response.on('data', function(chunk) {
var json = JSON.parse(chunk);
console.log(JSON.parse(chunk));
if (json.status_code != '200') {
var err = 'Bitly responded with ' + json.status_code + ':' +
json.status_txt;
}
callback(err, json.data);
});
}).on('error', function(e) {
console.log('BITLY:ERROR:' + e);
callback(e, {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment