Skip to content

Instantly share code, notes, and snippets.

@uu59
Created July 18, 2011 09:55
Show Gist options
  • Save uu59/1089058 to your computer and use it in GitHub Desktop.
Save uu59/1089058 to your computer and use it in GitHub Desktop.
# -- coding: utf-8
=begin
goo.gl shortener plugin without API Keys.
It based on https://gist.github.com/905426
⚡ long long long long text over 140+ http://www.yahoo.co.jp/
update 'long long long long text over 140+ http://goo.gl/r5Pl' [Yn]
Or manually, following command is put shorten URLs into history
⚡ :googl http://yahoo.com/ http://www.msn.com/
update 'http://goo.gl/r5Pl http://goo.gl/8gCU' [Yn]
=end
require "uri"
require "net/http"
require "rubygems"
require "json"
Earthquake.init do
_ = config[:googl2] ||= {}
_[:only_long_tweet] ||= true
shorten = proc do |url|
res = Net::HTTP.post_form(
URI.parse("http://goo.gl/api/shorten"),
{"url" => url}
)
j = JSON.parse(res.body)
j["short_url"] || url
end
command :googl do |m|
s = m[1].split(/\s+/).map{|url| shorten.call(url) }.join(" ")
Readline::HISTORY.push(s)
input s
end
input_filter do |text|
if text =~ /^:(update|reply)/ && (!_[:only_long_tweet] || text.size > 140)
text.gsub(URI.regexp(['http','https'])) do |url|
shorten.call(url)
end
else
text
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment