Class: Puny
- Inherits:
-
Object
- Object
- Puny
- Defined in:
- lib/puny.rb
Overview
Puny
Holds the methods available on the Puny API
Constant Summary collapse
- TO_PUNY =
'http://services.sapo.pt/PunyURL/GetCompressedURLByURL'- FROM_PUNY =
'http://services.sapo.pt/PunyURL/GetURLByCompressedURL'
Class Method Summary collapse
-
.expand(url) ⇒ Object
Expands a puny URL to the original URL.
-
.shorten(url) ⇒ Object
Shortens a URL.
Class Method Details
.expand(url) ⇒ Object
Expands a puny URL to the original URL
Returns a String instance with the original URL or nil if there was an error
Example:
require 'puny'
puts Puny.('http://b.ot.sl.pt')
53 54 55 56 57 |
# File 'lib/puny.rb', line 53 def self.(url) url = FROM_PUNY + '?url=' + CGI.escape(url) p = _process_response(open(url)) p.url end |
.shorten(url) ⇒ Object
Shortens a URL
Returns a PunyURL instance with the shortened version of the URL, or nil if there was an error
Example:
require 'puny'
puny = Puny.shorten('http://developers.sapo.pt')
puts puny.puny
puts puny.url
38 39 40 41 |
# File 'lib/puny.rb', line 38 def self.shorten(url) url = TO_PUNY + '?url=' + CGI.escape(url) _process_response(open(url)) end |