Last active
October 30, 2015 06:53
-
-
Save ArturLyapin/18b3286c3eec8d706b9f to your computer and use it in GitHub Desktop.
Request to Bitly
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
token = "your_secret_token" | |
long_url = "https://www.google.ru" | |
attributes = {:longUrl => long_url, :access_token => token} | |
uri = URI("https://api-ssl.bitly.com/v3/shorten?#{attributes.to_query}") | |
request = Net::HTTP::Get.new(uri) | |
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) {|http| http.request(request)} | |
JSON(response.body) | |
=> | |
{"status_code"=>200, | |
"status_txt"=>"OK", | |
"data"=>{"long_url"=>"https://www.google.ru/", | |
"url"=>"http://bit.ly/1KHrQET", | |
"hash"=>"1KHrQET", | |
"global_hash"=>"zusP6w", | |
"new_hash"=>0} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment