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
Instance Method Details
#call(status) ⇒ Object
16 17 18 19 |
# File 'lib/atig/ofilter/short_url.rb', line 16 def call(status) mesg = status[:status] status.merge(:status => short_urls(mesg)) end |
#short_urls(mesg) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/atig/ofilter/short_url.rb', line 21 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 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 |