Skip to content

Instantly share code, notes, and snippets.

@jaspertandy
Created November 22, 2011 14:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaspertandy/1385833 to your computer and use it in GitHub Desktop.
Save jaspertandy/1385833 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']
end
end
end
text
end
end
@bric3
Copy link

bric3 commented Feb 9, 2012

Hi,

Thx for this plugin, it's working great. However I encounter the same erroneous behavior with the latest version of your script.
You said you modified the core, that would be interesting to know what you modified.

Here's the stacktrace that appear in the console for reference:

earthquake: [ERROR] can't convert nil into String
/Users/brice/.earthquake/plugin/expand_tco.rb:11:in `gsub!'
/Users/brice/.earthquake/plugin/expand_tco.rb:11:in `block (5 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1322:in `block (2 levels) in transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2671:in `reading_body'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1321:in `block in transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1293:in `request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1195:in `request_get'
/Users/brice/.earthquake/plugin/expand_tco.rb:10:in `block (4 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745:in `start'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:557:in `start'
/Users/brice/.earthquake/plugin/expand_tco.rb:9:in `block (3 levels) in <top (required)>'
/Users/brice/.earthquake/plugin/expand_tco.rb:7:in `each'
/Users/brice/.earthquake/plugin/expand_tco.rb:7:in `block (2 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `call'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `block (2 levels) in puts_items'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `each'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `any?'

@adamtomecek
Copy link

https://gist.github.com/3187216

Fixed problem I was getting with empty String with some links.

@valentinritz
Copy link

@adamtomecek Thank's a lot for this!

This solved the issue :)

@tribela
Copy link

tribela commented Mar 20, 2014

https://gist.github.com/Kjwon15/9657129

I fixed it doesn't applied for item object.

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