earthquake 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +76 -2
- data/VERSION +1 -1
- data/earthquake.gemspec +8 -2
- data/lib/earthquake/commands.rb +57 -9
- data/lib/earthquake/core.rb +7 -8
- data/lib/earthquake/input.rb +7 -6
- data/lib/earthquake/output.rb +42 -19
- metadata +33 -11
data/README.md
CHANGED
@@ -13,17 +13,91 @@ Install
|
|
13
13
|
Usage
|
14
14
|
----
|
15
15
|
|
16
|
-
###
|
16
|
+
### Launch
|
17
17
|
|
18
18
|
$ earthquake
|
19
19
|
|
20
|
+
Commands
|
21
|
+
----
|
22
|
+
|
23
|
+
### Tweet
|
24
|
+
|
25
|
+
⚡ Hello World!
|
26
|
+
|
27
|
+
### Searth
|
28
|
+
|
29
|
+
⚡ :search #ruby
|
30
|
+
|
31
|
+
### Eval
|
32
|
+
|
33
|
+
⚡ :eval Time.now
|
34
|
+
|
35
|
+
### Exit
|
36
|
+
|
37
|
+
⚡ :exit
|
38
|
+
|
39
|
+
### Restart
|
40
|
+
|
41
|
+
⚡ :restart
|
42
|
+
|
43
|
+
And there are more commands!
|
44
|
+
|
45
|
+
Customize
|
46
|
+
----
|
47
|
+
|
48
|
+
The config file is '~/.earthquake/config'.
|
49
|
+
|
50
|
+
### Changing the colors
|
51
|
+
|
52
|
+
Earthquake.config[:colors] = (31..36).to_a - [34]
|
53
|
+
|
54
|
+
The blue is excluded.
|
55
|
+
|
56
|
+
### Running on debug mode
|
57
|
+
|
58
|
+
Earthquake.config[:debug] = true
|
59
|
+
|
60
|
+
デバッグモードで動作しているとき、コードの修正は即座に反映される(正確にはコマンドの実行の直前にリロードされる)。
|
61
|
+
|
62
|
+
### Defining your commands
|
63
|
+
|
64
|
+
A command named 'foo':
|
65
|
+
|
66
|
+
Earthquake.init do
|
67
|
+
command :foo do
|
68
|
+
puts "foo!"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Handle the command args:
|
73
|
+
|
74
|
+
Earthquake.init do
|
75
|
+
command :hi do |m|
|
76
|
+
puts "Hi #{m[1]}!"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
The 'm' is a MatchData.
|
81
|
+
|
82
|
+
Using regexp:
|
83
|
+
|
84
|
+
Earthquake.init do
|
85
|
+
# Usage: :add 10 20
|
86
|
+
command %r|^:add (\d+)\s+(\d+)|, :as => :add do |m|
|
87
|
+
puts m[1].to_i + m[2].to_i
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
20
91
|
TODO
|
21
92
|
----
|
22
93
|
|
23
94
|
* plugin system
|
24
|
-
|
95
|
+
* filter
|
25
96
|
* reconnect
|
26
97
|
* show more events
|
98
|
+
* show retweeted status id
|
99
|
+
* keyword tracking
|
100
|
+
* more intelligent completion
|
27
101
|
|
28
102
|
Copyright
|
29
103
|
----
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/earthquake.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{earthquake}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["jugyo"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-19}
|
13
13
|
s.default_executable = %q{earthquake}
|
14
14
|
s.description = %q{Twitter Client on Terminal with Twitter Streaming API.}
|
15
15
|
s.email = %q{jugyo.org@gmail.com}
|
@@ -61,6 +61,8 @@ Gem::Specification.new do |s|
|
|
61
61
|
s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
|
62
62
|
s.add_runtime_dependency(%q<launchy>, [">= 0"])
|
63
63
|
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<twitter_oauth>, [">= 0"])
|
65
|
+
s.add_runtime_dependency(%q<termcolor>, [">= 0"])
|
64
66
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
65
67
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
68
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -73,6 +75,8 @@ Gem::Specification.new do |s|
|
|
73
75
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
74
76
|
s.add_dependency(%q<launchy>, [">= 0"])
|
75
77
|
s.add_dependency(%q<oauth>, [">= 0"])
|
78
|
+
s.add_dependency(%q<twitter_oauth>, [">= 0"])
|
79
|
+
s.add_dependency(%q<termcolor>, [">= 0"])
|
76
80
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
77
81
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
82
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -86,6 +90,8 @@ Gem::Specification.new do |s|
|
|
86
90
|
s.add_dependency(%q<awesome_print>, [">= 0"])
|
87
91
|
s.add_dependency(%q<launchy>, [">= 0"])
|
88
92
|
s.add_dependency(%q<oauth>, [">= 0"])
|
93
|
+
s.add_dependency(%q<twitter_oauth>, [">= 0"])
|
94
|
+
s.add_dependency(%q<termcolor>, [">= 0"])
|
89
95
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
90
96
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
91
97
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/lib/earthquake/commands.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Earthquake
|
3
3
|
init do
|
4
|
-
command :exit do
|
4
|
+
command :exit do
|
5
5
|
stop
|
6
6
|
end
|
7
7
|
|
8
|
-
command :help do
|
8
|
+
command :help do
|
9
9
|
puts "TODO..."
|
10
10
|
end
|
11
11
|
|
12
|
-
command :restart do
|
12
|
+
command :restart do
|
13
13
|
puts 'restarting...'
|
14
14
|
exec File.expand_path('../../..//bin/earthquake', __FILE__)
|
15
15
|
end
|
@@ -19,23 +19,47 @@ module Earthquake
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# update
|
22
|
-
command %r|^[
|
23
|
-
twitter.update(m[0]) if confirm("'#{m[0]}'")
|
22
|
+
command %r|^[^:].*| do |m|
|
23
|
+
twitter.update(m[0]) if confirm("update '#{m[0]}'")
|
24
24
|
end
|
25
25
|
|
26
|
-
command %r
|
27
|
-
# TODO
|
28
|
-
|
26
|
+
command %r|^:reply (\d+)\s+(.*)|, :as => :reply do |m|
|
27
|
+
# TODO: fill the user name to reply
|
28
|
+
twitter.update(m[2], :in_reply_to_status_id => m[1]) if confirm("reply '#{m[2]}' to #{m[1]}")
|
29
29
|
end
|
30
30
|
|
31
31
|
command :status do |m|
|
32
|
-
|
32
|
+
puts_items twitter.status(m[1])
|
33
33
|
end
|
34
34
|
|
35
35
|
command :delete do |m|
|
36
36
|
twitter.status_destroy(m[1])
|
37
37
|
end
|
38
38
|
|
39
|
+
command :mentions do
|
40
|
+
puts_items twitter.mentions.reverse
|
41
|
+
end
|
42
|
+
|
43
|
+
command :follow do |m|
|
44
|
+
twitter.friend(m[1])
|
45
|
+
end
|
46
|
+
|
47
|
+
command :unfollow do |m|
|
48
|
+
twitter.unfriend(m[1])
|
49
|
+
end
|
50
|
+
|
51
|
+
command :list do |m|
|
52
|
+
puts_items twitter.user_timeline(:screen_name => m[1]).reverse
|
53
|
+
end
|
54
|
+
|
55
|
+
command :user do |m|
|
56
|
+
ap twitter.show(m[1]).slice(*%w(id screen_name name profile_image_url description url location time_zone lang protected))
|
57
|
+
end
|
58
|
+
|
59
|
+
command :search do |m|
|
60
|
+
puts_items twitter.search(m[1])["results"].each { |s| s["user"] = {"screen_name" => s["from_user"]} }.reverse
|
61
|
+
end
|
62
|
+
|
39
63
|
command :retweet do |m|
|
40
64
|
twitter.retweet(m[1])
|
41
65
|
end
|
@@ -47,5 +71,29 @@ module Earthquake
|
|
47
71
|
command :unfavorite do |m|
|
48
72
|
twitter.unfavorite(m[1])
|
49
73
|
end
|
74
|
+
|
75
|
+
command :retweeted_by_me do
|
76
|
+
puts_items twitter.retweeted_by_me.reverse
|
77
|
+
end
|
78
|
+
|
79
|
+
command :retweeted_to_me do
|
80
|
+
puts_items twitter.retweeted_to_me.reverse
|
81
|
+
end
|
82
|
+
|
83
|
+
command :retweets_of_me do
|
84
|
+
puts_items twitter.retweets_of_me.reverse
|
85
|
+
end
|
86
|
+
|
87
|
+
command :block do |m|
|
88
|
+
twitter.block(m[1])
|
89
|
+
end
|
90
|
+
|
91
|
+
command :unblock do |m|
|
92
|
+
twitter.unblock(m[1])
|
93
|
+
end
|
94
|
+
|
95
|
+
command :report_spam do |m|
|
96
|
+
twitter.report_spam(m[1])
|
97
|
+
end
|
50
98
|
end
|
51
99
|
end
|
data/lib/earthquake/core.rb
CHANGED
@@ -15,8 +15,9 @@ module Earthquake
|
|
15
15
|
inits << block
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def _init
|
19
|
+
load_config
|
20
|
+
inits.each { |block| class_eval(&block) }
|
20
21
|
inits.clear
|
21
22
|
end
|
22
23
|
|
@@ -24,11 +25,10 @@ module Earthquake
|
|
24
25
|
loaded = ActiveSupport::Dependencies.loaded.dup
|
25
26
|
ActiveSupport::Dependencies.clear
|
26
27
|
loaded.each { |lib| require_dependency lib }
|
27
|
-
|
28
|
+
_init
|
28
29
|
end
|
29
30
|
|
30
|
-
def load_config
|
31
|
-
# TODO: parse argv
|
31
|
+
def load_config
|
32
32
|
self.config = {
|
33
33
|
:dir => File.expand_path('~/.earthquake'),
|
34
34
|
:consumer_key => 'qOdgatiUm6HIRcdoGVqaZg',
|
@@ -41,9 +41,8 @@ module Earthquake
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def start(*argv)
|
44
|
-
|
45
|
-
|
46
|
-
init_all
|
44
|
+
# TODO: parse argv
|
45
|
+
_init
|
47
46
|
|
48
47
|
Thread.start do
|
49
48
|
while buf = Readline.readline("⚡ ", true)
|
data/lib/earthquake/input.rb
CHANGED
@@ -25,11 +25,15 @@ module Earthquake
|
|
25
25
|
def command(pattern, options = {}, &block)
|
26
26
|
if block
|
27
27
|
if pattern.is_a?(String) || pattern.is_a?(Symbol)
|
28
|
-
command_name = "
|
28
|
+
command_name = ":#{pattern}"
|
29
29
|
command_names << command_name
|
30
|
-
|
30
|
+
if block.arity > 0
|
31
|
+
pattern = %r|^#{command_name}\s+(.*)$|
|
32
|
+
else
|
33
|
+
pattern = %r|^#{command_name}$|
|
34
|
+
end
|
31
35
|
end
|
32
|
-
command_names << "
|
36
|
+
command_names << ":#{options[:as]}" if options[:as]
|
33
37
|
commands << {:pattern => pattern, :block => block}
|
34
38
|
else
|
35
39
|
commands.detect { |c| c[:name] == name }
|
@@ -54,9 +58,6 @@ module Earthquake
|
|
54
58
|
Readline.completion_proc = lambda { |text|
|
55
59
|
command_names.grep /^#{Regexp.quote(text)}/
|
56
60
|
}
|
57
|
-
|
58
|
-
config[:command_prefix] ||= '/'
|
59
|
-
|
60
61
|
commands.clear
|
61
62
|
end
|
62
63
|
|
data/lib/earthquake/output.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module Earthquake
|
2
3
|
module Output
|
3
4
|
def output
|
4
5
|
return if item_queue.empty?
|
5
6
|
insert do
|
6
7
|
while item = item_queue.shift
|
7
|
-
|
8
|
+
puts_items(item)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def puts_items(items)
|
14
|
+
[items].flatten.each do |item|
|
15
|
+
output_handers.each do |p|
|
16
|
+
begin
|
17
|
+
p.call(item)
|
18
|
+
rescue => e
|
19
|
+
puts e, e.backtrace
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
def output_handers
|
@@ -36,33 +43,49 @@ module Earthquake
|
|
36
43
|
end
|
37
44
|
|
38
45
|
def color_of(screen_name)
|
39
|
-
|
46
|
+
colors[screen_name.to_i(36) % colors.size]
|
47
|
+
end
|
48
|
+
|
49
|
+
def colors
|
50
|
+
config[:colors]
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
43
54
|
init do
|
44
55
|
output_handers.clear
|
45
56
|
|
46
|
-
config[:colors]
|
57
|
+
config[:colors] ||= (31..36).to_a + (91..96).to_a
|
47
58
|
|
48
59
|
output_hander do |item|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"<#{user_color}>#{item["user"]["screen_name"].e}</#{user_color}>: " +
|
58
|
-
"#{text}<90>#{misc.e}</90>"
|
59
|
-
puts status.t
|
60
|
+
next unless item["text"]
|
61
|
+
|
62
|
+
misc = (item["in_reply_to_status_id"] ? " (reply to #{item["in_reply_to_status_id"]})" : "")
|
63
|
+
source = item["source"] =~ />(.*)</ ? $1 : 'web'
|
64
|
+
user_color = color_of(item["user"]["screen_name"])
|
65
|
+
text = item["text"].e.gsub(/[@#]([0-9A-Za-z_]+)/) do |i|
|
66
|
+
c = color_of($1)
|
67
|
+
"<#{c}>#{i}</#{c}>"
|
60
68
|
end
|
69
|
+
status = "<90>[#{item["id"].to_s.e}]</90> " +
|
70
|
+
"<#{user_color}>#{item["user"]["screen_name"].e}</#{user_color}>: " +
|
71
|
+
"#{text}<90>#{misc.e} #{source.e}</90>"
|
72
|
+
puts status.t
|
61
73
|
end
|
62
74
|
|
63
75
|
output_hander do |item|
|
64
|
-
|
76
|
+
next unless item["event"]
|
77
|
+
|
78
|
+
case item["event"]
|
79
|
+
when "follow", "block", "unblock"
|
80
|
+
puts "[#{item["event"]}] #{item["source"]["screen_name"]} => #{item["target"]["screen_name"]}"
|
81
|
+
when "favorite", "unfavorite"
|
82
|
+
puts "[#{item["event"]}] #{item["source"]["screen_name"]} => #{item["target"]["screen_name"]} : #{item["target_object"]["text"]}"
|
83
|
+
when "delete"
|
65
84
|
puts "[deleted] #{item["delete"]["status"]["id"]}"
|
85
|
+
else
|
86
|
+
if config[:debug]
|
87
|
+
ap item
|
88
|
+
end
|
66
89
|
end
|
67
90
|
end
|
68
91
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: earthquake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- jugyo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-19 00:00:00 +09:00
|
14
14
|
default_executable: earthquake
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -91,8 +91,30 @@ dependencies:
|
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: *id007
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: twitter_oauth
|
95
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
type: :runtime
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: termcolor
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
type: :runtime
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rspec
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
96
118
|
none: false
|
97
119
|
requirements:
|
98
120
|
- - ~>
|
@@ -100,10 +122,10 @@ dependencies:
|
|
100
122
|
version: 2.3.0
|
101
123
|
type: :development
|
102
124
|
prerelease: false
|
103
|
-
version_requirements: *
|
125
|
+
version_requirements: *id010
|
104
126
|
- !ruby/object:Gem::Dependency
|
105
127
|
name: bundler
|
106
|
-
requirement: &
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
107
129
|
none: false
|
108
130
|
requirements:
|
109
131
|
- - ~>
|
@@ -111,10 +133,10 @@ dependencies:
|
|
111
133
|
version: 1.0.0
|
112
134
|
type: :development
|
113
135
|
prerelease: false
|
114
|
-
version_requirements: *
|
136
|
+
version_requirements: *id011
|
115
137
|
- !ruby/object:Gem::Dependency
|
116
138
|
name: jeweler
|
117
|
-
requirement: &
|
139
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
118
140
|
none: false
|
119
141
|
requirements:
|
120
142
|
- - ~>
|
@@ -122,10 +144,10 @@ dependencies:
|
|
122
144
|
version: 1.5.2
|
123
145
|
type: :development
|
124
146
|
prerelease: false
|
125
|
-
version_requirements: *
|
147
|
+
version_requirements: *id012
|
126
148
|
- !ruby/object:Gem::Dependency
|
127
149
|
name: rcov
|
128
|
-
requirement: &
|
150
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
129
151
|
none: false
|
130
152
|
requirements:
|
131
153
|
- - ">="
|
@@ -133,7 +155,7 @@ dependencies:
|
|
133
155
|
version: "0"
|
134
156
|
type: :development
|
135
157
|
prerelease: false
|
136
|
-
version_requirements: *
|
158
|
+
version_requirements: *id013
|
137
159
|
description: Twitter Client on Terminal with Twitter Streaming API.
|
138
160
|
email: jugyo.org@gmail.com
|
139
161
|
executables:
|
@@ -178,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
200
|
requirements:
|
179
201
|
- - ">="
|
180
202
|
- !ruby/object:Gem::Version
|
181
|
-
hash:
|
203
|
+
hash: 2518256249527376929
|
182
204
|
segments:
|
183
205
|
- 0
|
184
206
|
version: "0"
|