Class: Atig::IFilter::ExpandUrl

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/atig/ifilter/expand_url.rb

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Constructor Details

#initialize(context) ⇒ ExpandUrl

Returns a new instance of ExpandUrl.



11
12
13
14
15
16
# File 'lib/atig/ifilter/expand_url.rb', line 11

def initialize(context)
  @log  = context.log
  @opts = context.opts
  @http = Atig::Http.new @log
  @cache = Atig::SizedHash.new 100
end

Instance Method Details

#call(status) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/atig/ifilter/expand_url.rb', line 18

def call(status)
  target = short_url_regexp
  entities = (entities = status.entities).nil? ? [] : entities.urls
  status.merge :text => status.text.gsub(target) {|url|
    unless entities.nil? or entities.empty?
      @cache[url] ||= search_url_from_entities(url, entities)
      url = @cache[url] if @cache[url] =~ target
    end
    @cache[url] ||= resolve_http_redirect(URI(url)).to_s || url
  }
end