Created
September 17, 2011 16:24
-
-
Save jimmyjacobson/1224098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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