tweetwine 0.2.7 → 0.2.8

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.2.8 released 2010-01-17
2
+
3
+ * Unescape basic HTML encoding when displaying statuses
4
+ * Retry connection on timeout
5
+
1
6
  === 0.2.7 released 2009-12-22
2
7
 
3
8
  * Formatted help texts so that they do not exceed 80 chars in width.
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Tuomas Kareinen.
1
+ Copyright (c) 2009-2010 Tuomas Kareinen.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.rdoc CHANGED
@@ -83,4 +83,5 @@ com >.
83
83
 
84
84
  == Legal notes
85
85
 
86
- Copyright (c) 2009 Tuomas Kareinen. See MIT-LICENSE.txt in this directory.
86
+ Copyright (c) 2009-2010 Tuomas Kareinen. See MIT-LICENSE.txt in this
87
+ directory.
data/lib/tweetwine/io.rb CHANGED
@@ -90,6 +90,7 @@ module Tweetwine
90
90
  end
91
91
 
92
92
  def format_status(status)
93
+ status = Util.unescape_html(status)
93
94
  if @colors
94
95
  status = colorize_all_by_group(:yellow, status, USERNAME_REGEX)
95
96
  status = colorize_all_by_group(:magenta, status, HASHTAG_REGEX)
@@ -1,3 +1,3 @@
1
1
  module Tweetwine
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -27,7 +27,7 @@ module Tweetwine
27
27
  begin
28
28
  tries += 1
29
29
  yield
30
- rescue Errno::ECONNRESET => e
30
+ rescue Errno::ECONNRESET, RestClient::RequestTimeout => e
31
31
  if tries < MAX_RETRIES
32
32
  timeout = RETRY_BASE_WAIT_TIMEOUT**tries
33
33
  @io.warn("Could not connect -- retrying in #{timeout} seconds") if @io
@@ -1,3 +1,4 @@
1
+ require "cgi"
1
2
  require "time"
2
3
  require "uri"
3
4
 
@@ -64,6 +65,10 @@ module Tweetwine
64
65
  URI.escape(str.to_s, /[^#{URI::PATTERN::UNRESERVED}]/)
65
66
  end
66
67
 
68
+ def self.unescape_html(str)
69
+ CGI.unescapeHTML(str.gsub('&nbsp;', ' '))
70
+ end
71
+
67
72
  def self.find_hash_path(hash, path)
68
73
  return nil if hash.nil?
69
74
  path = [path] if !path.is_a? Array
data/test/io_test.rb CHANGED
@@ -99,6 +99,27 @@ class IOTest < Test::Unit::TestCase
99
99
  @io.show_record(record)
100
100
  end
101
101
 
102
+
103
+ should "unescape HTML in a status" do
104
+ from_user = "fooman"
105
+ escaped_status = "apple &gt; orange &amp; grapefruit &lt; banana"
106
+ unescaped_status = "apple > orange & grapefruit < banana"
107
+ record = {
108
+ :from_user => from_user,
109
+ :status => escaped_status,
110
+ :created_at => Time.at(1),
111
+ :to_user => nil
112
+ }
113
+ Util.expects(:humanize_time_diff).returns([2, "secs"])
114
+ @output.expects(:puts).with(<<-END
115
+ #{from_user}, 2 secs ago:
116
+ #{unescaped_status}
117
+
118
+ END
119
+ )
120
+ @io.show_record(record)
121
+ end
122
+
102
123
  should "output a preview of a status" do
103
124
  status = "@nick, check http://bit.ly/18rU_Vx"
104
125
  @output.expects(:puts).with(<<-END
@@ -40,24 +40,26 @@ class ClientTest < Test::Unit::TestCase
40
40
  assert_raise(HttpError) { @client.get("https://unresolved.org") }
41
41
  end
42
42
 
43
- should "retry connection upon connection reset" do
44
- retrying_calls = sequence("Retrying Client calls")
45
- RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls).raises(Errno::ECONNRESET)
46
- RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls)
47
- @io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
48
- @client.get("https://moderate.traffic.org")
49
- end
50
-
51
- should "retry connection a maximum of certain number of times" do
52
- retrying_calls = sequence("Retrying Client calls")
53
- io_calls = sequence("IO")
54
- Client::MAX_RETRIES.times do
55
- RestClient.expects(:get).with("https://unresponsive.org").in_sequence(retrying_calls).raises(Errno::ECONNRESET)
43
+ [Errno::ECONNRESET, RestClient::RequestTimeout].each do |error_class|
44
+ should "retry connection upon connection reset, case #{error_class}" do
45
+ retrying_calls = sequence("Retrying Client calls")
46
+ RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls).raises(error_class)
47
+ RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls)
48
+ @io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
49
+ @client.get("https://moderate.traffic.org")
56
50
  end
57
- (Client::MAX_RETRIES - 1).times do
58
- @io.expects(:warn).in_sequence(io_calls)
51
+
52
+ should "retry connection a maximum of certain number of times, case #{error_class}" do
53
+ retrying_calls = sequence("Retrying Client calls")
54
+ io_calls = sequence("IO")
55
+ Client::MAX_RETRIES.times do
56
+ RestClient.expects(:get).with("https://unresponsive.org").in_sequence(retrying_calls).raises(error_class)
57
+ end
58
+ (Client::MAX_RETRIES - 1).times do
59
+ @io.expects(:warn).in_sequence(io_calls)
60
+ end
61
+ assert_raise(HttpError) { @client.get("https://unresponsive.org") }
59
62
  end
60
- assert_raise(HttpError) { @client.get("https://unresponsive.org") }
61
63
  end
62
64
 
63
65
  should "return a resource with IO inherited from the client" do
@@ -101,24 +103,26 @@ class ResourceTest < Test::Unit::TestCase
101
103
  assert_raise(HttpError) { @resource.get }
102
104
  end
103
105
 
104
- should "retry connection upon connection reset" do
105
- retrying_calls = sequence("Retrying Resource calls")
106
- @wrapped.expects(:get).in_sequence(retrying_calls).raises(Errno::ECONNRESET)
107
- @wrapped.expects(:get).in_sequence(retrying_calls)
108
- @io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
109
- @resource.get
110
- end
111
-
112
- should "retry connection a maximum of certain number of times" do
113
- retrying_calls = sequence("Retrying Resource calls")
114
- io_calls = sequence("IO")
115
- Resource::MAX_RETRIES.times do
116
- @wrapped.expects(:get).in_sequence(retrying_calls).raises(Errno::ECONNRESET)
106
+ [Errno::ECONNRESET, RestClient::RequestTimeout].each do |error_class|
107
+ should "retry connection upon connection reset, case #{error_class}" do
108
+ retrying_calls = sequence("Retrying Resource calls")
109
+ @wrapped.expects(:get).in_sequence(retrying_calls).raises(error_class)
110
+ @wrapped.expects(:get).in_sequence(retrying_calls)
111
+ @io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
112
+ @resource.get
117
113
  end
118
- (Resource::MAX_RETRIES - 1).times do
119
- @io.expects(:warn).in_sequence(io_calls)
114
+
115
+ should "retry connection a maximum of certain number of times, case #{error_class}" do
116
+ retrying_calls = sequence("Retrying Resource calls")
117
+ io_calls = sequence("IO")
118
+ Resource::MAX_RETRIES.times do
119
+ @wrapped.expects(:get).in_sequence(retrying_calls).raises(error_class)
120
+ end
121
+ (Resource::MAX_RETRIES - 1).times do
122
+ @io.expects(:warn).in_sequence(io_calls)
123
+ end
124
+ assert_raise(HttpError) { @resource.get }
120
125
  end
121
- assert_raise(HttpError) { @resource.get }
122
126
  end
123
127
  end
124
128
  end
data/test/util_test.rb CHANGED
@@ -120,7 +120,7 @@ class UtilTest < Test::Unit::TestCase
120
120
  assert_equal "_", Util.percent_encode("_")
121
121
  end
122
122
 
123
- should "encode space character with precent-encoding, not with '+' character" do
123
+ should "encode space character with percent-encoding, not with '+' character" do
124
124
  assert_equal "%20", Util.percent_encode(" ")
125
125
  end
126
126
 
@@ -138,6 +138,26 @@ class UtilTest < Test::Unit::TestCase
138
138
  end
139
139
  end
140
140
 
141
+ context "for unescaping HTML" do
142
+ should "not affect already unescaped characters" do
143
+ assert_equal "a", Util.unescape_html("a")
144
+ assert_equal "B", Util.unescape_html("B")
145
+ assert_equal "3", Util.unescape_html("3")
146
+ assert_equal ".", Util.unescape_html(".")
147
+ assert_equal "-", Util.unescape_html("-")
148
+ assert_equal "_", Util.unescape_html("_")
149
+ assert_equal "+", Util.unescape_html("+")
150
+ end
151
+
152
+ should "unescape HTML-escaped characters" do
153
+ assert_equal "<", Util.unescape_html("&lt;")
154
+ assert_equal ">", Util.unescape_html("&gt;")
155
+ assert_equal "&", Util.unescape_html("&amp;")
156
+ assert_equal "\"", Util.unescape_html("&quot;")
157
+ assert_equal " ", Util.unescape_html("&nbsp;")
158
+ end
159
+ end
160
+
141
161
  context "for traversing a hash with a path expression for finding a value" do
142
162
  setup do
143
163
  @inner_hash = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetwine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
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-12-22 00:00:00 +02:00
12
+ date: 2010-01-17 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ licenses: []
80
80
  post_install_message:
81
81
  rdoc_options:
82
82
  - --title
83
- - tweetwine 0.2.7
83
+ - tweetwine 0.2.8
84
84
  - --main
85
85
  - README.rdoc
86
86
  - --exclude