Skip to content

Instantly share code, notes, and snippets.

@conmame
Created March 20, 2012 08:17
Show Gist options
  • Save conmame/2132731 to your computer and use it in GitHub Desktop.
Save conmame/2132731 to your computer and use it in GitHub Desktop.
open t.co url
# -*- encoding: utf-8 -*-
require "net/http"
require "uri"
class OpenTcoUrl
def initialize; end
def open_tco_url tco_url
result = []
tco_url.each do |t|
next unless t =~ /^http:\/\/t.co\/.*$/
uri = URI.parse(t)
Net::HTTP.start(uri.host, uri.port){|http|
header = {
"user-agent" => "Ruby/#{RUBY_VERSION} open t.co"
}
response = http.head(uri.path, header)
result << response["location"]
}
end
result
end
end
@conmame
Copy link
Author

conmame commented Mar 20, 2012

t = OpenTcoUrl.new
full_url = t.open_tco_url ARGV

ruby fileName.rb http://t.co/hogehoge http://t.co/hoge ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment