Skip to content

Instantly share code, notes, and snippets.

@adamtomecek
Forked from jaspertandy/expand_tco.rb
Created July 27, 2012 10:02
Show Gist options
  • Save adamtomecek/3187216 to your computer and use it in GitHub Desktop.
Save adamtomecek/3187216 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
Earthquake.init do
output_filter do |item|
next unless item['text']
text = item["text"]
text.scan( /http:\/\/t\.co\/[a-zA-Z0-9\-]+/ ).each do |url|
uri = URI.parse url
Net::HTTP::start( uri.host , uri.port ) do |connection|
connection.request_get uri.path do |response|
text.gsub! url , response['Location'] unless response['Location'].nil?
end
end
end
text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment