Class: Atig::Unu
- Inherits:
-
Object
- Object
- Atig::Unu
- Defined in:
- lib/atig/unu.rb
Instance Method Summary collapse
-
#initialize(logger) ⇒ Unu
constructor
A new instance of Unu.
- #shorten(url) ⇒ Object
Constructor Details
Instance Method Details
#shorten(url) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/atig/unu.rb', line 9 def shorten(url) unu_url = "http://u.nu/" unu = URI("#{unu_url}unu-api-simple") url = URI.rstrip url unu.query = { :url => url }.to_query_str res = @http.http(unu, 5, 5).request(@http.req(:get, unu)).body if res[0, 12] == unu_url res else @log.error res url end rescue Errno::ETIMEDOUT, JSON::ParserError, IOError, Timeout::Error, Errno::ECONNRESET => e @log.error e url end |