tuomas-tweetwine 0.1.9 → 0.1.10

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,7 @@
1
+ === 0.1.10 released 2009-08-09
2
+
3
+ * Improved URL highlight support.
4
+
1
5
  === 0.1.9 released 2009-07-15
2
6
 
3
7
  * Added commands "friends" and "followers"
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.9"
5
+ version = "0.1.10"
6
6
 
7
7
  require "lib/#{package_name}"
8
8
 
data/lib/tweetwine/io.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "uri"
2
+
1
3
  module Tweetwine
2
4
  class IO
3
5
  COLOR_CODES = {
@@ -8,7 +10,6 @@ module Tweetwine
8
10
  }
9
11
 
10
12
  NICK_REGEX = /@\w+/
11
- URL_REGEX = /(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(:[0-9]{2,5})?(((\/[a-z0-9_\-]+)+\/?)|(\/))?/i
12
13
 
13
14
  def initialize(options)
14
15
  @input = options[:input] || $stdin
@@ -46,18 +47,18 @@ module Tweetwine
46
47
  def show_as_status(record)
47
48
  time_diff_value, time_diff_unit = Util.humanize_time_diff(record[:status][:created_at], Time.now)
48
49
  from_user = record[:user]
49
- from_user = colorize(:green, from_user) if @colorize
50
+ colorize!(:green, from_user) if @colorize
50
51
  in_reply_to = record[:status][:in_reply_to]
51
52
  in_reply_to = if in_reply_to && !in_reply_to.empty?
52
- in_reply_to = colorize(:green, in_reply_to) if @colorize
53
+ colorize!(:green, in_reply_to) if @colorize
53
54
  "in reply to #{in_reply_to}, "
54
55
  else
55
56
  ""
56
57
  end
57
58
  status = record[:status][:text]
58
59
  if @colorize
59
- status = colorize(:yellow, status, NICK_REGEX)
60
- status = colorize(:cyan, status, URL_REGEX)
60
+ colorize!(:yellow, status, [NICK_REGEX])
61
+ colorize!(:cyan, status, URI.extract(status, ["http", "https"]))
61
62
  end
62
63
  @output.puts <<-END
63
64
  #{from_user}, #{in_reply_to}#{time_diff_value} #{time_diff_unit} ago:
@@ -68,7 +69,7 @@ module Tweetwine
68
69
 
69
70
  def show_as_user(record)
70
71
  user = record[:user]
71
- user = colorize(:green, user) if @colorize
72
+ colorize!(:green, user) if @colorize
72
73
  @output.puts <<-END
73
74
  #{user}
74
75
 
@@ -77,13 +78,15 @@ module Tweetwine
77
78
 
78
79
  private
79
80
 
80
- def colorize(color, str, matcher = nil)
81
+ def colorize!(color, str, patterns = nil)
81
82
  color_code = COLOR_CODES[color.to_sym]
82
83
 
83
- unless matcher
84
- colorize_str(color_code, str)
84
+ if patterns
85
+ patterns.each do |pattern|
86
+ str.sub!(pattern) { |s| colorize_str(color_code, s) }
87
+ end
85
88
  else
86
- str.gsub(matcher) { |s| colorize_str(color_code, s) }
89
+ str.replace colorize_str(color_code, str)
87
90
  end
88
91
  end
89
92
 
data/test/client_test.rb CHANGED
@@ -156,7 +156,7 @@ class ClientTest < Test::Unit::TestCase
156
156
  :text => "wondering around",
157
157
  :in_reply_to => nil
158
158
  }
159
- },
159
+ }
160
160
  )
161
161
  RestClient.expects(:post) \
162
162
  .with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
@@ -175,7 +175,7 @@ class ClientTest < Test::Unit::TestCase
175
175
  :text => "wondering around",
176
176
  :in_reply_to => nil
177
177
  }
178
- },
178
+ }
179
179
  )
180
180
  RestClient.expects(:post) \
181
181
  .with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
@@ -231,7 +231,7 @@ class ClientTest < Test::Unit::TestCase
231
231
  :text => truncated_status_update,
232
232
  :in_reply_to => nil
233
233
  }
234
- },
234
+ }
235
235
  )
236
236
  RestClient.expects(:post) \
237
237
  .with("https://foo:bar@twitter.com/statuses/update.json", {:status => truncated_status_update}) \
data/test/io_test.rb CHANGED
@@ -85,14 +85,14 @@ Hi, @barman! Lulz woo!
85
85
  :user => "barman",
86
86
  :status => {
87
87
  :created_at => Time.at(1),
88
- :text => "Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?",
88
+ :text => "Hi, @fooman! How are you doing?",
89
89
  :in_reply_to => "fooman"
90
90
  }
91
91
  }
92
92
  Util.expects(:humanize_time_diff).returns([2, "secs"])
93
93
  @output.expects(:puts).with(<<-END
94
94
  barman, in reply to fooman, 2 secs ago:
95
- Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?
95
+ Hi, @fooman! How are you doing?
96
96
 
97
97
  END
98
98
  )
@@ -140,14 +140,32 @@ Hi, \033[33m@barman\033[0m! Lulz woo!
140
140
  :user => "barman",
141
141
  :status => {
142
142
  :created_at => Time.at(1),
143
- :text => "Hi, @fooman! Check this: http://www.foo.com. Nice, isn't it?",
143
+ :text => "Hi, @fooman! How are you doing?",
144
144
  :in_reply_to => "fooman"
145
145
  }
146
146
  }
147
147
  Util.expects(:humanize_time_diff).returns([2, "secs"])
148
148
  @output.expects(:puts).with(<<-END
149
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?
150
+ Hi, \033[33m@fooman\033[0m! How are you doing?
151
+
152
+ END
153
+ )
154
+ @io.show(record)
155
+ end
156
+
157
+ should "highlight HTTP and HTTPS URIs in a status" do
158
+ record = {
159
+ :user => "barman",
160
+ :status => {
161
+ :created_at => Time.at(1),
162
+ :text => "Three links: http://bit.ly/18rU_Vx http://is.gd/1qLk3 and https://is.gd/2rLk4",
163
+ }
164
+ }
165
+ Util.expects(:humanize_time_diff).returns([2, "secs"])
166
+ @output.expects(:puts).with(<<-END
167
+ \033[32mbarman\033[0m, 2 secs ago:
168
+ Three links: \033[36mhttp://bit.ly/18rU_Vx\033[0m \033[36mhttp://is.gd/1qLk3\033[0m and \033[36mhttps://is.gd/2rLk4\033[0m
151
169
 
152
170
  END
153
171
  )
@@ -167,43 +185,6 @@ Hi, \033[33m@fooman\033[0m! Check this: \033[36mhttp://www.foo.com\033[0m. Nice,
167
185
  assert_no_full_match IO::NICK_REGEX, "@nick-man"
168
186
  end
169
187
  end
170
-
171
- context "URL regex" do
172
- should "match an IP" do
173
- assert_full_match IO::URL_REGEX, "http://127.0.0.1"
174
- assert_full_match IO::URL_REGEX, "http://127.0.0.1/"
175
- assert_full_match IO::URL_REGEX, "https://127.0.0.1"
176
- assert_full_match IO::URL_REGEX, "https://127.0.0.1/"
177
- end
178
-
179
- should "match a FQDN" do
180
- assert_full_match IO::URL_REGEX, "https://fo.com"
181
- assert_full_match IO::URL_REGEX, "https://fo.com/"
182
- assert_full_match IO::URL_REGEX, "http://www.foo.com"
183
- assert_full_match IO::URL_REGEX, "http://www.foo.com/"
184
- assert_full_match IO::URL_REGEX, "https://www.foo.com"
185
- assert_full_match IO::URL_REGEX, "https://www.foo.com/"
186
- end
187
-
188
- should "respect whitespace, parentheses, periods, etc. at the end" do
189
- assert_full_match IO::URL_REGEX, "http://tr.im/WGAP"
190
- assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP "
191
- assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP)"
192
- assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP."
193
- assert_no_full_match IO::URL_REGEX, "http://tr.im/WGAP,"
194
- end
195
-
196
- should "match multipart URLs" do
197
- assert_full_match IO::URL_REGEX, "http://technomancy.us/126"
198
- assert_full_match IO::URL_REGEX, "http://technomancy.us/126/"
199
- assert_full_match IO::URL_REGEX, "http://bit.ly/18rUVx"
200
- assert_full_match IO::URL_REGEX, "http://bit.ly/18rUVx/"
201
- assert_full_match IO::URL_REGEX, "http://bit.ly/18rU_Vx"
202
- assert_full_match IO::URL_REGEX, "http://bit.ly/18rU_Vx/"
203
- assert_full_match IO::URL_REGEX, "http://www.ireport.com/docs/DOC-266869"
204
- assert_full_match IO::URL_REGEX, "http://www.ireport.com/docs/DOC-266869/"
205
- end
206
- end
207
188
  end
208
189
 
209
190
  end
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.9
4
+ version: 0.1.10
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-07-15 00:00:00 -07:00
12
+ date: 2009-08-09 00:00:00 -07:00
13
13
  default_executable: tweetwine
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,10 +50,11 @@ files:
50
50
  - test/util_test.rb
51
51
  has_rdoc: false
52
52
  homepage: http://github.com/tuomas/tweetwine
53
+ licenses:
53
54
  post_install_message:
54
55
  rdoc_options:
55
56
  - --title
56
- - Tweetwine 0.1.9
57
+ - Tweetwine 0.1.10
57
58
  - --main
58
59
  - README.rdoc
59
60
  - --exclude
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements: []
77
78
 
78
79
  rubyforge_project:
79
- rubygems_version: 1.2.0
80
+ rubygems_version: 1.3.5
80
81
  signing_key:
81
82
  specification_version: 3
82
83
  summary: A simple Twitter agent for command line use