Skip to content

Instantly share code, notes, and snippets.

@ArturLyapin
Last active October 30, 2015 06:53
Show Gist options
  • Save ArturLyapin/18b3286c3eec8d706b9f to your computer and use it in GitHub Desktop.
Save ArturLyapin/18b3286c3eec8d706b9f to your computer and use it in GitHub Desktop.
Request to Bitly
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