earthquake 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +20 -0
- data/README.md +30 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/earthquake +4 -0
- data/lib/earthquake.rb +13 -0
- data/lib/earthquake/core.rb +138 -0
- data/spec/earthquake_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +193 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'twitter-stream', :require => 'twitter/json_stream'
|
7
|
+
gem 'notify'
|
8
|
+
gem 'i18n'
|
9
|
+
gem 'activesupport', :require => 'active_support/core_ext'
|
10
|
+
gem 'awesome_print', :require => 'ap'
|
11
|
+
gem 'launchy'
|
12
|
+
gem 'oauth'
|
13
|
+
|
14
|
+
# Add dependencies to develop your gem here.
|
15
|
+
# Include everything needed to run rake, tests, features, etc.
|
16
|
+
group :development do
|
17
|
+
gem "rspec", "~> 2.3.0"
|
18
|
+
gem "bundler", "~> 1.0.0"
|
19
|
+
gem "jeweler", "~> 1.5.2"
|
20
|
+
gem "rcov", ">= 0"
|
21
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.5)
|
5
|
+
awesome_print (0.3.2)
|
6
|
+
configuration (1.2.0)
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
eventmachine (0.12.10)
|
9
|
+
git (1.2.5)
|
10
|
+
i18n (0.5.0)
|
11
|
+
jeweler (1.5.2)
|
12
|
+
bundler (~> 1.0.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
launchy (0.4.0)
|
16
|
+
configuration (>= 0.0.5)
|
17
|
+
rake (>= 0.8.1)
|
18
|
+
notify (0.3.0)
|
19
|
+
oauth (0.4.4)
|
20
|
+
rake (0.8.7)
|
21
|
+
rcov (0.9.9)
|
22
|
+
roauth (0.0.3)
|
23
|
+
rspec (2.3.0)
|
24
|
+
rspec-core (~> 2.3.0)
|
25
|
+
rspec-expectations (~> 2.3.0)
|
26
|
+
rspec-mocks (~> 2.3.0)
|
27
|
+
rspec-core (2.3.1)
|
28
|
+
rspec-expectations (2.3.0)
|
29
|
+
diff-lcs (~> 1.1.2)
|
30
|
+
rspec-mocks (2.3.0)
|
31
|
+
twitter-stream (0.1.12)
|
32
|
+
eventmachine (>= 0.12.8)
|
33
|
+
roauth (>= 0.0.2)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
activesupport
|
40
|
+
awesome_print
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
i18n
|
43
|
+
jeweler (~> 1.5.2)
|
44
|
+
launchy
|
45
|
+
notify
|
46
|
+
oauth
|
47
|
+
rcov
|
48
|
+
rspec (~> 2.3.0)
|
49
|
+
twitter-stream
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 jugyo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Earthquake
|
2
|
+
====
|
3
|
+
|
4
|
+
Twitter Client on Terminal with Streaming API.
|
5
|
+
|
6
|
+
Install
|
7
|
+
----
|
8
|
+
|
9
|
+
gem install earthquake
|
10
|
+
|
11
|
+
Usage
|
12
|
+
----
|
13
|
+
|
14
|
+
### Run
|
15
|
+
|
16
|
+
$ earthquake
|
17
|
+
|
18
|
+
TODO
|
19
|
+
----
|
20
|
+
|
21
|
+
* plugin system
|
22
|
+
* command
|
23
|
+
* filter
|
24
|
+
* colorize
|
25
|
+
* reconnect
|
26
|
+
|
27
|
+
Copyright
|
28
|
+
----
|
29
|
+
|
30
|
+
Copyright (c) 2011 jugyo. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "earthquake"
|
16
|
+
gem.homepage = "http://github.com/jugyo/earthquake"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Twitter Client on Terminal.}
|
19
|
+
gem.description = %Q{Twitter Client on Terminal with Twitter Streaming API.}
|
20
|
+
gem.email = "jugyo.org@gmail.com"
|
21
|
+
gem.authors = ["jugyo"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "earthquake #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/earthquake
ADDED
data/lib/earthquake.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
module Earthquake
|
2
|
+
module Core
|
3
|
+
attr_accessor :config
|
4
|
+
attr_reader :item_queue
|
5
|
+
|
6
|
+
def init(*argv)
|
7
|
+
# TODO: parse argv
|
8
|
+
self.config = {
|
9
|
+
:dir => File.expand_path('~/.earthquake'),
|
10
|
+
:consumer_key => 'qOdgatiUm6HIRcdoGVqaZg',
|
11
|
+
:consumer_secret => 'DHcL0bmS02vjSMHMrbFxCQqbDxh8yJZuLuzKviyFMo'
|
12
|
+
}
|
13
|
+
config[:file] ||= File.join(config[:dir], 'config')
|
14
|
+
load config[:file]
|
15
|
+
|
16
|
+
get_access_token unless self.config[:access_key] && self.config[:access_secret]
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_access_token
|
20
|
+
consumer = OAuth::Consumer.new(
|
21
|
+
self.config[:consumer_key],
|
22
|
+
self.config[:consumer_secret],
|
23
|
+
:site => 'http://api.twitter.com'
|
24
|
+
)
|
25
|
+
request_token = consumer.get_request_token
|
26
|
+
|
27
|
+
puts "1) open: #{request_token.authorize_url}"
|
28
|
+
Launchy::Browser.run(request_token.authorize_url)
|
29
|
+
|
30
|
+
print "2) Enter the PIN: "
|
31
|
+
pin = gets.strip
|
32
|
+
|
33
|
+
access_token = request_token.get_access_token(:oauth_verifier => pin)
|
34
|
+
config[:access_key] = access_token.token
|
35
|
+
config[:access_secret] = access_token.secret
|
36
|
+
|
37
|
+
puts "Saving 'access_key' and 'access_secret' to '#{config[:file]}'"
|
38
|
+
File.open(config[:file], 'a') do |f|
|
39
|
+
f << "\n"
|
40
|
+
f << "Earthquake.config[:access_key] = '#{config[:access_key]}'"
|
41
|
+
f << "\n"
|
42
|
+
f << "Earthquake.config[:access_secret] = '#{config[:access_secret]}'"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def start(*argv)
|
47
|
+
init(*argv)
|
48
|
+
|
49
|
+
@item_queue = []
|
50
|
+
|
51
|
+
Thread.abort_on_exception = true
|
52
|
+
|
53
|
+
Thread.start do
|
54
|
+
while buf = Readline.readline("[earthquake] ", true)
|
55
|
+
begin
|
56
|
+
buf = buf.strip
|
57
|
+
|
58
|
+
if buf == '/exit'
|
59
|
+
# TODO: refactor
|
60
|
+
@stream.stop if @stream
|
61
|
+
EventMachine.stop if EventMachine.reactor_running?
|
62
|
+
end
|
63
|
+
rescue => e
|
64
|
+
notify "[ERROR] #{e}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Thread.start do
|
70
|
+
loop do
|
71
|
+
# TODO: handle the response that include friends
|
72
|
+
if Readline.line_buffer.empty?
|
73
|
+
while item = item_queue.shift
|
74
|
+
begin
|
75
|
+
insert "#{item["user"]["screen_name"]}: #{item["text"]}"
|
76
|
+
rescue => e
|
77
|
+
insert do
|
78
|
+
ap item
|
79
|
+
end
|
80
|
+
# notify "[ERROR] #{e}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
sleep 1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
EventMachine::run {
|
89
|
+
@stream = Twitter::JSONStream.connect(
|
90
|
+
:ssl => true,
|
91
|
+
:host => 'userstream.twitter.com',
|
92
|
+
:path => '/2/user.json',
|
93
|
+
:oauth => config.slice(:consumer_key, :consumer_secret, :access_key, :access_secret)
|
94
|
+
)
|
95
|
+
|
96
|
+
@stream.each_item do |item|
|
97
|
+
item_queue << JSON.parse(item)
|
98
|
+
end
|
99
|
+
|
100
|
+
@stream.on_error do |message|
|
101
|
+
$stdout.print "error: #{message}\n"
|
102
|
+
$stdout.flush
|
103
|
+
end
|
104
|
+
|
105
|
+
@stream.on_reconnect do |timeout, retries|
|
106
|
+
$stdout.print "reconnecting in: #{timeout} seconds\n"
|
107
|
+
$stdout.flush
|
108
|
+
end
|
109
|
+
|
110
|
+
@stream.on_max_reconnects do |timeout, retries|
|
111
|
+
$stdout.print "Failed after #{retries} failed reconnects\n"
|
112
|
+
$stdout.flush
|
113
|
+
end
|
114
|
+
|
115
|
+
trap('TERM') {
|
116
|
+
@stream.stop
|
117
|
+
EventMachine.stop if EventMachine.reactor_running?
|
118
|
+
}
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def notify(message)
|
123
|
+
Notify.notify 'earthquake', message
|
124
|
+
end
|
125
|
+
|
126
|
+
def insert(*messages)
|
127
|
+
clear_line
|
128
|
+
puts messages unless messages.empty?
|
129
|
+
yield if block_given?
|
130
|
+
ensure
|
131
|
+
Readline.refresh_line
|
132
|
+
end
|
133
|
+
|
134
|
+
def clear_line
|
135
|
+
print "\e[0G" + "\e[K"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'earthquake'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: earthquake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jugyo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-16 00:00:00 +09:00
|
14
|
+
default_executable: earthquake
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: twitter-stream
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: notify
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: i18n
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: activesupport
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: awesome_print
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: launchy
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: oauth
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: rspec
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 2.3.0
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: bundler
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.0.0
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: jeweler
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.5.2
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rcov
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: "0"
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: *id011
|
137
|
+
description: Twitter Client on Terminal with Twitter Streaming API.
|
138
|
+
email: jugyo.org@gmail.com
|
139
|
+
executables:
|
140
|
+
- earthquake
|
141
|
+
extensions: []
|
142
|
+
|
143
|
+
extra_rdoc_files:
|
144
|
+
- LICENSE.txt
|
145
|
+
- README.md
|
146
|
+
files:
|
147
|
+
- .document
|
148
|
+
- .rspec
|
149
|
+
- Gemfile
|
150
|
+
- Gemfile.lock
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- VERSION
|
155
|
+
- bin/earthquake
|
156
|
+
- lib/earthquake.rb
|
157
|
+
- lib/earthquake/core.rb
|
158
|
+
- spec/earthquake_spec.rb
|
159
|
+
- spec/spec_helper.rb
|
160
|
+
has_rdoc: true
|
161
|
+
homepage: http://github.com/jugyo/earthquake
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
hash: 2067108568798120051
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
version: "0"
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: "0"
|
184
|
+
requirements: []
|
185
|
+
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 1.6.0
|
188
|
+
signing_key:
|
189
|
+
specification_version: 3
|
190
|
+
summary: Twitter Client on Terminal.
|
191
|
+
test_files:
|
192
|
+
- spec/earthquake_spec.rb
|
193
|
+
- spec/spec_helper.rb
|