tuomas-tweetwine 0.1.8 → 0.1.9
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/CHANGELOG.rdoc +5 -0
- data/README.rdoc +2 -0
- data/Rakefile +1 -2
- data/lib/tweetwine/client.rb +57 -7
- data/lib/tweetwine/io.rb +25 -12
- data/test/client_test.rb +150 -65
- data/test/io_test.rb +58 -38
- data/test/test_helper.rb +32 -0
- metadata +3 -13
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -34,6 +34,8 @@ When invoking the program, the supported commands are
|
|
34
34
|
<tt>mentions</tt>:: Fetch latest mentions for the authenticated user.
|
35
35
|
<tt>user [name]</tt>:: Fetch a specific user's latest statuses, identified by the argument; if given no argument, fetch the statuses of the authenticated user.
|
36
36
|
<tt>update [status]</tt>:: Send a status update, but confirm the action first before actually sending. The status update can either be given as an argument or via STDIN if no argument is given.
|
37
|
+
<tt>friends</tt>:: Fetch friends and their latest statuses.
|
38
|
+
<tt>followers</tt>:: Fetch followers and their latest statuses.
|
37
39
|
|
38
40
|
If no <tt>[command]</tt> is given, the default action is <tt>home</tt>.
|
39
41
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
full_name = "Tweetwine"
|
4
4
|
package_name = "tweetwine"
|
5
|
-
version = "0.1.
|
5
|
+
version = "0.1.9"
|
6
6
|
|
7
7
|
require "lib/#{package_name}"
|
8
8
|
|
@@ -23,7 +23,6 @@ spec = Gem::Specification.new do |s|
|
|
23
23
|
s.files = FileList["Rakefile", "*.rdoc", "bin/**/*", "lib/**/*", "test/**/*"].to_a
|
24
24
|
s.executables = ["tweetwine"]
|
25
25
|
|
26
|
-
s.add_dependency("json", ">= 1.1.4")
|
27
26
|
s.add_dependency("rest-client", ">= 1.0.0")
|
28
27
|
|
29
28
|
s.has_rdoc = true
|
data/lib/tweetwine/client.rb
CHANGED
@@ -7,7 +7,7 @@ module Tweetwine
|
|
7
7
|
class Client
|
8
8
|
attr_reader :num_statuses, :page_num
|
9
9
|
|
10
|
-
COMMANDS = [:home, :mentions, :user, :update]
|
10
|
+
COMMANDS = [:home, :mentions, :user, :update, :friends, :followers]
|
11
11
|
|
12
12
|
DEFAULT_NUM_STATUSES = 20
|
13
13
|
DEFAULT_PAGE_NUM = 1
|
@@ -24,15 +24,15 @@ module Tweetwine
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def home
|
27
|
-
|
27
|
+
show_statuses(get_response_as_json("statuses/friends_timeline", :num_statuses, :page))
|
28
28
|
end
|
29
29
|
|
30
30
|
def mentions
|
31
|
-
|
31
|
+
show_statuses(get_response_as_json("statuses/mentions", :num_statuses, :page))
|
32
32
|
end
|
33
33
|
|
34
34
|
def user(user = @username)
|
35
|
-
|
35
|
+
show_statuses(get_response_as_json("statuses/user_timeline/#{user}", :num_statuses, :page))
|
36
36
|
end
|
37
37
|
|
38
38
|
def update(new_status = nil)
|
@@ -44,12 +44,20 @@ module Tweetwine
|
|
44
44
|
if !new_status.empty? && @io.confirm("Really send?")
|
45
45
|
status = JSON.parse(post("statuses/update.json", {:status => new_status}))
|
46
46
|
@io.info "Sent status update.\n\n"
|
47
|
-
|
47
|
+
show_statuses([status])
|
48
48
|
else
|
49
49
|
@io.info "Cancelled."
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def friends
|
54
|
+
show_users(get_response_as_json("statuses/friends/#{@username}", :page))
|
55
|
+
end
|
56
|
+
|
57
|
+
def followers
|
58
|
+
show_users(get_response_as_json("statuses/followers/#{@username}", :page))
|
59
|
+
end
|
60
|
+
|
53
61
|
private
|
54
62
|
|
55
63
|
def parse_int_gt_option(value, default, min, name_for_error)
|
@@ -65,8 +73,50 @@ module Tweetwine
|
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
68
|
-
def
|
69
|
-
|
76
|
+
def get_response_as_json(url_body, *query_opts)
|
77
|
+
url = url_body + ".json?#{parse_query_options(query_opts)}"
|
78
|
+
JSON.parse(get(url))
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse_query_options(query_opts)
|
82
|
+
str = []
|
83
|
+
query_opts.each do |opt|
|
84
|
+
case opt
|
85
|
+
when :page
|
86
|
+
str << "page=#{@page_num}"
|
87
|
+
when :num_statuses
|
88
|
+
str << "count=#{@num_statuses}"
|
89
|
+
# do nothing on else
|
90
|
+
end
|
91
|
+
end
|
92
|
+
str.join("&")
|
93
|
+
end
|
94
|
+
|
95
|
+
def show_statuses(data)
|
96
|
+
show_responses(data) { |entry| [entry["user"], entry] }
|
97
|
+
end
|
98
|
+
|
99
|
+
def show_users(data)
|
100
|
+
show_responses(data) { |entry| [entry, entry["status"]] }
|
101
|
+
end
|
102
|
+
|
103
|
+
def show_responses(data)
|
104
|
+
data.each do |entry|
|
105
|
+
user_data, status_data = yield entry
|
106
|
+
@io.show(parse_response(user_data, status_data))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def parse_response(user_data, status_data)
|
111
|
+
record = { :user => user_data["screen_name"] }
|
112
|
+
if status_data
|
113
|
+
record[:status] = {
|
114
|
+
:created_at => status_data["created_at"],
|
115
|
+
:in_reply_to => status_data["in_reply_to_screen_name"],
|
116
|
+
:text => status_data["text"]
|
117
|
+
}
|
118
|
+
end
|
119
|
+
record
|
70
120
|
end
|
71
121
|
|
72
122
|
def get(body_url)
|
data/lib/tweetwine/io.rb
CHANGED
@@ -35,35 +35,48 @@ module Tweetwine
|
|
35
35
|
confirmation.downcase[0,1] == "y"
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def show(record)
|
39
|
+
if record[:status]
|
40
|
+
show_as_status(record)
|
41
|
+
else
|
42
|
+
show_as_user(record)
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
time_diff_value, time_diff_unit = Util.humanize_time_diff(status["created_at"], Time.now)
|
46
|
-
from_user = status["user"]["screen_name"]
|
46
|
+
def show_as_status(record)
|
47
|
+
time_diff_value, time_diff_unit = Util.humanize_time_diff(record[:status][:created_at], Time.now)
|
48
|
+
from_user = record[:user]
|
47
49
|
from_user = colorize(:green, from_user) if @colorize
|
48
|
-
in_reply_to = status[
|
50
|
+
in_reply_to = record[:status][:in_reply_to]
|
49
51
|
in_reply_to = if in_reply_to && !in_reply_to.empty?
|
50
52
|
in_reply_to = colorize(:green, in_reply_to) if @colorize
|
51
53
|
"in reply to #{in_reply_to}, "
|
52
54
|
else
|
53
55
|
""
|
54
56
|
end
|
55
|
-
|
57
|
+
status = record[:status][:text]
|
56
58
|
if @colorize
|
57
|
-
|
58
|
-
|
59
|
+
status = colorize(:yellow, status, NICK_REGEX)
|
60
|
+
status = colorize(:cyan, status, URL_REGEX)
|
59
61
|
end
|
60
62
|
@output.puts <<-END
|
61
63
|
#{from_user}, #{in_reply_to}#{time_diff_value} #{time_diff_unit} ago:
|
62
|
-
#{
|
64
|
+
#{status}
|
63
65
|
|
64
66
|
END
|
65
67
|
end
|
66
68
|
|
69
|
+
def show_as_user(record)
|
70
|
+
user = record[:user]
|
71
|
+
user = colorize(:green, user) if @colorize
|
72
|
+
@output.puts <<-END
|
73
|
+
#{user}
|
74
|
+
|
75
|
+
END
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
67
80
|
def colorize(color, str, matcher = nil)
|
68
81
|
color_code = COLOR_CODES[color.to_sym]
|
69
82
|
|
data/test/client_test.rb
CHANGED
@@ -46,116 +46,144 @@ class ClientTest < Test::Unit::TestCase
|
|
46
46
|
@client = Client.new({ :username => "foo", :password => "bar" })
|
47
47
|
@io = mock()
|
48
48
|
@client.instance_variable_set(:@io, @io)
|
49
|
-
@
|
49
|
+
@statuses_query_params = "count=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
|
50
|
+
@users_query_params = "page=#{Client::DEFAULT_PAGE_NUM}"
|
50
51
|
end
|
51
52
|
|
52
53
|
should "raise ClientError for invalid request" do
|
53
54
|
RestClient.expects(:get) \
|
54
|
-
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@
|
55
|
+
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@statuses_query_params}") \
|
55
56
|
.raises(RestClient::Unauthorized)
|
56
57
|
assert_raises(ClientError) { @client.home }
|
57
58
|
end
|
58
59
|
|
59
60
|
should "fetch friends' statuses (home view)" do
|
60
|
-
statuses =
|
61
|
+
statuses, records = create_test_statuses(
|
61
62
|
{
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
:user => "zanzibar",
|
64
|
+
:status => {
|
65
|
+
:created_at => Time.at(1).to_s,
|
66
|
+
:text => "wassup?",
|
67
|
+
:in_reply_to => nil
|
68
|
+
}
|
65
69
|
},
|
66
70
|
{
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
:user => "lulzwoo",
|
72
|
+
:status => {
|
73
|
+
:created_at => Time.at(1).to_s,
|
74
|
+
:text => "nuttin'",
|
75
|
+
:in_reply_to => nil
|
76
|
+
}
|
70
77
|
}
|
71
|
-
|
78
|
+
)
|
72
79
|
RestClient.expects(:get) \
|
73
|
-
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@
|
80
|
+
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@statuses_query_params}") \
|
74
81
|
.returns(statuses.to_json)
|
75
|
-
@io.expects(:
|
82
|
+
@io.expects(:show).with(records[0])
|
83
|
+
@io.expects(:show).with(records[1])
|
76
84
|
@client.home
|
77
85
|
end
|
78
86
|
|
79
87
|
should "fetch mentions" do
|
80
|
-
statuses =
|
88
|
+
statuses, records = create_test_statuses(
|
81
89
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
90
|
+
:user => "zanzibar",
|
91
|
+
:status => {
|
92
|
+
:created_at => Time.at(1).to_s,
|
93
|
+
:text => "wassup, @foo?",
|
94
|
+
:in_reply_to => "foo"
|
95
|
+
}
|
86
96
|
},
|
87
97
|
{
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
98
|
+
:user => "lulzwoo",
|
99
|
+
:status => {
|
100
|
+
:created_at => Time.at(1).to_s,
|
101
|
+
:text => "@foo, doing nuttin'",
|
102
|
+
:in_reply_to => "foo"
|
103
|
+
}
|
92
104
|
}
|
93
|
-
|
105
|
+
)
|
94
106
|
RestClient.expects(:get) \
|
95
|
-
.with("https://foo:bar@twitter.com/statuses/mentions.json?#{@
|
107
|
+
.with("https://foo:bar@twitter.com/statuses/mentions.json?#{@statuses_query_params}") \
|
96
108
|
.returns(statuses.to_json)
|
97
|
-
@io.expects(:
|
109
|
+
@io.expects(:show).with(records[0])
|
110
|
+
@io.expects(:show).with(records[1])
|
98
111
|
@client.mentions
|
99
112
|
end
|
100
113
|
|
101
114
|
should "fetch a specific user's statuses, with the user identified by given argument" do
|
102
|
-
statuses =
|
115
|
+
statuses, records = create_test_statuses(
|
103
116
|
{
|
104
|
-
|
105
|
-
|
106
|
-
|
117
|
+
:user => "zanzibar",
|
118
|
+
:status => {
|
119
|
+
:created_at => Time.at(1).to_s,
|
120
|
+
:text => "wassup?",
|
121
|
+
:in_reply_to => nil
|
122
|
+
}
|
107
123
|
}
|
108
|
-
|
124
|
+
)
|
109
125
|
RestClient.expects(:get) \
|
110
|
-
.with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json?#{@
|
126
|
+
.with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json?#{@statuses_query_params}") \
|
111
127
|
.returns(statuses.to_json)
|
112
|
-
@io.expects(:
|
128
|
+
@io.expects(:show).with(records[0])
|
113
129
|
@client.user("zanzibar")
|
114
130
|
end
|
115
131
|
|
116
132
|
should "fetch a specific user's statuses, with the user being the authenticated user itself when given no argument" do
|
117
|
-
statuses =
|
133
|
+
statuses, records = create_test_statuses(
|
118
134
|
{
|
119
|
-
|
120
|
-
|
121
|
-
|
135
|
+
:user => "foo",
|
136
|
+
:status => {
|
137
|
+
:created_at => Time.at(1).to_s,
|
138
|
+
:text => "wassup?",
|
139
|
+
:in_reply_to => nil
|
140
|
+
}
|
122
141
|
}
|
123
|
-
|
142
|
+
)
|
124
143
|
RestClient.expects(:get) \
|
125
|
-
.with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json?#{@
|
144
|
+
.with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json?#{@statuses_query_params}") \
|
126
145
|
.returns(statuses.to_json)
|
127
|
-
@io.expects(:
|
146
|
+
@io.expects(:show).with(records[0])
|
128
147
|
@client.user
|
129
148
|
end
|
130
149
|
|
131
150
|
should "post a status update via argument, when positive confirmation" do
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
151
|
+
statuses, records = create_test_statuses(
|
152
|
+
{
|
153
|
+
:user => "foo",
|
154
|
+
:status => {
|
155
|
+
:created_at => Time.at(1).to_s,
|
156
|
+
:text => "wondering around",
|
157
|
+
:in_reply_to => nil
|
158
|
+
}
|
159
|
+
},
|
160
|
+
)
|
137
161
|
RestClient.expects(:post) \
|
138
162
|
.with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
|
139
|
-
.returns(
|
163
|
+
.returns(statuses[0].to_json)
|
140
164
|
@io.expects(:confirm).with("Really send?").returns(true)
|
141
165
|
@io.expects(:info).with("Sent status update.\n\n")
|
142
|
-
@io.expects(:
|
166
|
+
@io.expects(:show).with(records[0])
|
143
167
|
@client.update("wondering about")
|
144
168
|
end
|
145
169
|
|
146
170
|
should "post a status update via prompt, when positive confirmation" do
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
171
|
+
statuses, records = create_test_statuses(
|
172
|
+
{ :user => "foo",
|
173
|
+
:status => {
|
174
|
+
:created_at => Time.at(1).to_s,
|
175
|
+
:text => "wondering around",
|
176
|
+
:in_reply_to => nil
|
177
|
+
}
|
178
|
+
},
|
179
|
+
)
|
152
180
|
RestClient.expects(:post) \
|
153
181
|
.with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
|
154
|
-
.returns(
|
182
|
+
.returns(statuses[0].to_json)
|
155
183
|
@io.expects(:prompt).with("Status update").returns("wondering about")
|
156
184
|
@io.expects(:confirm).with("Really send?").returns(true)
|
157
185
|
@io.expects(:info).with("Sent status update.\n\n")
|
158
|
-
@io.expects(:
|
186
|
+
@io.expects(:show).with(records[0])
|
159
187
|
@client.update
|
160
188
|
end
|
161
189
|
|
@@ -163,8 +191,8 @@ class ClientTest < Test::Unit::TestCase
|
|
163
191
|
RestClient.expects(:post).never
|
164
192
|
@io.expects(:confirm).with("Really send?").returns(false)
|
165
193
|
@io.expects(:info).with("Cancelled.")
|
166
|
-
@io.expects(:
|
167
|
-
@client.update("wondering
|
194
|
+
@io.expects(:show).never
|
195
|
+
@client.update("wondering around")
|
168
196
|
end
|
169
197
|
|
170
198
|
should "cancel a status update via prompt, when negative confirmation" do
|
@@ -172,7 +200,7 @@ class ClientTest < Test::Unit::TestCase
|
|
172
200
|
@io.expects(:prompt).with("Status update").returns("wondering about")
|
173
201
|
@io.expects(:confirm).with("Really send?").returns(false)
|
174
202
|
@io.expects(:info).with("Cancelled.")
|
175
|
-
@io.expects(:
|
203
|
+
@io.expects(:show).never
|
176
204
|
@client.update
|
177
205
|
end
|
178
206
|
|
@@ -180,7 +208,7 @@ class ClientTest < Test::Unit::TestCase
|
|
180
208
|
RestClient.expects(:post).never
|
181
209
|
@io.expects(:confirm).never
|
182
210
|
@io.expects(:info).with("Cancelled.")
|
183
|
-
@io.expects(:
|
211
|
+
@io.expects(:show).never
|
184
212
|
@client.update("")
|
185
213
|
end
|
186
214
|
|
@@ -189,28 +217,85 @@ class ClientTest < Test::Unit::TestCase
|
|
189
217
|
@io.expects(:prompt).with("Status update").returns("")
|
190
218
|
@io.expects(:confirm).never
|
191
219
|
@io.expects(:info).with("Cancelled.")
|
192
|
-
@io.expects(:
|
220
|
+
@io.expects(:show).never
|
193
221
|
@client.update
|
194
222
|
end
|
195
223
|
|
196
224
|
should "truncate a status update with too long argument and warn the user" do
|
197
225
|
long_status_update = "x aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz 111 222 333 444 555 666 777 888 999 000"
|
198
226
|
truncated_status_update = "x aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz 111 222 333 444 555 666 777 888 99"
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
227
|
+
statuses, records = create_test_statuses(
|
228
|
+
{ :user => "foo",
|
229
|
+
:status => {
|
230
|
+
:created_at => Time.at(1).to_s,
|
231
|
+
:text => truncated_status_update,
|
232
|
+
:in_reply_to => nil
|
233
|
+
}
|
234
|
+
},
|
235
|
+
)
|
205
236
|
RestClient.expects(:post) \
|
206
237
|
.with("https://foo:bar@twitter.com/statuses/update.json", {:status => truncated_status_update}) \
|
207
|
-
.returns(
|
238
|
+
.returns(statuses[0].to_json)
|
208
239
|
@io.expects(:warn).with("Status will be truncated: #{truncated_status_update}")
|
209
240
|
@io.expects(:confirm).with("Really send?").returns(true)
|
210
241
|
@io.expects(:info).with("Sent status update.\n\n")
|
211
|
-
@io.expects(:
|
242
|
+
@io.expects(:show).with(records[0])
|
212
243
|
@client.update(long_status_update)
|
213
244
|
end
|
245
|
+
|
246
|
+
should "fetch friends" do
|
247
|
+
users, records = create_test_users(
|
248
|
+
{
|
249
|
+
:user => "zanzibar",
|
250
|
+
:status => {
|
251
|
+
:created_at => Time.at(1).to_s,
|
252
|
+
:text => "wassup, @foo?",
|
253
|
+
:in_reply_to => "foo"
|
254
|
+
}
|
255
|
+
},
|
256
|
+
{
|
257
|
+
:user => "lulzwoo",
|
258
|
+
:status => {
|
259
|
+
:created_at => Time.at(1).to_s,
|
260
|
+
:text => "@foo, doing nuttin'",
|
261
|
+
:in_reply_to => "foo"
|
262
|
+
}
|
263
|
+
}
|
264
|
+
)
|
265
|
+
RestClient.expects(:get) \
|
266
|
+
.with("https://foo:bar@twitter.com/statuses/friends/foo.json?#{@users_query_params}") \
|
267
|
+
.returns(users.to_json)
|
268
|
+
@io.expects(:show).with(records[0])
|
269
|
+
@io.expects(:show).with(records[1])
|
270
|
+
@client.friends
|
271
|
+
end
|
272
|
+
|
273
|
+
should "fetch followers" do
|
274
|
+
users, records = create_test_users(
|
275
|
+
{
|
276
|
+
:user => "zanzibar",
|
277
|
+
:status => {
|
278
|
+
:created_at => Time.at(1).to_s,
|
279
|
+
:text => "wassup, @foo?",
|
280
|
+
:in_reply_to => "foo"
|
281
|
+
}
|
282
|
+
},
|
283
|
+
{
|
284
|
+
:user => "lulzwoo",
|
285
|
+
:status => {
|
286
|
+
:created_at => Time.at(1).to_s,
|
287
|
+
:text => "@foo, doing nuttin'",
|
288
|
+
:in_reply_to => "foo"
|
289
|
+
}
|
290
|
+
}
|
291
|
+
)
|
292
|
+
RestClient.expects(:get) \
|
293
|
+
.with("https://foo:bar@twitter.com/statuses/followers/foo.json?#{@users_query_params}") \
|
294
|
+
.returns(users.to_json)
|
295
|
+
@io.expects(:show).with(records[0])
|
296
|
+
@io.expects(:show).with(records[1])
|
297
|
+
@client.followers
|
298
|
+
end
|
214
299
|
end
|
215
300
|
end
|
216
301
|
|
data/test/io_test.rb
CHANGED
@@ -52,14 +52,24 @@ class IOTest < Test::Unit::TestCase
|
|
52
52
|
@io = IO.new({ :input => @input, :output => @output, :colorize => false })
|
53
53
|
end
|
54
54
|
|
55
|
-
should "
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
should "output a record as user info when no status is given" do
|
56
|
+
record = { :user => "fooman" }
|
57
|
+
@output.expects(:puts).with(<<-END
|
58
|
+
fooman
|
59
|
+
|
60
|
+
END
|
61
|
+
)
|
62
|
+
@io.show(record)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "output record as a status when status is given, without in-reply info" do
|
66
|
+
record = {
|
67
|
+
:user => "fooman",
|
68
|
+
:status => {
|
69
|
+
:created_at => Time.at(1),
|
70
|
+
:text => "Hi, @barman! Lulz woo!"
|
61
71
|
}
|
62
|
-
|
72
|
+
}
|
63
73
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
64
74
|
@output.expects(:puts).with(<<-END
|
65
75
|
fooman, 2 secs ago:
|
@@ -67,26 +77,26 @@ Hi, @barman! Lulz woo!
|
|
67
77
|
|
68
78
|
END
|
69
79
|
)
|
70
|
-
@io.
|
80
|
+
@io.show(record)
|
71
81
|
end
|
72
82
|
|
73
|
-
should "
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
"
|
79
|
-
|
83
|
+
should "output record as a status when status is given, with in-reply info" do
|
84
|
+
record = {
|
85
|
+
:user => "barman",
|
86
|
+
:status => {
|
87
|
+
:created_at => Time.at(1),
|
88
|
+
:text => "Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?",
|
89
|
+
:in_reply_to => "fooman"
|
80
90
|
}
|
81
|
-
|
91
|
+
}
|
82
92
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
83
93
|
@output.expects(:puts).with(<<-END
|
84
|
-
|
85
|
-
Hi, @
|
94
|
+
barman, in reply to fooman, 2 secs ago:
|
95
|
+
Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?
|
86
96
|
|
87
97
|
END
|
88
98
|
)
|
89
|
-
@io.
|
99
|
+
@io.show(record)
|
90
100
|
end
|
91
101
|
end
|
92
102
|
|
@@ -97,14 +107,24 @@ Hi, @barman! Lulz woo!
|
|
97
107
|
@io = IO.new({ :input => @input, :output => @output, :colorize => true })
|
98
108
|
end
|
99
109
|
|
100
|
-
should "
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
110
|
+
should "output a record as user info when no status is given" do
|
111
|
+
record = { :user => "fooman" }
|
112
|
+
@output.expects(:puts).with(<<-END
|
113
|
+
\033[32mfooman\033[0m
|
114
|
+
|
115
|
+
END
|
116
|
+
)
|
117
|
+
@io.show(record)
|
118
|
+
end
|
119
|
+
|
120
|
+
should "output record as a status when status is given, without in-reply info" do
|
121
|
+
record = {
|
122
|
+
:user => "fooman",
|
123
|
+
:status => {
|
124
|
+
:created_at => Time.at(1),
|
125
|
+
:text => "Hi, @barman! Lulz woo!"
|
106
126
|
}
|
107
|
-
|
127
|
+
}
|
108
128
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
109
129
|
@output.expects(:puts).with(<<-END
|
110
130
|
\033[32mfooman\033[0m, 2 secs ago:
|
@@ -112,26 +132,26 @@ Hi, \033[33m@barman\033[0m! Lulz woo!
|
|
112
132
|
|
113
133
|
END
|
114
134
|
)
|
115
|
-
@io.
|
135
|
+
@io.show(record)
|
116
136
|
end
|
117
137
|
|
118
|
-
should "
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
"
|
124
|
-
|
138
|
+
should "output record as a status when status is given, with in-reply info" do
|
139
|
+
record = {
|
140
|
+
:user => "barman",
|
141
|
+
:status => {
|
142
|
+
:created_at => Time.at(1),
|
143
|
+
:text => "Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?",
|
144
|
+
:in_reply_to => "fooman"
|
125
145
|
}
|
126
|
-
|
146
|
+
}
|
127
147
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
128
148
|
@output.expects(:puts).with(<<-END
|
129
|
-
\033[
|
130
|
-
Hi, \033[33m@
|
149
|
+
\033[32mbarman\033[0m, in reply to \033[32mfooman\033[0m, 2 secs ago:
|
150
|
+
Hi, \033[33m@fooman\033[0m! Check this: \033[36mhttp://www.foo.com\033[0m. Nice, isn't it?
|
131
151
|
|
132
152
|
END
|
133
153
|
)
|
134
|
-
@io.
|
154
|
+
@io.show(record)
|
135
155
|
end
|
136
156
|
end
|
137
157
|
|
data/test/test_helper.rb
CHANGED
@@ -4,11 +4,43 @@ require "test/unit"
|
|
4
4
|
require "shoulda"
|
5
5
|
require "mocha"
|
6
6
|
|
7
|
+
module Tweetwine
|
8
|
+
module TestHelpers
|
9
|
+
def create_test_statuses(*records)
|
10
|
+
statuses = records.map do |record|
|
11
|
+
{
|
12
|
+
"created_at" => record[:status][:created_at],
|
13
|
+
"text" => record[:status][:text],
|
14
|
+
"in_reply_to_screen_name" => record[:status][:in_reply_to],
|
15
|
+
"user" => { "screen_name" => record[:user] }
|
16
|
+
}
|
17
|
+
end
|
18
|
+
[statuses, records]
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_test_users(*records)
|
22
|
+
statuses = records.map do |record|
|
23
|
+
{
|
24
|
+
"screen_name" => record[:user],
|
25
|
+
"status" => {
|
26
|
+
"created_at" => record[:status][:created_at],
|
27
|
+
"text" => record[:status][:text],
|
28
|
+
"in_reply_to_screen_name" => record[:status][:in_reply_to],
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
[statuses, records]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
7
37
|
Mocha::Configuration.prevent(:stubbing_non_existent_method)
|
8
38
|
|
9
39
|
module Test
|
10
40
|
module Unit
|
11
41
|
class TestCase
|
42
|
+
include Tweetwine::TestHelpers
|
43
|
+
|
12
44
|
def assert_full_match(regex, str, msg = "")
|
13
45
|
match_data = regex.match(str)
|
14
46
|
assert(str == match_data.to_s, msg)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tuomas-tweetwine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuomas Kareinen
|
@@ -9,19 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-15 00:00:00 -07:00
|
13
13
|
default_executable: tweetwine
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: json
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.1.4
|
24
|
-
version:
|
25
15
|
- !ruby/object:Gem::Dependency
|
26
16
|
name: rest-client
|
27
17
|
type: :runtime
|
@@ -63,7 +53,7 @@ homepage: http://github.com/tuomas/tweetwine
|
|
63
53
|
post_install_message:
|
64
54
|
rdoc_options:
|
65
55
|
- --title
|
66
|
-
- Tweetwine 0.1.
|
56
|
+
- Tweetwine 0.1.9
|
67
57
|
- --main
|
68
58
|
- README.rdoc
|
69
59
|
- --exclude
|