tuomas-tweetwine 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.5 released 2009-06-06
2
+
3
+ * URLs of http(s) scheme are highlighted. Changed colors.
4
+ * Friendly abort message when interrupting the program with Ctrl+C.
5
+
1
6
  === 0.1.4 released 2009-05-12
2
7
 
3
8
  * Command line option "--page N" fetches a specific status page
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.4"
5
+ version = "0.1.5"
6
6
 
7
7
  require "lib/#{package_name}"
8
8
 
@@ -24,7 +24,7 @@ spec = Gem::Specification.new do |s|
24
24
  s.executables = ["tweetwine"]
25
25
 
26
26
  s.add_dependency("json", ">= 1.1.4")
27
- s.add_dependency("rest-client", ">= 0.9.2")
27
+ s.add_dependency("rest-client", ">= 1.0.0")
28
28
 
29
29
  s.has_rdoc = true
30
30
  s.extra_rdoc_files = FileList["*.rdoc"].to_a
data/bin/tweetwine CHANGED
@@ -5,6 +5,15 @@ require "optparse"
5
5
 
6
6
  require File.dirname(__FILE__) << "/../lib/tweetwine"
7
7
 
8
+ EXIT_HELP = 1
9
+ EXIT_SIGINT = 2
10
+ EXIT_ERROR = 64
11
+
12
+ trap("INT") do
13
+ puts "\nAbort."
14
+ exit(EXIT_SIGINT)
15
+ end
16
+
8
17
  include Tweetwine
9
18
 
10
19
  begin
@@ -35,7 +44,7 @@ Usage: tweetwine [options...] [command]
35
44
  end
36
45
  opt.on_tail("-h", "--help", "Show this help message") do
37
46
  puts opt
38
- exit(1)
47
+ exit(EXIT_HELP)
39
48
  end
40
49
  end.parse!(args)
41
50
  rescue OptionParser::ParseError => e
@@ -47,5 +56,5 @@ Usage: tweetwine [options...] [command]
47
56
  client.send(config.command, *config.args)
48
57
  rescue ArgumentError, ClientError => e
49
58
  puts "Error: #{e.message}"
50
- exit(2)
59
+ exit(EXIT_ERROR)
51
60
  end
@@ -18,8 +18,8 @@ module Tweetwine
18
18
  raise ArgumentError, "No authentication data given" if @username.empty?
19
19
  @base_url = "https://#{@username}:#{options[:password]}@twitter.com/"
20
20
  @colorize = options[:colorize] || false
21
- @num_statuses = parse_positive_int_option(options[:num_statuses], DEFAULT_NUM_STATUSES, 1, "number of statuses_to_show")
22
- @page_num = parse_positive_int_option(options[:page_num], DEFAULT_PAGE_NUM, 1, "page number")
21
+ @num_statuses = parse_int_gt_option(options[:num_statuses], DEFAULT_NUM_STATUSES, 1, "number of statuses_to_show")
22
+ @page_num = parse_int_gt_option(options[:page_num], DEFAULT_PAGE_NUM, 1, "page number")
23
23
  @io = IO.new(options)
24
24
  end
25
25
 
@@ -52,7 +52,7 @@ module Tweetwine
52
52
 
53
53
  private
54
54
 
55
- def parse_positive_int_option(value, default, min, name_for_error)
55
+ def parse_int_gt_option(value, default, min, name_for_error)
56
56
  if value
57
57
  value = value.to_i
58
58
  if value >= min
data/lib/tweetwine/io.rb CHANGED
@@ -38,7 +38,10 @@ module Tweetwine
38
38
  ""
39
39
  end
40
40
  text = status["text"]
41
- text = colorize(:red, text, /@\w+/) if @colorize
41
+ if @colorize
42
+ text = colorize(:yellow, text, NICK_REGEX)
43
+ text = colorize(:cyan, text, URL_REGEX)
44
+ end
42
45
  @output.puts <<-END
43
46
  #{from_user}, #{in_reply_to}#{time_diff_value} #{time_diff_unit} ago:
44
47
  #{text}
@@ -50,9 +53,17 @@ module Tweetwine
50
53
  private
51
54
 
52
55
  COLOR_CODES = {
53
- :green => "\033[32m",
54
- :red => "\033[31m"
55
- }
56
+ :cyan => 36,
57
+ :green => 32,
58
+ :magenta => 35,
59
+ :yellow => 33
60
+ }.inject({}) do |result, pair|
61
+ result[pair.first.to_sym] = "\033[#{pair.last}m"
62
+ result
63
+ end
64
+
65
+ NICK_REGEX = /@\w+/
66
+ URL_REGEX = /(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/\S*)?/i
56
67
 
57
68
  def colorize(color, str, matcher = nil)
58
69
  color_code = COLOR_CODES[color.to_sym]
data/test/io_test.rb CHANGED
@@ -108,7 +108,7 @@ Hi, @barman! Lulz woo!
108
108
  Util.expects(:humanize_time_diff).returns([2, "secs"])
109
109
  @output.expects(:puts).with(<<-END
110
110
  \033[32mfooman\033[0m, 2 secs ago:
111
- Hi, \033[31m@barman\033[0m! Lulz woo!
111
+ Hi, \033[33m@barman\033[0m! Lulz woo!
112
112
 
113
113
  END
114
114
  )
@@ -121,13 +121,13 @@ Hi, \033[31m@barman\033[0m! Lulz woo!
121
121
  "created_at" => Time.at(1),
122
122
  "in_reply_to_screen_name" => "barman",
123
123
  "user" => { "screen_name" => "fooman" },
124
- "text" => "Hi, @barman! Lulz woo!"
124
+ "text" => "Hi, @barman! Check this: http://www.foo.com. Nice, isn't it?"
125
125
  }
126
126
  ]
127
127
  Util.expects(:humanize_time_diff).returns([2, "secs"])
128
128
  @output.expects(:puts).with(<<-END
129
129
  \033[32mfooman\033[0m, in reply to \033[32mbarman\033[0m, 2 secs ago:
130
- Hi, \033[31m@barman\033[0m! Lulz woo!
130
+ Hi, \033[33m@barman\033[0m! Check this: \033[36mhttp://www.foo.com\033[0m. Nice, isn't it?
131
131
 
132
132
  END
133
133
  )
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
4
+ version: 0.1.5
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-12 00:00:00 -07:00
12
+ date: 2009-06-06 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.2
33
+ version: 1.0.0
34
34
  version:
35
35
  description: A simple but tasty Twitter agent for command line use, made for fun.
36
36
  email: tkareine@gmail.com
@@ -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.4
66
+ - Tweetwine 0.1.5
67
67
  - --main
68
68
  - README.rdoc
69
69
  - --exclude