module URI
Constants
- URL_SHORTENINGS
Public Instance Methods
expand()
click to toggle source
短縮URLを展開
# File lib/twitter_image_parser/core_ext/uri.rb, line 5 def expand uri = self host = uri.host while URL_SHORTENINGS.any? { |val| val == host } next_uri = Net::HTTP.new(uri.host, uri.port).get(uri.path).header['location'] break if next_uri.blank? # 最終URLが上記ドメインの場合もあるため uri = URI.parse(next_uri) host = uri.host end uri end
img_url()
click to toggle source
画像投稿URLから画像パスを取得
# File lib/twitter_image_parser/core_ext/uri.rb, line 19 def img_url img_url = nil if self.host == 'twitpic.com' img_url = self.to_s.gsub("twitpic.com/", "twitpic.com/show/full/") elsif self.host == 'p.twipple.jp' img_url = self.to_s.gsub("p.twipple.jp/", "p.twpl.jp/show/orig/") elsif self.host == 'ow.ly' img_url = self.to_s.gsub("ow.ly/i/", "static.ow.ly/photos/original/")+'.jpg' elsif self.host == 'photozou.jp' img_url = self.to_s.gsub(/photozou\.jp\/photo\/show\/(\d)+\//, "photozou.jp/p/img/") elsif self.host == 'instagram.com' img_url = self.to_s + 'media/?size=l' elsif self.host == 'f.hatena.ne.jp' img_url = self.to_s.gsub(/f\.hatena.ne.jp\/(.+)\/(\d{8})(\d+)/) {"f.st-hatena.com/images/fotolife/#{$1[0,1]}/#{$1}/#{$2}/#{$2}#{$3}.jpg"} end img_url end