Skip to content

Instantly share code, notes, and snippets.

@nitishn
Created March 19, 2014 00:20
Show Gist options
  • Save nitishn/9633032 to your computer and use it in GitHub Desktop.
Save nitishn/9633032 to your computer and use it in GitHub Desktop.
A "deffered" bitly URL shortener.
var utility = {
app_data: {
bitlyAccessToken: 'the-key',
bitlyBaseUrl: 'https://api-ssl.bitly.com',
vanityUrl: '',
},
shortenUrl: function( longUrl, deffered_object ) {
var that = this;
var requestUrl = '';
// build the request url
requestUrl = this.app_data.bitlyBaseUrl + '/v3/shorten?access_token=' + this.app_data.bitlyAccessToken + '&longUrl=' + longUrl;
// make bitly url request
$.getJSON(requestUrl, function(response) {
this.app_data.vanityUrl = response.data.url;
deffered_object.resolve();
});
}
}
// usage
utility.shortenUrl( giantUrl, new $.Deferred() ); // can pass in existing deffered object or just toss it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment