jugyo-termtter 0.2.0 → 0.2.1
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/lib/termtter/notify-send.rb +2 -3
- data/lib/termtter/stdout.rb +10 -11
- data/lib/termtter.rb +22 -12
- data/test/test_termtter.rb +18 -19
- metadata +1 -1
data/lib/termtter/notify-send.rb
CHANGED
@@ -3,8 +3,8 @@ Termtter::Client.add_hook do |statuses, event|
|
|
3
3
|
max = 10
|
4
4
|
|
5
5
|
text = statuses[0..(max - 1)].map{|s|
|
6
|
-
status_text = s
|
7
|
-
"<b>#{s
|
6
|
+
status_text = s.text.gsub(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
|
7
|
+
"<b>#{s.user_screen_name}</b> <span font=\"9.0\">#{status_text}</span>"
|
8
8
|
}.join("\n")
|
9
9
|
|
10
10
|
text += "\n<a href=\"http://twitter.com/\">more…</a>" if statuses.size > max
|
@@ -12,4 +12,3 @@ Termtter::Client.add_hook do |statuses, event|
|
|
12
12
|
system 'notify-send', 'Termtter', text, '-t', '60000'
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
data/lib/termtter/stdout.rb
CHANGED
@@ -10,11 +10,11 @@ Termtter::Client.add_hook do |statuses, event|
|
|
10
10
|
unless statuses.empty?
|
11
11
|
if event == :update_friends_timeline then statuses = statuses.reverse end
|
12
12
|
statuses.each do |s|
|
13
|
-
text = s
|
14
|
-
color_num = colors[s
|
15
|
-
status = "#{s
|
16
|
-
unless s
|
17
|
-
status += " (reply to #{s
|
13
|
+
text = s.text.gsub("\n", '')
|
14
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
15
|
+
status = "#{s.user_screen_name}: #{text}"
|
16
|
+
unless s.in_reply_to_status_id && s.in_reply_to_status_id.empty?
|
17
|
+
status += " (reply to #{s.in_reply_to_status_id})"
|
18
18
|
end
|
19
19
|
|
20
20
|
case event
|
@@ -23,20 +23,19 @@ Termtter::Client.add_hook do |statuses, event|
|
|
23
23
|
else
|
24
24
|
time_format = '%m-%d %H:%d'
|
25
25
|
end
|
26
|
-
time_str = "(#{s
|
26
|
+
time_str = "(#{s.created_at.strftime(time_format)})"
|
27
27
|
|
28
28
|
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
when :search
|
32
32
|
statuses.each do |s|
|
33
|
-
text = s
|
34
|
-
color_num = colors[s
|
35
|
-
status = "#{s
|
36
|
-
time_str = "(#{s
|
33
|
+
text = s.text.gsub("\n", '')
|
34
|
+
color_num = colors[s.user_screen_name.hash % colors.size]
|
35
|
+
status = "#{s.user_screen_name}: #{text}"
|
36
|
+
time_str = "(#{s.created_at.strftime('%m-%d %H:%d')})"
|
37
37
|
|
38
38
|
puts "#{color(time_str, 90)} #{color(status, color_num)}"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
data/lib/termtter.rb
CHANGED
@@ -10,7 +10,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
10
10
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
11
11
|
|
12
12
|
module Termtter
|
13
|
-
VERSION = '0.2.
|
13
|
+
VERSION = '0.2.1'
|
14
14
|
|
15
15
|
class Client
|
16
16
|
|
@@ -73,13 +73,13 @@ module Termtter
|
|
73
73
|
statuses = []
|
74
74
|
ns = {'atom' => 'http://www.w3.org/2005/Atom'}
|
75
75
|
doc.xpath('//atom:entry', ns).each do |node|
|
76
|
-
status =
|
76
|
+
status = Status.new
|
77
77
|
published = node.xpath('atom:published', ns).text
|
78
|
-
status
|
79
|
-
status
|
78
|
+
status.created_at = Time.utc(*ParseDate::parsedate(published)).localtime
|
79
|
+
status.text = CGI.unescapeHTML(node.xpath('atom:content', ns).text.gsub(/<\/?[^>]*>/, ''))
|
80
80
|
name = node.xpath('atom:author/atom:name', ns).text
|
81
|
-
status
|
82
|
-
status
|
81
|
+
status.user_screen_name = name.scan(/^([^\s]+) /).flatten[0]
|
82
|
+
status.user_name = name.scan(/\((.*)\)/).flatten[0]
|
83
83
|
statuses << status
|
84
84
|
end
|
85
85
|
|
@@ -112,20 +112,21 @@ module Termtter
|
|
112
112
|
doc = Nokogiri::XML(open(uri, :http_basic_authentication => [@user_name, @password]))
|
113
113
|
|
114
114
|
statuses = []
|
115
|
-
doc.xpath('//status').each do |
|
116
|
-
status =
|
115
|
+
doc.xpath('//status').each do |node|
|
116
|
+
status = Status.new
|
117
117
|
%w(
|
118
118
|
id text created_at truncated in_reply_to_status_id in_reply_to_user_id
|
119
119
|
user/id user/name user/screen_name
|
120
120
|
).each do |key|
|
121
|
-
|
121
|
+
method = "#{key.gsub('/', '_')}=".to_sym
|
122
|
+
status.send(method, node.xpath(key).text)
|
122
123
|
end
|
123
|
-
status
|
124
|
+
status.created_at = Time.utc(*ParseDate::parsedate(status.created_at)).localtime
|
124
125
|
statuses << status
|
125
126
|
end
|
126
127
|
|
127
128
|
if update_since_id && !statuses.empty?
|
128
|
-
@since_id = statuses[0]
|
129
|
+
@since_id = statuses[0].id
|
129
130
|
end
|
130
131
|
|
131
132
|
return statuses
|
@@ -213,5 +214,14 @@ Enter "help" for instructions
|
|
213
214
|
end
|
214
215
|
|
215
216
|
end
|
216
|
-
|
217
|
+
|
218
|
+
class Status
|
219
|
+
%w(
|
220
|
+
id text created_at truncated in_reply_to_status_id in_reply_to_user_id
|
221
|
+
user_id user_name user_screen_name
|
222
|
+
).each do |attr|
|
223
|
+
attr_accessor attr.to_sym
|
224
|
+
end
|
225
|
+
end
|
217
226
|
|
227
|
+
end
|
data/test/test_termtter.rb
CHANGED
@@ -23,16 +23,16 @@ class TestTermtter < Test::Unit::TestCase
|
|
23
23
|
statuses = @termtter.get_timeline('')
|
24
24
|
|
25
25
|
assert_equal 3, statuses.size
|
26
|
-
assert_equal '102', statuses[0]
|
27
|
-
assert_equal 'test2', statuses[0]
|
28
|
-
assert_equal 'Test User 2', statuses[0]
|
29
|
-
assert_equal 'texttext 2', statuses[0]
|
30
|
-
assert_equal 'Thu Dec 25 22:19:57 +0900 2008', statuses[0]
|
31
|
-
assert_equal '100', statuses[2]
|
32
|
-
assert_equal 'test0', statuses[2]
|
33
|
-
assert_equal 'Test User 0', statuses[2]
|
34
|
-
assert_equal 'texttext 0', statuses[2]
|
35
|
-
assert_equal 'Thu Dec 25 22:10:57 +0900 2008', statuses[2]
|
26
|
+
assert_equal '102', statuses[0].user_id
|
27
|
+
assert_equal 'test2', statuses[0].user_screen_name
|
28
|
+
assert_equal 'Test User 2', statuses[0].user_name
|
29
|
+
assert_equal 'texttext 2', statuses[0].text
|
30
|
+
assert_equal 'Thu Dec 25 22:19:57 +0900 2008', statuses[0].created_at.to_s
|
31
|
+
assert_equal '100', statuses[2].user_id
|
32
|
+
assert_equal 'test0', statuses[2].user_screen_name
|
33
|
+
assert_equal 'Test User 0', statuses[2].user_name
|
34
|
+
assert_equal 'texttext 0', statuses[2].text
|
35
|
+
assert_equal 'Thu Dec 25 22:10:57 +0900 2008', statuses[2].created_at.to_s
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_get_timeline_with_update_since_id
|
@@ -51,14 +51,14 @@ class TestTermtter < Test::Unit::TestCase
|
|
51
51
|
|
52
52
|
statuses = @termtter.search('')
|
53
53
|
assert_equal 3, statuses.size
|
54
|
-
assert_equal 'test2', statuses[0]
|
55
|
-
assert_equal 'Test User 2', statuses[0]
|
56
|
-
assert_equal 'texttext 2', statuses[0]
|
57
|
-
assert_equal 'Thu Dec 25 22:52:36 +0900 2008', statuses[0]
|
58
|
-
assert_equal 'test0', statuses[2]
|
59
|
-
assert_equal 'Test User 0', statuses[2]
|
60
|
-
assert_equal 'texttext 0', statuses[2]
|
61
|
-
assert_equal 'Thu Dec 25 22:42:36 +0900 2008', statuses[2]
|
54
|
+
assert_equal 'test2', statuses[0].user_screen_name
|
55
|
+
assert_equal 'Test User 2', statuses[0].user_name
|
56
|
+
assert_equal 'texttext 2', statuses[0].text
|
57
|
+
assert_equal 'Thu Dec 25 22:52:36 +0900 2008', statuses[0].created_at.to_s
|
58
|
+
assert_equal 'test0', statuses[2].user_screen_name
|
59
|
+
assert_equal 'Test User 0', statuses[2].user_name
|
60
|
+
assert_equal 'texttext 0', statuses[2].text
|
61
|
+
assert_equal 'Thu Dec 25 22:42:36 +0900 2008', statuses[2].created_at.to_s
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_add_hook
|
@@ -80,4 +80,3 @@ class TestTermtter < Test::Unit::TestCase
|
|
80
80
|
assert_equal false, call_hook
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|