jugyo-termtter 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/termtter/stdout.rb +1 -1
- data/lib/termtter.rb +23 -28
- data/test/test_termtter.rb +14 -16
- metadata +2 -2
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ $hoe = Hoe.new('termtter', Termtter::VERSION) do |p|
|
|
9
9
|
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
10
|
p.rubyforge_name = p.name # TODO this is default value
|
11
11
|
p.extra_deps = [
|
12
|
-
['
|
12
|
+
['json'],
|
13
13
|
['configatron'],
|
14
14
|
]
|
15
15
|
#p.extra_dev_deps = [
|
data/lib/termtter/stdout.rb
CHANGED
@@ -13,7 +13,7 @@ Termtter::Client.add_hook do |statuses, event|
|
|
13
13
|
text = s.text.gsub("\n", '')
|
14
14
|
color_num = colors[s.user_screen_name.hash % colors.size]
|
15
15
|
status = "#{s.user_screen_name}: #{text}"
|
16
|
-
unless s.in_reply_to_status_id && s.in_reply_to_status_id.
|
16
|
+
unless s.in_reply_to_status_id && s.in_reply_to_status_id.nil?
|
17
17
|
status += " (reply to #{s.in_reply_to_status_id})"
|
18
18
|
end
|
19
19
|
|
data/lib/termtter.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'json'
|
3
3
|
require 'open-uri'
|
4
4
|
require 'cgi'
|
5
5
|
require 'readline'
|
@@ -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.3.
|
13
|
+
VERSION = '0.3.5'
|
14
14
|
|
15
15
|
class CommandNotFound < StandardError; end
|
16
16
|
|
@@ -59,12 +59,12 @@ module Termtter
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def list_friends_timeline
|
62
|
-
statuses = get_timeline("http://twitter.com/statuses/friends_timeline.
|
62
|
+
statuses = get_timeline("http://twitter.com/statuses/friends_timeline.json")
|
63
63
|
call_hooks(statuses, :list_friends_timeline)
|
64
64
|
end
|
65
65
|
|
66
66
|
def update_friends_timeline
|
67
|
-
uri = "http://twitter.com/statuses/friends_timeline.
|
67
|
+
uri = "http://twitter.com/statuses/friends_timeline.json"
|
68
68
|
if @since_id && !@since_id.empty?
|
69
69
|
uri += "?since_id=#{@since_id}"
|
70
70
|
end
|
@@ -74,23 +74,19 @@ module Termtter
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def get_user_timeline(screen_name)
|
77
|
-
statuses = get_timeline("http://twitter.com/statuses/user_timeline/#{screen_name}.
|
77
|
+
statuses = get_timeline("http://twitter.com/statuses/user_timeline/#{screen_name}.json")
|
78
78
|
call_hooks(statuses, :list_user_timeline)
|
79
79
|
end
|
80
80
|
|
81
81
|
def search(query)
|
82
|
-
doc = Nokogiri::XML(open('http://search.twitter.com/search.atom?q=' + CGI.escape(query)))
|
83
|
-
|
84
82
|
statuses = []
|
85
|
-
|
86
|
-
|
83
|
+
|
84
|
+
results = JSON.parse(open('http://search.twitter.com/search.json?q=' + CGI.escape(query)).read)['results']
|
85
|
+
results.each do |s|
|
87
86
|
status = Status.new
|
88
|
-
|
89
|
-
status.created_at = Time.utc(*ParseDate::parsedate(
|
90
|
-
status.
|
91
|
-
name = node.xpath('atom:author/atom:name', ns).text
|
92
|
-
status.user_screen_name = name.scan(/^([^\s]+) /).flatten[0]
|
93
|
-
status.user_name = name.scan(/\((.*)\)/).flatten[0]
|
87
|
+
status.text = s['text']
|
88
|
+
status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
|
89
|
+
status.user_screen_name = s['from_user']
|
94
90
|
statuses << status
|
95
91
|
end
|
96
92
|
|
@@ -99,12 +95,12 @@ module Termtter
|
|
99
95
|
end
|
100
96
|
|
101
97
|
def show(id)
|
102
|
-
statuses = get_timeline("http://twitter.com/statuses/show/#{id}.
|
98
|
+
statuses = get_timeline("http://twitter.com/statuses/show/#{id}.json")
|
103
99
|
call_hooks(statuses, :show)
|
104
100
|
end
|
105
101
|
|
106
102
|
def replies
|
107
|
-
statuses = get_timeline("http://twitter.com/statuses/replies.
|
103
|
+
statuses = get_timeline("http://twitter.com/statuses/replies.json")
|
108
104
|
call_hooks(statuses, :show)
|
109
105
|
end
|
110
106
|
|
@@ -120,19 +116,18 @@ module Termtter
|
|
120
116
|
end
|
121
117
|
|
122
118
|
def get_timeline(uri, update_since_id = false)
|
123
|
-
doc = Nokogiri::XML(open(uri, :http_basic_authentication => [@user_name, @password]))
|
124
|
-
|
125
119
|
statuses = []
|
126
|
-
|
120
|
+
|
121
|
+
JSON.parse(open(uri, :http_basic_authentication => [@user_name, @password]).read).each do |s|
|
122
|
+
u = s["user"]
|
127
123
|
status = Status.new
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
status.send(
|
124
|
+
status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
|
125
|
+
%w(id text truncated in_reply_to_status_id in_reply_to_user_id).each do |key|
|
126
|
+
status.send("#{key}=".to_sym, s[key])
|
127
|
+
end
|
128
|
+
%w(id name screen_name url profile_image_url).each do |key|
|
129
|
+
status.send("user_#{key}=".to_sym, u[key])
|
134
130
|
end
|
135
|
-
status.created_at = Time.utc(*ParseDate::parsedate(status.created_at)).localtime
|
136
131
|
statuses << status
|
137
132
|
end
|
138
133
|
|
@@ -145,7 +140,7 @@ module Termtter
|
|
145
140
|
|
146
141
|
def call_commands(text)
|
147
142
|
return if text.empty?
|
148
|
-
|
143
|
+
|
149
144
|
command_found = false
|
150
145
|
@@commands.each do |key, command|
|
151
146
|
if key =~ text
|
data/test/test_termtter.rb
CHANGED
@@ -17,43 +17,41 @@ class TestTermtter < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_get_timeline
|
20
|
-
statuses = swap_open('friends_timeline.
|
20
|
+
statuses = swap_open('friends_timeline.json') { @termtter.get_timeline('') }
|
21
21
|
|
22
22
|
assert_equal 3, statuses.size
|
23
23
|
|
24
|
-
assert_equal
|
24
|
+
assert_equal 102, statuses[0].user_id
|
25
25
|
assert_equal 'test2', statuses[0].user_screen_name
|
26
26
|
assert_equal 'Test User 2', statuses[0].user_name
|
27
27
|
assert_equal 'texttext 2', statuses[0].text
|
28
28
|
assert_equal 'http://twitter.com/test2', statuses[0].user_url
|
29
|
-
assert_equal 'http://
|
30
|
-
assert_equal '
|
29
|
+
assert_equal 'http://s3.amazonaws.com/twitter_production/profile_images/000/102.png', statuses[0].user_profile_image_url
|
30
|
+
assert_equal 'Sat Jan 03 21:13:45 +0900 2009', statuses[0].created_at.to_s
|
31
31
|
|
32
|
-
assert_equal
|
32
|
+
assert_equal 100, statuses[2].user_id
|
33
33
|
assert_equal 'test0', statuses[2].user_screen_name
|
34
34
|
assert_equal 'Test User 0', statuses[2].user_name
|
35
35
|
assert_equal 'texttext 0', statuses[2].text
|
36
36
|
assert_equal 'http://twitter.com/test0', statuses[2].user_url
|
37
|
-
assert_equal 'http://
|
38
|
-
assert_equal '
|
37
|
+
assert_equal 'http://s3.amazonaws.com/twitter_production/profile_images/000/100.png', statuses[2].user_profile_image_url
|
38
|
+
assert_equal 'Sat Jan 03 21:13:45 +0900 2009', statuses[2].created_at.to_s
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_get_timeline_with_update_since_id
|
42
|
-
statuses = swap_open('friends_timeline.
|
43
|
-
assert_equal
|
42
|
+
statuses = swap_open('friends_timeline.json') { @termtter.get_timeline('', true) }
|
43
|
+
assert_equal 10002, @termtter.since_id
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_search
|
47
|
-
statuses = swap_open('search.
|
47
|
+
statuses = swap_open('search.json') { @termtter.search('') }
|
48
48
|
assert_equal 3, statuses.size
|
49
49
|
assert_equal 'test2', statuses[0].user_screen_name
|
50
|
-
assert_equal 'Test User 2', statuses[0].user_name
|
51
50
|
assert_equal 'texttext 2', statuses[0].text
|
52
|
-
assert_equal '
|
51
|
+
assert_equal 'Sat Jan 03 21:49:09 +0900 2009', statuses[0].created_at.to_s
|
53
52
|
assert_equal 'test0', statuses[2].user_screen_name
|
54
|
-
assert_equal 'Test User 0', statuses[2].user_name
|
55
53
|
assert_equal 'texttext 0', statuses[2].text
|
56
|
-
assert_equal '
|
54
|
+
assert_equal 'Sat Jan 03 21:49:09 +0900 2009', statuses[2].created_at.to_s
|
57
55
|
end
|
58
56
|
|
59
57
|
def test_add_hook
|
@@ -61,7 +59,7 @@ class TestTermtter < Test::Unit::TestCase
|
|
61
59
|
Termtter::Client.add_hook do |statuses, event|
|
62
60
|
call_hook = true
|
63
61
|
end
|
64
|
-
swap_open('search.
|
62
|
+
swap_open('search.json'){ @termtter.search('') }
|
65
63
|
|
66
64
|
assert_equal true, call_hook
|
67
65
|
|
@@ -71,7 +69,7 @@ class TestTermtter < Test::Unit::TestCase
|
|
71
69
|
|
72
70
|
assert_equal false, call_hook
|
73
71
|
end
|
74
|
-
|
72
|
+
|
75
73
|
def test_add_command
|
76
74
|
command_text = nil
|
77
75
|
matche_text = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jugyo-termtter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -13,7 +13,7 @@ date: 2009-01-03 00:00:00 -08:00
|
|
13
13
|
default_executable: termtter
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: json
|
17
17
|
version_requirement:
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|