termtter 0.8.13 → 0.8.14
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/Rakefile +10 -0
- data/lib/plugin/standard_plugins.rb +36 -55
- data/lib/termtter/client.rb +8 -4
- data/lib/termtter/twitter.rb +17 -6
- data/lib/termtter/version.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -45,3 +45,13 @@ desc 'Generate gem'
|
|
45
45
|
task :gem => :gemspec do |t|
|
46
46
|
system 'gem', 'build', 'termtter.gemspec'
|
47
47
|
end
|
48
|
+
|
49
|
+
namespace :gem do
|
50
|
+
desc 'Install needed gems'
|
51
|
+
task :install do
|
52
|
+
%w[ json_pure configatron highline termcolor ].each do |gem|
|
53
|
+
sh "sudo gem install #{gem} -r"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -60,7 +60,7 @@ module Termtter::Client
|
|
60
60
|
:exec_proc => lambda {|arg|
|
61
61
|
followers = Termtter::API.twitter.followers
|
62
62
|
Termtter::Client.public_storage[:followers] = followers
|
63
|
-
|
63
|
+
puts followers.map{|f|f.screen_name}.join(' ')
|
64
64
|
}
|
65
65
|
)
|
66
66
|
|
@@ -95,17 +95,31 @@ module Termtter::Client
|
|
95
95
|
register_command(
|
96
96
|
:name => :show,
|
97
97
|
:exec_proc => lambda {|arg|
|
98
|
-
id = arg.gsub(
|
98
|
+
id = arg.gsub(/.*:\s*/, '')
|
99
99
|
call_hooks(Termtter::API.twitter.show(id), :show)
|
100
|
+
},
|
101
|
+
:completion_proc => lambda {|cmd, arg|
|
102
|
+
case arg
|
103
|
+
when /(\w+):\s*(\d+)\s*$/
|
104
|
+
find_status_ids($2).map{|id| "#{cmd} #{$1}: #{id}"}
|
105
|
+
else
|
106
|
+
users = find_users(arg)
|
107
|
+
unless users.empty?
|
108
|
+
users.map{|user| "#{cmd} #{user}:"}
|
109
|
+
else
|
110
|
+
find_status_ids(arg).map{|id| "#{cmd} #{id}"}
|
111
|
+
end
|
112
|
+
end
|
100
113
|
}
|
101
114
|
)
|
102
115
|
|
103
116
|
register_command(
|
104
117
|
:name => :shows,
|
105
118
|
:exec_proc => lambda {|arg|
|
106
|
-
id = arg.gsub(
|
119
|
+
id = arg.gsub(/.*:\s*/, '')
|
107
120
|
call_hooks(Termtter::API.twitter.show(id, true), :show)
|
108
|
-
}
|
121
|
+
},
|
122
|
+
:completion_proc => get_command(:show).completion_proc
|
109
123
|
)
|
110
124
|
|
111
125
|
# TODO: Change colors when remaining_hits is low.
|
@@ -158,6 +172,7 @@ module Termtter::Client
|
|
158
172
|
register_command(
|
159
173
|
:name => :help, :aliases => [:h],
|
160
174
|
:exec_proc => lambda {|arg|
|
175
|
+
# TODO: move to each commands
|
161
176
|
helps = [
|
162
177
|
["help,h", "Print this help message"],
|
163
178
|
["list,l", "List the posts in your friends timeline"],
|
@@ -177,32 +192,19 @@ module Termtter::Client
|
|
177
192
|
)
|
178
193
|
|
179
194
|
register_command(
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
end
|
190
|
-
},
|
191
|
-
:help => ['execute COMMAND', 'execute the command']
|
192
|
-
)
|
193
|
-
|
194
|
-
add_command /^!(!)?\s*(.*)$/ do |m, t|
|
195
|
-
warn '!COMMAND command will be removed. Use command execute instead.'
|
196
|
-
begin
|
197
|
-
result = `#{m[2]}` unless m[2].empty?
|
198
|
-
unless m[1].nil? || result.empty?
|
199
|
-
t.update_status(result.gsub("\n", " "))
|
195
|
+
:name => :execute,
|
196
|
+
:exec_proc => lambda{|arg|
|
197
|
+
if arg
|
198
|
+
`#{arg}`.each_line do |line|
|
199
|
+
unless line.strip.empty?
|
200
|
+
Termtter::API.twitter.update_status(line)
|
201
|
+
puts "=> #{line}"
|
202
|
+
end
|
200
203
|
end
|
201
|
-
puts "=> #{result}"
|
202
|
-
rescue => e
|
203
|
-
puts e
|
204
204
|
end
|
205
|
-
|
205
|
+
},
|
206
|
+
:help => ['execute COMMAND', 'execute the command']
|
207
|
+
)
|
206
208
|
|
207
209
|
def self.formatted_help(helps)
|
208
210
|
helps = helps.sort_by{|help| help[0]}
|
@@ -228,17 +230,12 @@ module Termtter::Client
|
|
228
230
|
end
|
229
231
|
end
|
230
232
|
|
231
|
-
def self.
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
candidates
|
238
|
-
else
|
239
|
-
candidates.grep(/#{Regexp.quote a}/)
|
240
|
-
end.
|
241
|
-
map {|u| b % u }
|
233
|
+
def self.find_status_ids(text)
|
234
|
+
public_storage[:status_ids].select{|id| id =~ /#{Regexp.quote(text)}/}
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.find_users(text)
|
238
|
+
public_storage[:users].select{|user| user =~ /#{Regexp.quote(text)}/}
|
242
239
|
end
|
243
240
|
|
244
241
|
def self.find_user_candidates(a, b)
|
@@ -250,20 +247,4 @@ module Termtter::Client
|
|
250
247
|
map {|u| b % u }
|
251
248
|
end
|
252
249
|
|
253
|
-
add_completion do |input|
|
254
|
-
standard_commands = %w[exit help list pause profile update direct resume replies search show limit]
|
255
|
-
case input
|
256
|
-
when /^show(s)?\s+(([\w\d]+):)?\s*(.*)/
|
257
|
-
if $2
|
258
|
-
find_status_id_candidates $4, "show#{$1} #{$2}%s", $3
|
259
|
-
else
|
260
|
-
result = find_user_candidates $4, "show#{$1} %s:"
|
261
|
-
result = find_status_id_candidates $4, "show#{$1} %s" if result.empty?
|
262
|
-
result
|
263
|
-
end
|
264
|
-
else
|
265
|
-
standard_commands.grep(/^#{Regexp.quote input}/)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
250
|
end
|
data/lib/termtter/client.rb
CHANGED
@@ -23,6 +23,7 @@ module Termtter
|
|
23
23
|
configatron.set_default(:prompt, '> ')
|
24
24
|
configatron.set_default(:enable_ssl, false)
|
25
25
|
configatron.proxy.set_default(:port, '8080')
|
26
|
+
configatron.set_default(:devel, false)
|
26
27
|
Thread.abort_on_exception = true
|
27
28
|
end
|
28
29
|
|
@@ -209,10 +210,6 @@ module Termtter
|
|
209
210
|
def load_default_plugins
|
210
211
|
plugin 'standard_plugins'
|
211
212
|
plugin 'stdout'
|
212
|
-
configatron.set_default(:devel, false)
|
213
|
-
if configatron.devel
|
214
|
-
plugin 'devel'
|
215
|
-
end
|
216
213
|
end
|
217
214
|
|
218
215
|
def load_config
|
@@ -256,6 +253,12 @@ module Termtter
|
|
256
253
|
end
|
257
254
|
end
|
258
255
|
|
256
|
+
def pre_config_load()
|
257
|
+
if configatron.devel
|
258
|
+
plugin 'devel'
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
259
262
|
def setup_readline
|
260
263
|
if Readline.respond_to?(:basic_word_break_characters=)
|
261
264
|
Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
|
@@ -339,6 +342,7 @@ module Termtter
|
|
339
342
|
load_default_plugins()
|
340
343
|
load_config()
|
341
344
|
Termtter::API.setup()
|
345
|
+
pre_config_load()
|
342
346
|
|
343
347
|
call_hooks([], :initialize)
|
344
348
|
call_new_hooks(:initialize)
|
data/lib/termtter/twitter.rb
CHANGED
@@ -44,10 +44,14 @@ module Termtter
|
|
44
44
|
def get_user_timeline(screen_name)
|
45
45
|
return get_timeline(url_for("/statuses/user_timeline/#{screen_name}.json"))
|
46
46
|
rescue OpenURI::HTTPError => e
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
case e.message
|
48
|
+
when /404/
|
49
|
+
warn "No such user: #{screen_name}"
|
50
|
+
nears = near_users(screen_name)
|
51
|
+
puts "near users: #{nears}" unless nears.empty?
|
52
|
+
return []
|
53
|
+
end
|
54
|
+
raise
|
51
55
|
end
|
52
56
|
|
53
57
|
configatron.search.set_default(:highlihgt_text_format, '<on_magenta><white>\1</white></on_magenta>')
|
@@ -69,8 +73,8 @@ module Termtter
|
|
69
73
|
get_status = lambda { get_timeline(url_for("/statuses/show/#{id}.json"))[0] }
|
70
74
|
statuses = []
|
71
75
|
statuses << status = Array(Client.public_storage[:log]).detect(get_status) {|s| s.id == id.to_i }
|
72
|
-
statuses << show(id, true) if rth && id = status.in_reply_to_status_id
|
73
|
-
statuses.flatten
|
76
|
+
statuses << show(id, true) if rth && status && id = status.in_reply_to_status_id
|
77
|
+
statuses.flatten.compact
|
74
78
|
end
|
75
79
|
|
76
80
|
def replies
|
@@ -130,6 +134,13 @@ module Termtter
|
|
130
134
|
|
131
135
|
def fetch_as_json(uri)
|
132
136
|
JSON.parse(open_uri(uri).read)
|
137
|
+
rescue OpenURI::HTTPError => e
|
138
|
+
case e.message
|
139
|
+
when /403/, /401/
|
140
|
+
warn '[PROTECTED USER] You must add to show his/her tweet.'
|
141
|
+
return []
|
142
|
+
end
|
143
|
+
raise
|
133
144
|
end
|
134
145
|
|
135
146
|
def open_uri(uri)
|
data/lib/termtter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termtter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-03-
|
13
|
+
date: 2009-03-12 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|