Skip to content

Instantly share code, notes, and snippets.

@t11a
Last active December 17, 2015 12:09
Show Gist options
  • Save t11a/5607216 to your computer and use it in GitHub Desktop.
Save t11a/5607216 to your computer and use it in GitHub Desktop.
require "rest_client"
def url_shortener(url)
res=""
key = "API_KEY_DAYO"
host = "https://www.googleapis.com/urlshortener/v1/url"
params = {
longUrl: url,
key: key
}
begin
response = RestClient.post host, params.to_json, content_type: "application/json"
parsed = JSON.parse(response)
res = parsed["id"]
rescue => e
puts "#{e.response}"
end
res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment