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 +5 -0
- data/MIT-LICENSE.txt +1 -1
- data/README.rdoc +2 -1
- data/lib/tweetwine/io.rb +1 -0
- data/lib/tweetwine/meta.rb +1 -1
- data/lib/tweetwine/retrying_http.rb +1 -1
- data/lib/tweetwine/util.rb +5 -0
- data/test/io_test.rb +21 -0
- data/test/retrying_http_test.rb +36 -32
- data/test/util_test.rb +21 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/MIT-LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
data/lib/tweetwine/io.rb
CHANGED
data/lib/tweetwine/meta.rb
CHANGED
@@ -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
|
data/lib/tweetwine/util.rb
CHANGED
@@ -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(' ', ' '))
|
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 > orange & grapefruit < 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
|
data/test/retrying_http_test.rb
CHANGED
@@ -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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
58
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
119
|
-
|
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
|
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("<")
|
154
|
+
assert_equal ">", Util.unescape_html(">")
|
155
|
+
assert_equal "&", Util.unescape_html("&")
|
156
|
+
assert_equal "\"", Util.unescape_html(""")
|
157
|
+
assert_equal " ", Util.unescape_html(" ")
|
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.
|
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:
|
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.
|
83
|
+
- tweetwine 0.2.8
|
84
84
|
- --main
|
85
85
|
- README.rdoc
|
86
86
|
- --exclude
|