Created
March 19, 2014 00:20
-
-
Save nitishn/9633032 to your computer and use it in GitHub Desktop.
A "deffered" bitly URL shortener.
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 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