Class: Atig::OFilter::ShortUrl
- Inherits:
-
Object
- Object
- Atig::OFilter::ShortUrl
- Defined in:
- lib/atig/ofilter/short_url.rb
Constant Summary collapse
- MIN_LEN =
20
Instance Method Summary collapse
- #call(status) ⇒ Object
-
#initialize(context) ⇒ ShortUrl
constructor
A new instance of ShortUrl.
- #short_urls(mesg) ⇒ Object
Constructor Details
#initialize(context) ⇒ ShortUrl
Returns a new instance of ShortUrl.
11 12 13 14 15 |
# File 'lib/atig/ofilter/short_url.rb', line 11 def initialize(context) @log = context.log @opts = context.opts @http = Atig::Http.new @log end |
Instance Method Details
#call(status) ⇒ Object
17 18 19 20 |
# File 'lib/atig/ofilter/short_url.rb', line 17 def call(status) mesg = status[:status] status.merge(:status => short_urls(mesg)) end |
#short_urls(mesg) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/atig/ofilter/short_url.rb', line 22 def short_urls(mesg) shorten = case when @opts.bitlify.to_s.include?(":") login, key, len = @opts.bitlify.to_s.split(":", 3) @len = (len || MIN_LEN).to_i Bitly.login @log, login, key when @opts.bitlify @len = (@opts.bitlify.to_s || MIN_LEN).to_i Bitly.no_login @log when @opts.unuify @len = (@opts.unuify.to_s || MIN_LEN).to_i Unu.new @log else return mesg end mesg.gsub(URI.regexp(%w[http https])) do|url| if URI.rstrip(url).size < @len then url else shorten.shorten url end end end |