Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created June 18, 2013 16:25
Show Gist options
  • Select an option

  • Save jswhisperer/5806892 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/5806892 to your computer and use it in GitHub Desktop.
URL shortener with google and coffeescript
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