module ShortUri
Constants
- VERSION
Public Class Methods
get_shorten_url(long_url, access_token, options = {})
click to toggle source
# File lib/short_uri.rb, line 8 def self.get_shorten_url(long_url, access_token, options = {}) uri = URI.parse('https://api-ssl.bitly.com'.concat('/v3/shorten?'.concat({:longUrl => long_url, :access_token => access_token}.merge(options).collect { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')))) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) res = https.request(request) begin sh_uri = JSON.parse(res.body)['data']['url'] rescue long_url end if sh_uri =~ URI::regexp sh_uri else long_url end end