tuomas-tweetwine 0.1.2 → 0.1.3

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,15 +1,21 @@
1
+ === 0.1.3 released 2009-05-05
2
+
3
+ * Empty status update indicates cancellation of the command
4
+ * Other minor improvements
5
+
1
6
  === 0.1.2 released 2009-05-04
2
7
 
3
- * Renamed command "friends" to "home".
4
- * Added command "mentions".
5
- * Improved command line argument and configuration file parsing.
8
+ * Renamed command "friends" to "home"
9
+ * Added command "mentions"
10
+ * When showing a status, indicate if it is a reply
11
+ * Improved command line argument and configuration file parsing
6
12
 
7
13
  === 0.1.1 released 2009-04-23
8
14
 
9
- * Renamed command "msg" to "update".
10
- * If status update if longer than 140 characters, warn about it.
15
+ * Renamed command "msg" to "update"
16
+ * If status update if longer than 140 characters, warn about it
11
17
 
12
18
  === 0.1.0 released 2009-04-22
13
19
 
14
- * Initial release with minimal functionality.
15
- * Usable for quickly checking friends' statuses and sending status updates.
20
+ * Initial release with minimal functionality
21
+ * Usable for quickly checking friends' statuses and sending status updates
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.2"
5
+ version = "0.1.3"
6
6
 
7
7
  require "lib/#{package_name}"
8
8
 
data/bin/tweetwine CHANGED
@@ -36,7 +36,7 @@ Usage: tweetwine [options...] [command]
36
36
  end
37
37
  end.parse!(args)
38
38
  rescue OptionParser::ParseError => e
39
- raise ArgumentError.new(e)
39
+ raise ArgumentError, e.message
40
40
  end
41
41
  options
42
42
  end
@@ -22,7 +22,7 @@ module Tweetwine
22
22
  if (1..MAX_NUM_STATUSES).include? options[:num_statuses]
23
23
  options[:num_statuses]
24
24
  else
25
- raise ArgumentError, "Invalid number of statuses to show -- must be between 1..#{Client::MAX_NUM_STATUSES}"
25
+ raise ArgumentError, "Invalid number of statuses to show -- must be between 1..#{MAX_NUM_STATUSES}"
26
26
  end
27
27
  else
28
28
  DEFAULT_NUM_STATUSES
@@ -31,24 +31,24 @@ module Tweetwine
31
31
  end
32
32
 
33
33
  def home
34
- @io.show_statuses JSON.parse(get("statuses/friends_timeline.json?count=#{@num_statuses}"))
34
+ get_and_show "statuses/friends_timeline.json?count=#{@num_statuses}"
35
35
  end
36
36
 
37
37
  def mentions
38
- @io.show_statuses JSON.parse(get("statuses/mentions.json?count=#{@num_statuses}"))
38
+ get_and_show "statuses/mentions.json?count=#{@num_statuses}"
39
39
  end
40
40
 
41
41
  def user(user = @username)
42
- @io.show_statuses JSON.parse(get("statuses/user_timeline/#{user}.json?count=#{@num_statuses}"))
42
+ get_and_show "statuses/user_timeline/#{user}.json?count=#{@num_statuses}"
43
43
  end
44
44
 
45
45
  def update(new_status = nil)
46
46
  new_status = @io.prompt("Status update") unless new_status
47
47
  if new_status.length > MAX_STATUS_LENGTH
48
48
  new_status = new_status[0...MAX_STATUS_LENGTH]
49
- @io.warn("Update will be truncated: #{new_status}")
49
+ @io.warn("Status will be truncated: #{new_status}")
50
50
  end
51
- if @io.confirm("Really send?")
51
+ if !new_status.empty? && @io.confirm("Really send?")
52
52
  status = JSON.parse(post("statuses/update.json", {:status => new_status}))
53
53
  @io.info "Sent status update.\n\n"
54
54
  @io.show_statuses([status])
@@ -59,6 +59,10 @@ module Tweetwine
59
59
 
60
60
  private
61
61
 
62
+ def get_and_show(rest_url)
63
+ @io.show_statuses JSON.parse(get(rest_url))
64
+ end
65
+
62
66
  def get(rest_url)
63
67
  rest_client_action(:get, @base_url + rest_url)
64
68
  end
data/lib/tweetwine/io.rb CHANGED
@@ -27,7 +27,7 @@ module Tweetwine
27
27
 
28
28
  def show_statuses(statuses)
29
29
  statuses.each do |status|
30
- time_diff_value, time_diff_unit = Util.humanize_time_diff(Time.now, status["created_at"])
30
+ time_diff_value, time_diff_unit = Util.humanize_time_diff(status["created_at"], Time.now)
31
31
  from_user = status["user"]["screen_name"]
32
32
  from_user = colorize(:green, from_user) if @colorize
33
33
  in_reply_to = status["in_reply_to_screen_name"]
@@ -13,7 +13,7 @@ module Tweetwine
13
13
  def parse(args = [], config_file = nil, &cmd_parser)
14
14
  options = parse_options(args, config_file, &cmd_parser)
15
15
  command = if args.empty? then @supported_commands.first else args.shift.to_sym end
16
- raise ArgumentError, "Unknown command." unless @supported_commands.include? command
16
+ raise ArgumentError, "Unknown command" unless @supported_commands.include? command
17
17
  @options, @command, @args = options, command, args
18
18
  self
19
19
  end
data/test/client_test.rb CHANGED
@@ -9,6 +9,7 @@ class ClientTest < Test::Unit::TestCase
9
9
  assert_raises(ArgumentError) { Client.new({}) }
10
10
  assert_raises(ArgumentError) { Client.new({ :password => "bar" }) }
11
11
  assert_raises(ArgumentError) { Client.new({ :username => "", :password => "bar" }) }
12
+ assert_nothing_raised { Client.new({ :username => "foo", :password => "bar" }) }
12
13
  end
13
14
 
14
15
  should "use default num of statuses if not configured otherwise" do
@@ -112,7 +113,7 @@ class ClientTest < Test::Unit::TestCase
112
113
  @client.user
113
114
  end
114
115
 
115
- should "post a status update, when positive confirmation" do
116
+ should "post a status update via argument, when positive confirmation" do
116
117
  status = {
117
118
  "created_at" => Time.at(1).to_s,
118
119
  "user" => { "username" => "foo" },
@@ -127,7 +128,23 @@ class ClientTest < Test::Unit::TestCase
127
128
  @client.update("wondering about")
128
129
  end
129
130
 
130
- should "cancel a status update, when negative confirmation" do
131
+ should "post a status update via prompt, when positive confirmation" do
132
+ status = {
133
+ "created_at" => Time.at(1).to_s,
134
+ "user" => { "username" => "foo" },
135
+ "text" => "wondering about"
136
+ }
137
+ RestClient.expects(:post) \
138
+ .with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
139
+ .returns(status.to_json)
140
+ @io.expects(:prompt).with("Status update").returns("wondering about")
141
+ @io.expects(:confirm).with("Really send?").returns(true)
142
+ @io.expects(:info).with("Sent status update.\n\n")
143
+ @io.expects(:show_statuses).with([status])
144
+ @client.update
145
+ end
146
+
147
+ should "cancel a status update via argument, when negative confirmation" do
131
148
  RestClient.expects(:post).never
132
149
  @io.expects(:confirm).with("Really send?").returns(false)
133
150
  @io.expects(:info).with("Cancelled.")
@@ -135,7 +152,33 @@ class ClientTest < Test::Unit::TestCase
135
152
  @client.update("wondering about")
136
153
  end
137
154
 
138
- should "truncate a status update too long and warn the user" do
155
+ should "cancel a status update via prompt, when negative confirmation" do
156
+ RestClient.expects(:post).never
157
+ @io.expects(:prompt).with("Status update").returns("wondering about")
158
+ @io.expects(:confirm).with("Really send?").returns(false)
159
+ @io.expects(:info).with("Cancelled.")
160
+ @io.expects(:show_statuses).never
161
+ @client.update
162
+ end
163
+
164
+ should "cancel a status update via argument, when empty status" do
165
+ RestClient.expects(:post).never
166
+ @io.expects(:confirm).never
167
+ @io.expects(:info).with("Cancelled.")
168
+ @io.expects(:show_statuses).never
169
+ @client.update("")
170
+ end
171
+
172
+ should "cancel a status update via prompt, when empty status" do
173
+ RestClient.expects(:post).never
174
+ @io.expects(:prompt).with("Status update").returns("")
175
+ @io.expects(:confirm).never
176
+ @io.expects(:info).with("Cancelled.")
177
+ @io.expects(:show_statuses).never
178
+ @client.update
179
+ end
180
+
181
+ should "truncate a status update with too long argument and warn the user" do
139
182
  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"
140
183
  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"
141
184
  status = {
@@ -147,7 +190,7 @@ class ClientTest < Test::Unit::TestCase
147
190
  RestClient.expects(:post) \
148
191
  .with("https://foo:bar@twitter.com/statuses/update.json", {:status => truncated_status_update}) \
149
192
  .returns(status.to_json)
150
- @io.expects(:warn).with("Update will be truncated: #{truncated_status_update}")
193
+ @io.expects(:warn).with("Status will be truncated: #{truncated_status_update}")
151
194
  @io.expects(:confirm).with("Really send?").returns(true)
152
195
  @io.expects(:info).with("Sent status update.\n\n")
153
196
  @io.expects(:show_statuses).with([status])
@@ -22,6 +22,24 @@ class StartupConfigTest < Test::Unit::TestCase
22
22
  assert_equal :default_action, @config.command
23
23
  end
24
24
 
25
+ should "check that given command is supported" do
26
+ @config.parse(%w{default_action}) { |args| {} }
27
+ assert_equal :default_action, @config.command
28
+
29
+ @config.parse(%w{another_action}) { |args| {} }
30
+ assert_equal :another_action, @config.command
31
+ end
32
+
33
+ should "parse cmdline args, command, and leftover args" do
34
+ @config.parse(%w{--opt foo another_action left overs}) do |args|
35
+ args.slice!(0..1)
36
+ {:opt => "foo"}
37
+ end
38
+ assert_equal({:opt => "foo"}, @config.options)
39
+ assert_equal :another_action, @config.command
40
+ assert_equal %w{left overs}, @config.args
41
+ end
42
+
25
43
  context "when given no cmdline args and a config file" do
26
44
  setup do
27
45
  @config.parse([], TEST_CONFIG_FILE)
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-05-05 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -63,7 +63,7 @@ homepage: http://github.com/tuomas/tweetwine
63
63
  post_install_message:
64
64
  rdoc_options:
65
65
  - --title
66
- - Tweetwine 0.1.2
66
+ - Tweetwine 0.1.3
67
67
  - --main
68
68
  - README.rdoc
69
69
  - --exclude