module ShorturlAt
Constants
- SHORTEN_URL
- TINY_URL
- VERSION
Attributes
long_url[RW]
Public Class Methods
shorten(long_url, method='')
click to toggle source
# File lib/shorturl_at.rb, line 15 def shorten(long_url, method='') case method when 'tinyurl' shorten_tiny_url(long_url) when 'rebrandly' shorten_rebrandly else response = HTTP.post(SHORTEN_URL, :form => {:u => long_url}) if response.status.success? doc = Nokogiri::HTML(response.body.to_s) short_url = doc.at('input#shortenurl')['value'] short_url = "http://#{short_url}" end short_url end end
shorten_rebrandly(long_url)
click to toggle source
# File lib/shorturl_at.rb, line 41 def shorten_rebrandly(long_url) end
shorten_tiny_url(long_url)
click to toggle source
# File lib/shorturl_at.rb, line 32 def shorten_tiny_url(long_url) response = HTTP.post(TINY_URL, :form => {:url => long_url}) if response.status.success? doc = Nokogiri::HTML(response.body.to_s) short_url = doc.at('a#copy_div')['href'] end short_url end