earthquake 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -3
- data/VERSION +1 -1
- data/earthquake.gemspec +1 -1
- data/lib/earthquake/commands.rb +18 -7
- data/lib/earthquake/input.rb +3 -1
- data/lib/earthquake/twitter.rb +17 -7
- metadata +1 -1
data/README.md
CHANGED
@@ -33,6 +33,11 @@ Commands
|
|
33
33
|
|
34
34
|
⚡ Hello World!
|
35
35
|
|
36
|
+
### Timeline
|
37
|
+
|
38
|
+
⚡ :recent
|
39
|
+
⚡ :recent twitter
|
40
|
+
|
36
41
|
### Searth
|
37
42
|
|
38
43
|
⚡ :search #ruby
|
@@ -157,12 +162,9 @@ The 'm' is a MatchData.
|
|
157
162
|
TODO
|
158
163
|
----
|
159
164
|
|
160
|
-
* unescape html
|
161
165
|
* dealing direct messages
|
162
166
|
* more intelligent completion
|
163
|
-
* caching statuses
|
164
167
|
* typable id
|
165
|
-
* request asynchronously
|
166
168
|
* spec
|
167
169
|
|
168
170
|
Copyright
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.6
|
data/earthquake.gemspec
CHANGED
data/lib/earthquake/commands.rb
CHANGED
@@ -55,12 +55,12 @@ module Earthquake
|
|
55
55
|
async { twitter.unfriend(m[1]) }
|
56
56
|
end
|
57
57
|
|
58
|
-
command :
|
59
|
-
puts_items twitter.
|
58
|
+
command :recent do
|
59
|
+
puts_items twitter.home_timeline.reverse
|
60
60
|
end
|
61
61
|
|
62
|
-
command :
|
63
|
-
puts_items twitter.
|
62
|
+
command :recent do |m|
|
63
|
+
puts_items twitter.user_timeline(:screen_name => m[1]).reverse
|
64
64
|
end
|
65
65
|
|
66
66
|
command :user do |m|
|
@@ -70,7 +70,7 @@ module Earthquake
|
|
70
70
|
command :search do |m|
|
71
71
|
puts_items twitter.search(m[1])["results"].each { |s|
|
72
72
|
s["user"] = {"screen_name" => s["from_user"]}
|
73
|
-
|
73
|
+
s["disable_cache"] = true
|
74
74
|
words = m[1].split(/\s+/).reject{|x| x[0] =~ /^-|^(OR|AND)$/ }.map{|x|
|
75
75
|
case x
|
76
76
|
when /^from:(.+)/, /^to:(.+)/
|
@@ -83,8 +83,19 @@ module Earthquake
|
|
83
83
|
}.reverse
|
84
84
|
end
|
85
85
|
|
86
|
-
command :retweet do |m|
|
87
|
-
|
86
|
+
command %r|^:retweet\s+(\d+)$|, :as => :retweet do |m|
|
87
|
+
target = twitter.status(m[1])
|
88
|
+
if confirm("retweet 'RT @#{target["user"]["screen_name"]}: #{target["text"].e}'")
|
89
|
+
async { twitter.retweet(m[1]) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
command %r|^:retweet\s+(\d+)\s+(.*)$|, :as => :retweet do |m|
|
94
|
+
target = twitter.status(m[1])
|
95
|
+
text = "#{m[2]} RT @#{target["user"]["screen_name"]}: #{target["text"].e} (#{target["id"]})"
|
96
|
+
if confirm("unofficial retweet '#{text}'")
|
97
|
+
async { twitter.update(text) }
|
98
|
+
end
|
88
99
|
end
|
89
100
|
|
90
101
|
command :favorite do |m|
|
data/lib/earthquake/input.rb
CHANGED
data/lib/earthquake/twitter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# NOTE: It's important to cache duped objects
|
1
2
|
module Earthquake
|
2
3
|
module Twitter
|
3
4
|
attr_reader :twitter
|
@@ -5,19 +6,28 @@ module Earthquake
|
|
5
6
|
|
6
7
|
init do
|
7
8
|
@twitter = TwitterOAuth::Client.new(config.slice(:consumer_key, :consumer_secret, :token, :secret))
|
9
|
+
|
10
|
+
filter do |item|
|
11
|
+
next if item["text"].nil? || item["disable_cache"]
|
12
|
+
Earthquake.cache.write("status:#{item["id"]}", item.dup, :expires_in => 1.hour.ago)
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
once do
|
11
17
|
class ::TwitterOAuth::Client
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
[:status, :info].each do |m|
|
19
|
+
define_method("#{m}_with_cache") do |*args|
|
20
|
+
key = "#{m}:#{args.join(',')}"
|
21
|
+
if result = Earthquake.cache.read(key)
|
22
|
+
result.dup
|
23
|
+
else
|
24
|
+
result = __send__(:"#{m}_without_cache", *args)
|
25
|
+
Earthquake.cache.write(key, result.dup, :expires_in => 1.hour.ago)
|
26
|
+
result
|
27
|
+
end
|
17
28
|
end
|
18
|
-
|
29
|
+
alias_method_chain m, :cache
|
19
30
|
end
|
20
|
-
alias_method_chain :status, :cache
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|