Module: ShorturlAt

Defined in:
lib/shorturl_at.rb,
lib/shorturl_at/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

SHORTEN_URL =
'https://www.shorturl.at/shortener.php'
TINY_URL =
'https://tinyurl.com/create.php'
VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.long_urlObject

Returns the value of attribute long_url.



13
14
15
# File 'lib/shorturl_at.rb', line 13

def long_url
  @long_url
end

Class Method Details

.shorten(long_url, method = '') ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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) ⇒ Object



41
42
43
# File 'lib/shorturl_at.rb', line 41

def shorten_rebrandly(long_url)

end

.shorten_tiny_url(long_url) ⇒ Object



32
33
34
35
36
37
38
39
# 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