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 CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.9 released 2009-07-15
2
+
3
+ * Added commands "friends" and "followers"
4
+ * Removed dependency to the "json" gem. It is included in Ruby 1.9.
5
+
1
6
  === 0.1.8 released 2009-07-01
2
7
 
3
8
  * SIGINT (Ctrl+c) is trapper earlier, resulting in clean abort while Ruby
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.8"
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
@@ -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
- get_result_as_json_and_show "statuses/friends_timeline"
27
+ show_statuses(get_response_as_json("statuses/friends_timeline", :num_statuses, :page))
28
28
  end
29
29
 
30
30
  def mentions
31
- get_result_as_json_and_show "statuses/mentions"
31
+ show_statuses(get_response_as_json("statuses/mentions", :num_statuses, :page))
32
32
  end
33
33
 
34
34
  def user(user = @username)
35
- get_result_as_json_and_show "statuses/user_timeline/#{user}"
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
- @io.show_statuses([status])
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 get_result_as_json_and_show(url_body)
69
- @io.show_statuses JSON.parse(get(url_body + ".json?count=#{@num_statuses}&page=#{@page_num}"))
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 show_statuses(statuses)
39
- statuses.each { |status| show_status(status) }
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
- private
43
-
44
- def show_status(status)
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["in_reply_to_screen_name"]
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
- text = status["text"]
57
+ status = record[:status][:text]
56
58
  if @colorize
57
- text = colorize(:yellow, text, NICK_REGEX)
58
- text = colorize(:cyan, text, URL_REGEX)
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
- #{text}
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
- @query_params = "count=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
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?#{@query_params}") \
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
- "created_at" => Time.at(1).to_s,
63
- "user" => { "username" => "zanzibar" },
64
- "text" => "wassup?"
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
- "created_at" => Time.at(2).to_s,
68
- "user" => { "username" => "lulzwoo" },
69
- "text" => "nuttin"
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?#{@query_params}") \
80
+ .with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@statuses_query_params}") \
74
81
  .returns(statuses.to_json)
75
- @io.expects(:show_statuses).with(statuses)
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
- "created_at" => Time.at(1).to_s,
83
- "in_reply_to_screen_name" => "foo",
84
- "user" => { "username" => "zanzibar" },
85
- "text" => "wassup, @foo?"
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
- "created_at" => Time.at(2).to_s,
89
- "in_reply_to_screen_name" => "foo",
90
- "user" => { "username" => "lulzwoo" },
91
- "text" => "@foo, doing nuttin"
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?#{@query_params}") \
107
+ .with("https://foo:bar@twitter.com/statuses/mentions.json?#{@statuses_query_params}") \
96
108
  .returns(statuses.to_json)
97
- @io.expects(:show_statuses).with(statuses)
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
- "created_at" => Time.at(1).to_s,
105
- "user" => { "username" => "zanzibar" },
106
- "text" => "wassup?"
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?#{@query_params}") \
126
+ .with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json?#{@statuses_query_params}") \
111
127
  .returns(statuses.to_json)
112
- @io.expects(:show_statuses).with(statuses)
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
- "created_at" => Time.at(1).to_s,
120
- "user" => { "username" => "foo" },
121
- "text" => "wassup?"
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?#{@query_params}") \
144
+ .with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json?#{@statuses_query_params}") \
126
145
  .returns(statuses.to_json)
127
- @io.expects(:show_statuses).with(statuses)
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
- status = {
133
- "created_at" => Time.at(1).to_s,
134
- "user" => { "username" => "foo" },
135
- "text" => "wondering about"
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(status.to_json)
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(:show_statuses).with([status])
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
- status = {
148
- "created_at" => Time.at(1).to_s,
149
- "user" => { "username" => "foo" },
150
- "text" => "wondering about"
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(status.to_json)
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(:show_statuses).with([status])
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(:show_statuses).never
167
- @client.update("wondering about")
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(:show_statuses).never
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(:show_statuses).never
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(:show_statuses).never
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
- status = {
200
- "created_at" => Time.at(1).to_s,
201
- "user" => { "username" => "foo" },
202
- "text" => truncated_status_update
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(status.to_json)
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(:show_statuses).with([status])
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 "print statuses without in-reply info" do
56
- statuses = [
57
- {
58
- "created_at" => Time.at(1),
59
- "user" => { "screen_name" => "fooman" },
60
- "text" => "Hi, @barman! Lulz woo!"
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.show_statuses(statuses)
80
+ @io.show(record)
71
81
  end
72
82
 
73
- should "print statuses with in-reply info" do
74
- statuses = [
75
- {
76
- "created_at" => Time.at(1),
77
- "in_reply_to_screen_name" => "barman",
78
- "user" => { "screen_name" => "fooman" },
79
- "text" => "Hi, @barman! Lulz woo!"
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
- fooman, in reply to barman, 2 secs ago:
85
- Hi, @barman! Lulz woo!
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.show_statuses(statuses)
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 "print statuses without in-reply info" do
101
- statuses = [
102
- {
103
- "created_at" => Time.at(1),
104
- "user" => { "screen_name" => "fooman" },
105
- "text" => "Hi, @barman! Lulz woo!"
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.show_statuses(statuses)
135
+ @io.show(record)
116
136
  end
117
137
 
118
- should "print statuses with in-reply info" do
119
- statuses = [
120
- {
121
- "created_at" => Time.at(1),
122
- "in_reply_to_screen_name" => "barman",
123
- "user" => { "screen_name" => "fooman" },
124
- "text" => "Hi, @barman! Check this: http://www.foo.com. Nice, isn't it?"
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[32mfooman\033[0m, in reply to \033[32mbarman\033[0m, 2 secs ago:
130
- Hi, \033[33m@barman\033[0m! Check this: \033[36mhttp://www.foo.com\033[0m. Nice, isn't it?
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.show_statuses(statuses)
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.8
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-01 00:00:00 -07:00
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.8
56
+ - Tweetwine 0.1.9
67
57
  - --main
68
58
  - README.rdoc
69
59
  - --exclude