1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# -*- coding: utf-8 -*-
# エンティティで展開しきれなかった t.co で短縮されたURLを展開する。
# http://www.gistlog.org/gist/1008272
require 'uri'
require 'net/http'
class TCo < MessageConverters
def plugin_name()
:tco
end
def shrink_url(url)
# 未対応
return url
end
def shrinked_url?(url)
!!(url =~ /http:\/\/t\.co\//)
end
def expand_url(url)
type_strict url => :to_s
hash = Hash.new
begin
res = timeout(5){ Net::HTTP.get_response(URI.parse(url.to_s)) }
if res.is_a?(Net::HTTPRedirection)
res["location"]
else
url.to_s end
rescue Exception => e
warn e
url.to_s
end
end
regist
end
|