Created
June 18, 2013 16:25
-
-
Save jswhisperer/5806892 to your computer and use it in GitHub Desktop.
URL shortener with google and coffeescript
This file contains hidden or 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
| apikey = "YOUR GOOGLE API KEY GOES HERE" | |
| shorten_url = (url, success_callback, error_callback) -> | |
| xhr = Titanium.Network.createHTTPClient() | |
| xhr.open "POST", "https://www.googleapis.com/urlshortener/v1/url?key=" + apikey | |
| xhr.setRequestHeader "Content-type", "application/json" | |
| xhr.onload = () -> success_callback xhr.status, xhr.responseText | |
| xhr.onerror = () -> error_callback xhr.status, xhr.responseText | |
| content = "{\"longUrl\": \"#{url}\"}" | |
| xhr.send content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment