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 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.5
1
+ 0.4.6
data/earthquake.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{earthquake}
8
- s.version = "0.4.5"
8
+ s.version = "0.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
@@ -55,12 +55,12 @@ module Earthquake
55
55
  async { twitter.unfriend(m[1]) }
56
56
  end
57
57
 
58
- command :list do |m|
59
- puts_items twitter.user_timeline(:screen_name => m[1]).reverse
58
+ command :recent do
59
+ puts_items twitter.home_timeline.reverse
60
60
  end
61
61
 
62
- command :home do
63
- puts_items twitter.home_timeline.reverse
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
- }.each {|s|
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
- async { twitter.retweet(m[1]) }
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|
@@ -1,4 +1,6 @@
1
1
  # encoding: UTF-8
2
+ require 'set'
3
+
2
4
  module Earthquake
3
5
  module Input
4
6
  def commands
@@ -6,7 +8,7 @@ module Earthquake
6
8
  end
7
9
 
8
10
  def command_names
9
- @command_names ||= []
11
+ @command_names ||= Set.new
10
12
  end
11
13
 
12
14
  def completions
@@ -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
- def status_with_cache(id)
13
- key = "status:#{id}"
14
- unless s = Earthquake.cache.read(key)
15
- s = status_without_cache(id)
16
- Earthquake.cache.write(key, s, :expires_in => 1.hour.ago)
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
- s.dup
29
+ alias_method_chain m, :cache
19
30
  end
20
- alias_method_chain :status, :cache
21
31
  end
22
32
  end
23
33
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earthquake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.5
5
+ version: 0.4.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo