Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created November 19, 2011 09:39
Show Gist options
  • Save hisasann/1378656 to your computer and use it in GitHub Desktop.
Save hisasann/1378656 to your computer and use it in GitHub Desktop.
bit.lyAPIのサンプル.rb
require "rubygems"
require "json"
require "net/http"
def shorten(long_url)
id = 'hisasann'
api_key = 'xxxxx'
query = "longUrl=#{long_url}&login=#{id}&apiKey=#{api_key}&format=json"
result = JSON.parse(Net::HTTP.get("api.bit.ly", "/v3/shorten?#{query}"))
return result["data"]["url"]
end
p shorten 'http://hisasann.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment