Last active
December 17, 2015 12:09
-
-
Save t11a/5607216 to your computer and use it in GitHub Desktop.
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
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