earthquake 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,6 +6,7 @@ Only supports Ruby 1.9.
6
6
 
7
7
  Homepage: [https://github.com/jugyo/earthquake](https://github.com/jugyo/earthquake)
8
8
  Twitter: [http://twitter.com/earthquakegem](http://twitter.com/earthquakegem)
9
+ Changelog'd: [earthquake: Twitter terminal client with streaming API support](http://thechangelog.com/post/4005924669/earthquake-twitter-client-on-terminal-with-streaming-api)
9
10
  Demo: [http://www.youtube.com/watch?v=S2KtBGrIe5c](http://www.youtube.com/watch?v=S2KtBGrIe5c)
10
11
  Slide: [http://www.slideshare.net/jugyo/earthquakegem](http://www.slideshare.net/jugyo/earthquakegem)
11
12
 
@@ -23,6 +24,16 @@ Features
23
24
  Install
24
25
  ----
25
26
 
27
+ You'll need openssl and readline support with your 1.9.2. If you are
28
+ using rvm you can run:
29
+
30
+ $ rvm pkg install openssl
31
+ $ rvm remove 1.9.2
32
+ $ rvm install 1.9.2 --with-openssl-dir=$HOME/.rvm/usr \
33
+ --with-readline-dir=$HOME/.rvm/usr
34
+
35
+ Then install the gem:
36
+
26
37
  $ gem install earthquake
27
38
 
28
39
  **Ubuntu:** EventMachine needs the package libssl-dev.
@@ -100,7 +111,7 @@ Commands
100
111
 
101
112
  ### Alias
102
113
 
103
- ⚡ :alias rt retweet
114
+ ⚡ :alias :rt :retweet
104
115
 
105
116
  And more!
106
117
 
@@ -133,6 +144,30 @@ You can change the directory at launch by entering a directory as an argument. F
133
144
  :url => [4, 34]
134
145
  }
135
146
 
147
+ ### Tracking specified keywords
148
+
149
+ # ~/.earthquake/config
150
+ Earthquake.config[:api] = {
151
+ :method => 'POST',
152
+ :host => 'stream.twitter.com',
153
+ :path => '/1/statuses/filter.json',
154
+ :ssl => true,
155
+ :filters => %w(Twitter Earthquake)
156
+ }
157
+
158
+ ### Tracking specified users
159
+
160
+ # ~/.earthquake/config
161
+ Earthquake.config[:api] = {
162
+ :method => 'POST',
163
+ :host => 'stream.twitter.com',
164
+ :path => '/1/statuses/filter.json',
165
+ :ssl => true,
166
+ :params => {
167
+ :follow => '6253282,183709371' # @twitterapi @sitestreams
168
+ }
169
+ }
170
+
136
171
  ### Defining aliases
137
172
 
138
173
  # ~/.earthquake/config
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.2
data/bin/earthquake CHANGED
@@ -2,13 +2,19 @@
2
2
  require 'slop'
3
3
 
4
4
  argv = ARGV.dup
5
- opts = Slop.parse! argv, :help => true do
6
- banner "Usage: earthquake [options] [directory]"
7
- on :d, :debug, 'Enable debug mode'
8
- on :n, :'no-logo', 'No Logo'
9
- on :c, :command, "Invoke an command and exit", true
5
+ slop = Slop.new(:strict => true, :help => true)
6
+ slop.banner "Usage: earthquake [options] [directory]"
7
+ slop.on :d, :debug, 'Enable debug mode'
8
+ slop.on :n, :'no-logo', 'No Logo'
9
+ slop.on :c, :command, "Invoke an command and exit", true
10
+ slop.on :l, :lolize, 'enable lolize (see: https://github.com/miaout17/lolize)'
11
+ begin
12
+ slop.parse!(argv)
13
+ rescue => e
14
+ puts e
15
+ exit!
10
16
  end
11
- options = opts.to_hash(true)
17
+ options = slop.to_hash(true)
12
18
  options.delete(:help)
13
19
  options[:dir] = argv.shift unless argv.empty?
14
20
 
@@ -20,6 +26,8 @@ $:.unshift eq_dir.join('lib') if $0 == __FILE__
20
26
  command = options.delete(:command)
21
27
  no_logo = options.delete(:'no-logo')
22
28
 
29
+ require 'lolize/auto' if options[:lolize]
30
+
23
31
  if !no_logo && !command
24
32
  print "\e[31m"
25
33
  puts %q{
data/earthquake.gemspec CHANGED
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{earthquake}
8
- s.version = "0.8.0"
7
+ s.name = "earthquake"
8
+ s.version = "0.8.2"
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-08-31}
13
- s.default_executable = %q{earthquake}
14
- s.description = %q{Twitter Client on Terminal with Twitter Streaming API.}
15
- s.email = %q{jugyo.org@gmail.com}
12
+ s.date = "2011-10-15"
13
+ s.description = "Twitter Client on Terminal with Twitter Streaming API."
14
+ s.email = "jugyo.org@gmail.com"
16
15
  s.executables = ["earthquake"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE.txt",
@@ -35,6 +34,7 @@ Gem::Specification.new do |s|
35
34
  "lib/earthquake/core.rb",
36
35
  "lib/earthquake/ext.rb",
37
36
  "lib/earthquake/get_access_token.rb",
37
+ "lib/earthquake/help.rb",
38
38
  "lib/earthquake/id_var.rb",
39
39
  "lib/earthquake/input.rb",
40
40
  "lib/earthquake/output.rb",
@@ -42,12 +42,12 @@ Gem::Specification.new do |s|
42
42
  "spec/earthquake_spec.rb",
43
43
  "spec/spec_helper.rb"
44
44
  ]
45
- s.homepage = %q{http://github.com/jugyo/earthquake}
45
+ s.homepage = "http://github.com/jugyo/earthquake"
46
46
  s.licenses = ["MIT"]
47
47
  s.require_paths = ["lib"]
48
48
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
49
- s.rubygems_version = %q{1.6.2}
50
- s.summary = %q{Twitter Client on Terminal.}
49
+ s.rubygems_version = "1.8.10"
50
+ s.summary = "Twitter Client on Terminal."
51
51
  s.test_files = [
52
52
  "spec/earthquake_spec.rb",
53
53
  "spec/spec_helper.rb"
data/lib/earthquake.rb CHANGED
@@ -24,6 +24,7 @@ Encoding.default_external = Encoding.find('UTF-8')
24
24
  input
25
25
  get_access_token
26
26
  twitter
27
+ help
27
28
  commands
28
29
  id_var
29
30
  ).each { |name| require_dependency File.expand_path("../earthquake/#{name}", __FILE__) }
@@ -2,14 +2,47 @@
2
2
  require 'uri'
3
3
  require 'open-uri'
4
4
  Earthquake.init do
5
+
6
+ # :exit
7
+
5
8
  command :exit do
6
9
  stop
7
10
  end
8
11
 
12
+ help :exit, 'exit from earthquake'
13
+
14
+ # :help
15
+
9
16
  command :help do
10
- system 'less', File.expand_path('../../../README.md', __FILE__)
17
+ summaries = {}
18
+ helps.each do |k, v|
19
+ summaries[k] = v[0]
20
+ end
21
+ ap summaries
11
22
  end
12
23
 
24
+ command :help do |m|
25
+ if help = helps[m[1].gsub(/^:/, '').to_sym]
26
+ summary, usage = *help
27
+ puts
28
+ puts "#{m[1]} - #{summary}".indent(4).c(92)
29
+ if usage
30
+ puts
31
+ puts usage.indent(4).c(92)
32
+ end
33
+ puts
34
+ else
35
+ ap nil
36
+ end
37
+ end
38
+
39
+ help :help, 'show help', <<-HELP
40
+ ⚡ :help
41
+ ⚡ :help :retweet
42
+ HELP
43
+
44
+ # :restart
45
+
13
46
  command :restart do
14
47
  puts 'restarting...'
15
48
  stop
@@ -18,10 +51,18 @@ Earthquake.init do
18
51
  exec File.expand_path('../../../bin/earthquake', __FILE__), *args
19
52
  end
20
53
 
54
+ help :restart, 'restart earthquake'
55
+
56
+ # :eval
57
+
21
58
  command :eval do |m|
22
59
  ap eval(m[1])
23
60
  end
24
61
 
62
+ help :eval, 'eval script', <<-HELP
63
+ ⚡ :eval 1 + 1
64
+ HELP
65
+
25
66
  command :update do |m|
26
67
  async_e { twitter.update(m[1]) } if confirm("update '#{m[1]}'")
27
68
  end
@@ -58,6 +58,7 @@ module Earthquake
58
58
  config[:consumer_secret] ||= 'V98dYYmWm9JoG7qfOF0jhJaVEVW3QhGYcDJ9JQSXU'
59
59
  config[:output_interval] ||= 1
60
60
  config[:history_size] ||= 1000
61
+ config[:api] ||= { :host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true }
61
62
 
62
63
  [config[:dir], config[:plugin_dir]].each do |dir|
63
64
  unless File.exists?(dir)
@@ -131,7 +132,7 @@ module Earthquake
131
132
 
132
133
  def reconnect
133
134
  item_queue.clear
134
- start_stream(:host => 'userstream.twitter.com', :path => '/2/user.json', :ssl => true)
135
+ start_stream(config[:api])
135
136
  end
136
137
 
137
138
  def start_stream(options)
@@ -32,6 +32,8 @@ end
32
32
 
33
33
  class String
34
34
  def c(*codes)
35
+ return self if Earthquake.config[:lolize]
36
+
35
37
  codes = codes.flatten.map { |code|
36
38
  case code
37
39
  when String, Symbol
@@ -44,6 +46,8 @@ class String
44
46
  end
45
47
 
46
48
  def coloring(pattern, color = nil, &block)
49
+ return self if Earthquake.config[:lolize]
50
+
47
51
  self.gsub(pattern) do |i|
48
52
  applied_colors = $`.scan(/\e\[[\d;]+m/)
49
53
  c = color || block.call(i)
@@ -66,4 +70,14 @@ class String
66
70
  define_method(:e) do
67
71
  gsub(/[#{t.keys.join}]/o, t)
68
72
  end
73
+
74
+ def indent(count, char = ' ')
75
+ (char * count) + gsub(/(\n+)/) { |m| m + (char * count) }
76
+ end
77
+
78
+ def trim_indent
79
+ lines = self.split("\n")
80
+ unindent = self.split("\n").select { |s| s !~ /^\s$/ }.map { |s| s.index(/[^\s]/) || 0 }.min
81
+ lines.map { |s| s.gsub(/^#{' ' * unindent}/, '') }.join("\n")
82
+ end
69
83
  end
@@ -0,0 +1,17 @@
1
+ module Earthquake
2
+ module Help
3
+ def helps
4
+ @helps ||= {}
5
+ end
6
+
7
+ def help(name, summary, usage = nil)
8
+ helps[name] = summary, usage ? usage.trim_indent : nil
9
+ end
10
+ end
11
+
12
+ init do
13
+ helps.clear
14
+ end
15
+
16
+ extend Help
17
+ end
@@ -30,8 +30,15 @@ module Earthquake
30
30
  end
31
31
 
32
32
  def puts_items(items)
33
+ mark_color = config[:colors].sample + 10
34
+
33
35
  [items].flatten.reverse_each do |item|
34
36
  next if output_filters.any? { |f| f.call(item) == false }
37
+
38
+ if item["text"] && !item["_stream"]
39
+ item['_mark'] = ' '.c(mark_color) + item['_mark'].to_s
40
+ end
41
+
35
42
  outputs.each do |o|
36
43
  begin
37
44
  o[:block].call(item)
@@ -121,8 +128,8 @@ module Earthquake
121
128
  output :delete do |item|
122
129
  if item["delete"] && cache.read("status:#{item["delete"]["status"]["id"]}")
123
130
  tweet = twitter.status(item["delete"]["status"]["id"])
124
- tweet["_mark"] = "[deleted]".c(:event) + ' '
125
- puts_items tweet
131
+ puts "[delete]".c(:event) +
132
+ " #{tweet["user"]["screen_name"]}: #{tweet["text"]}"
126
133
  end
127
134
  end
128
135
 
metadata CHANGED
@@ -1,160 +1,157 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: earthquake
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
4
5
  prerelease:
5
- version: 0.8.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - jugyo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-31 00:00:00 +09:00
14
- default_executable: earthquake
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: twitter-stream
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &17560420 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
23
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *17560420
25
+ - !ruby/object:Gem::Dependency
28
26
  name: notify
29
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &17559940 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :runtime
36
34
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *17559940
36
+ - !ruby/object:Gem::Dependency
39
37
  name: i18n
40
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &17559460 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
46
44
  type: :runtime
47
45
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *17559460
47
+ - !ruby/object:Gem::Dependency
50
48
  name: activesupport
51
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &17558980 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :runtime
58
56
  prerelease: false
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
57
+ version_requirements: *17558980
58
+ - !ruby/object:Gem::Dependency
61
59
  name: awesome_print
62
- requirement: &id005 !ruby/object:Gem::Requirement
60
+ requirement: &17558500 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
68
66
  type: :runtime
69
67
  prerelease: false
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *17558500
69
+ - !ruby/object:Gem::Dependency
72
70
  name: launchy
73
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ requirement: &17558020 !ruby/object:Gem::Requirement
74
72
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
79
77
  type: :runtime
80
78
  prerelease: false
81
- version_requirements: *id006
82
- - !ruby/object:Gem::Dependency
79
+ version_requirements: *17558020
80
+ - !ruby/object:Gem::Dependency
83
81
  name: oauth
84
- requirement: &id007 !ruby/object:Gem::Requirement
82
+ requirement: &17557540 !ruby/object:Gem::Requirement
85
83
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
90
88
  type: :runtime
91
89
  prerelease: false
92
- version_requirements: *id007
93
- - !ruby/object:Gem::Dependency
90
+ version_requirements: *17557540
91
+ - !ruby/object:Gem::Dependency
94
92
  name: twitter_oauth
95
- requirement: &id008 !ruby/object:Gem::Requirement
93
+ requirement: &17557060 !ruby/object:Gem::Requirement
96
94
  none: false
97
- requirements:
98
- - - "="
99
- - !ruby/object:Gem::Version
95
+ requirements:
96
+ - - =
97
+ - !ruby/object:Gem::Version
100
98
  version: 0.4.3
101
99
  type: :runtime
102
100
  prerelease: false
103
- version_requirements: *id008
104
- - !ruby/object:Gem::Dependency
101
+ version_requirements: *17557060
102
+ - !ruby/object:Gem::Dependency
105
103
  name: slop
106
- requirement: &id009 !ruby/object:Gem::Requirement
104
+ requirement: &17556580 !ruby/object:Gem::Requirement
107
105
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
112
110
  type: :runtime
113
111
  prerelease: false
114
- version_requirements: *id009
115
- - !ruby/object:Gem::Dependency
112
+ version_requirements: *17556580
113
+ - !ruby/object:Gem::Dependency
116
114
  name: rspec
117
- requirement: &id010 !ruby/object:Gem::Requirement
115
+ requirement: &17556100 !ruby/object:Gem::Requirement
118
116
  none: false
119
- requirements:
117
+ requirements:
120
118
  - - ~>
121
- - !ruby/object:Gem::Version
119
+ - !ruby/object:Gem::Version
122
120
  version: 2.3.0
123
121
  type: :development
124
122
  prerelease: false
125
- version_requirements: *id010
126
- - !ruby/object:Gem::Dependency
123
+ version_requirements: *17556100
124
+ - !ruby/object:Gem::Dependency
127
125
  name: bundler
128
- requirement: &id011 !ruby/object:Gem::Requirement
126
+ requirement: &17590360 !ruby/object:Gem::Requirement
129
127
  none: false
130
- requirements:
128
+ requirements:
131
129
  - - ~>
132
- - !ruby/object:Gem::Version
130
+ - !ruby/object:Gem::Version
133
131
  version: 1.0.0
134
132
  type: :development
135
133
  prerelease: false
136
- version_requirements: *id011
137
- - !ruby/object:Gem::Dependency
134
+ version_requirements: *17590360
135
+ - !ruby/object:Gem::Dependency
138
136
  name: jeweler
139
- requirement: &id012 !ruby/object:Gem::Requirement
137
+ requirement: &17589880 !ruby/object:Gem::Requirement
140
138
  none: false
141
- requirements:
139
+ requirements:
142
140
  - - ~>
143
- - !ruby/object:Gem::Version
141
+ - !ruby/object:Gem::Version
144
142
  version: 1.5.2
145
143
  type: :development
146
144
  prerelease: false
147
- version_requirements: *id012
145
+ version_requirements: *17589880
148
146
  description: Twitter Client on Terminal with Twitter Streaming API.
149
147
  email: jugyo.org@gmail.com
150
- executables:
148
+ executables:
151
149
  - earthquake
152
150
  extensions: []
153
-
154
- extra_rdoc_files:
151
+ extra_rdoc_files:
155
152
  - LICENSE.txt
156
153
  - README.md
157
- files:
154
+ files:
158
155
  - .document
159
156
  - .rspec
160
157
  - Gemfile
@@ -171,40 +168,38 @@ files:
171
168
  - lib/earthquake/core.rb
172
169
  - lib/earthquake/ext.rb
173
170
  - lib/earthquake/get_access_token.rb
171
+ - lib/earthquake/help.rb
174
172
  - lib/earthquake/id_var.rb
175
173
  - lib/earthquake/input.rb
176
174
  - lib/earthquake/output.rb
177
175
  - lib/earthquake/twitter.rb
178
176
  - spec/earthquake_spec.rb
179
177
  - spec/spec_helper.rb
180
- has_rdoc: true
181
178
  homepage: http://github.com/jugyo/earthquake
182
- licenses:
179
+ licenses:
183
180
  - MIT
184
181
  post_install_message:
185
182
  rdoc_options: []
186
-
187
- require_paths:
183
+ require_paths:
188
184
  - lib
189
- required_ruby_version: !ruby/object:Gem::Requirement
185
+ required_ruby_version: !ruby/object:Gem::Requirement
190
186
  none: false
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
194
190
  version: 1.9.1
195
- required_rubygems_version: !ruby/object:Gem::Requirement
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
192
  none: false
197
- requirements:
198
- - - ">="
199
- - !ruby/object:Gem::Version
200
- version: "0"
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
201
197
  requirements: []
202
-
203
198
  rubyforge_project:
204
- rubygems_version: 1.6.2
199
+ rubygems_version: 1.8.10
205
200
  signing_key:
206
201
  specification_version: 3
207
202
  summary: Twitter Client on Terminal.
208
- test_files:
203
+ test_files:
209
204
  - spec/earthquake_spec.rb
210
205
  - spec/spec_helper.rb