Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created October 3, 2011 04:31
Show Gist options
  • Select an option

  • Save emasaka/1258444 to your computer and use it in GitHub Desktop.

Select an option

Save emasaka/1258444 to your computer and use it in GitHub Desktop.
make earthquake.gem to expand t.co URL (third party patch)
From de5e8c5038751a105a089b030716c883d8842758 Mon Sep 17 00:00:00 2001
From: emasaka <emasaka@gmail.com>
Date: Fri, 30 Sep 2011 20:46:49 +0900
Subject: [PATCH 1/2] expand t.co
---
lib/earthquake/output.rb | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/lib/earthquake/output.rb b/lib/earthquake/output.rb
index 8f7da08..7a35ce4 100644
--- a/lib/earthquake/output.rb
+++ b/lib/earthquake/output.rb
@@ -59,6 +59,17 @@ module Earthquake
def color_of(screen_name)
config[:colors][screen_name.delete("^0-9A-Za-z_").to_i(36) % config[:colors].size]
end
+
+ def expand_tco(text, entities)
+ if !entities || entities['urls'].empty?
+ text
+ else
+ entities['urls'].sort {|a, b| b['indices'][0] <=> a['indices'][0] }.inject(text.dup) do |r, u|
+ r[u['indices'][0]...u['indices'][1]] = u['expanded_url'] if u['expanded_url']
+ r
+ end
+ end
+ end
end
init do
@@ -93,7 +104,9 @@ module Earthquake
id = id2var(item["id"])
- text = (item["retweeted_status"] && item["truncated"] ? "RT @#{item["retweeted_status"]["user"]["screen_name"]}: #{item["retweeted_status"]["text"]}" : item["text"]).u
+ text = (item["retweeted_status"] && item["truncated"] ?
+ "RT @#{item["retweeted_status"]["user"]["screen_name"]}: #{expand_tco(item["retweeted_status"]["text"], item['entities'])}" :
+ expand_tco(item["text"], item['entities']) ).u
text.gsub!(/\s+/, ' ') unless config[:raw_text]
text = text.coloring(/@[0-9A-Za-z_]+/) { |i| color_of(i) }
text = text.coloring(/(^#[^\s]+)|(\s+#[^\s]+)/) { |i| color_of(i) }
--
1.7.6.3
From 70028a89f286d3a7d0ab7b49a5bf0e39a6f513cf Mon Sep 17 00:00:00 2001
From: emasaka <emasaka@gmail.com>
Date: Sat, 1 Oct 2011 12:58:06 +0900
Subject: [PATCH 2/2] expand t.co in some commands
---
lib/earthquake/commands.rb | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/earthquake/commands.rb b/lib/earthquake/commands.rb
index 7685b7e..cb9a3b1 100644
--- a/lib/earthquake/commands.rb
+++ b/lib/earthquake/commands.rb
@@ -60,7 +60,7 @@ Earthquake.init do
end
command :mentions do
- puts_items twitter.mentions
+ puts_items twitter.mentions(:include_entities => 1)
end
command :follow do |m|
@@ -72,12 +72,12 @@ Earthquake.init do
end
command :recent do
- puts_items twitter.home_timeline(:count => config[:recent_count])
+ puts_items twitter.home_timeline(:count => config[:recent_count], :include_entities => 1)
end
# :recent jugyo
command %r|^:recent\s+([^\/\s]+)$|, :as => :recent do |m|
- puts_items twitter.user_timeline(:screen_name => m[1])
+ puts_items twitter.user_timeline(:screen_name => m[1], :include_entities => 1)
end
# :recent yugui/ruby-committers
@@ -136,15 +136,15 @@ Earthquake.init do
end
command :retweeted_by_me do
- puts_items twitter.retweeted_by_me
+ puts_items twitter.retweeted_by_me(:include_entities => 1)
end
command :retweeted_to_me do
- puts_items twitter.retweeted_to_me
+ puts_items twitter.retweeted_to_me(:include_entities => 1)
end
command :retweets_of_me do
- puts_items twitter.retweets_of_me
+ puts_items twitter.retweets_of_me(:include_entities => 1)
end
command :block do |m|
--
1.7.6.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment