tuomas-tweetwine 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/Rakefile +1 -0
- data/bin/tweetwine +50 -38
- data/lib/tweetwine/client.rb +6 -5
- data/lib/tweetwine/io.rb +1 -1
- data/lib/tweetwine/meta.rb +1 -1
- data/lib/tweetwine/rest_client_wrapper.rb +24 -4
- data/lib/tweetwine/url_shortener.rb +3 -2
- data/lib/tweetwine/util.rb +1 -1
- data/test/client_test.rb +340 -332
- data/test/io_test.rb +140 -143
- data/test/options_test.rb +1 -1
- data/test/rest_client_wrapper_test.rb +42 -5
- data/test/startup_config_test.rb +56 -54
- data/test/url_shortener_test.rb +135 -102
- data/test/util_test.rb +16 -18
- metadata +5 -4
data/test/url_shortener_test.rb
CHANGED
@@ -3,123 +3,156 @@ require "test_helper"
|
|
3
3
|
module Tweetwine
|
4
4
|
|
5
5
|
class UrlShortenerTest < Test::Unit::TestCase
|
6
|
-
context "
|
7
|
-
|
8
|
-
|
9
|
-
UrlShortener.new({
|
10
|
-
:service_url => nil,
|
11
|
-
:url_param_name => "url",
|
12
|
-
:xpath_selector => "//input[@id='short_url']/@value"
|
13
|
-
})
|
14
|
-
end
|
6
|
+
context "An UrlShortener instance" do
|
7
|
+
setup do
|
8
|
+
@rest_client = mock()
|
15
9
|
end
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
context "upon initialization" do
|
12
|
+
should "raise exception if service URL is not given" do
|
13
|
+
assert_raise(ArgumentError) do
|
14
|
+
UrlShortener.new(
|
15
|
+
@rest_client,
|
16
|
+
{
|
17
|
+
:service_url => nil,
|
18
|
+
:url_param_name => "url",
|
19
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
20
|
+
}
|
21
|
+
)
|
22
|
+
end
|
24
23
|
end
|
25
|
-
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
should "raise exception if URL parameter name is not given" do
|
26
|
+
assert_raise(ArgumentError) do
|
27
|
+
UrlShortener.new(
|
28
|
+
@rest_client,
|
29
|
+
{
|
30
|
+
:service_url => "http://shorten.it/create",
|
31
|
+
:url_param_name => nil,
|
32
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
context "An URL shortener configured for HTTP GET" do
|
49
|
-
should "use parameters as URL query parameters, with just the URL parameter" do
|
50
|
-
url_shortener = UrlShortener.new({
|
51
|
-
:method => "get",
|
52
|
-
:service_url => "http://shorten.it/create",
|
53
|
-
:url_param_name => "url",
|
54
|
-
:xpath_selector => "//input[@id='short_url']/@value"
|
55
|
-
})
|
56
|
-
RestClientWrapper.expects(:get) \
|
57
|
-
.with("http://shorten.it/create?url=http://www.ruby-doc.org/core/")
|
58
|
-
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
38
|
+
should "raise exception if XPath selector is not given" do
|
39
|
+
assert_raise(ArgumentError) do
|
40
|
+
UrlShortener.new(
|
41
|
+
@rest_client,
|
42
|
+
{
|
43
|
+
:service_url => "http://shorten.it/create",
|
44
|
+
:url_param_name => "url",
|
45
|
+
:xpath_selector => nil
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
59
49
|
end
|
60
50
|
|
61
|
-
should "
|
62
|
-
url_shortener = UrlShortener.new(
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
:
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
RestClientWrapper.expects(:get) \
|
72
|
-
.with("http://shorten.it/create?token=xyz&url=http://www.ruby-doc.org/core/")
|
73
|
-
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
51
|
+
should "fallback to use GET method if not given explicitly" do
|
52
|
+
url_shortener = UrlShortener.new(
|
53
|
+
@rest_client,
|
54
|
+
{
|
55
|
+
:service_url => "http://shorten.it/create",
|
56
|
+
:url_param_name => "url",
|
57
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
58
|
+
}
|
59
|
+
)
|
60
|
+
assert_equal(:get, url_shortener.instance_variable_get(:@method))
|
74
61
|
end
|
75
62
|
end
|
76
63
|
|
77
|
-
context "
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
64
|
+
context "at runtime" do
|
65
|
+
context "configured for HTTP GET" do
|
66
|
+
should "use parameters as URL query parameters, with just the URL parameter" do
|
67
|
+
url_shortener = UrlShortener.new(
|
68
|
+
@rest_client,
|
69
|
+
{
|
70
|
+
:method => "get",
|
71
|
+
:service_url => "http://shorten.it/create",
|
72
|
+
:url_param_name => "url",
|
73
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
74
|
+
}
|
75
|
+
)
|
76
|
+
@rest_client.expects(:get) \
|
77
|
+
.with("http://shorten.it/create?url=http://www.ruby-doc.org/core/")
|
78
|
+
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
79
|
+
end
|
80
|
+
|
81
|
+
should "use parameters as URL query parameters, with additional extra parameters" do
|
82
|
+
url_shortener = UrlShortener.new(
|
83
|
+
@rest_client,
|
84
|
+
{
|
85
|
+
:method => "get",
|
86
|
+
:service_url => "http://shorten.it/create",
|
87
|
+
:url_param_name => "url",
|
88
|
+
:extra_params => {
|
89
|
+
:token => "xyz"
|
90
|
+
},
|
91
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
92
|
+
}
|
93
|
+
)
|
94
|
+
@rest_client.expects(:get) \
|
95
|
+
.with("http://shorten.it/create?token=xyz&url=http://www.ruby-doc.org/core/")
|
96
|
+
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
97
|
+
end
|
88
98
|
end
|
89
99
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
:
|
103
|
-
|
104
|
-
|
105
|
-
|
100
|
+
context "configured for HTTP POST" do
|
101
|
+
should "use parameters as payload, with just the URL parameter" do
|
102
|
+
url_shortener = UrlShortener.new(
|
103
|
+
@rest_client,
|
104
|
+
{
|
105
|
+
:method => "post",
|
106
|
+
:service_url => "http://shorten.it/create",
|
107
|
+
:url_param_name => "url",
|
108
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
109
|
+
}
|
110
|
+
)
|
111
|
+
@rest_client.expects(:post) \
|
112
|
+
.with("http://shorten.it/create", {:url => "http://www.ruby-doc.org/core/"})
|
113
|
+
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
114
|
+
end
|
115
|
+
|
116
|
+
should "use parameters as payload, with additional extra parameters" do
|
117
|
+
url_shortener = UrlShortener.new(
|
118
|
+
@rest_client,
|
119
|
+
{
|
120
|
+
:method => "post",
|
121
|
+
:service_url => "http://shorten.it/create",
|
122
|
+
:url_param_name => "url",
|
123
|
+
:extra_params => {
|
124
|
+
:token => "xyz"
|
125
|
+
},
|
126
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
127
|
+
}
|
128
|
+
)
|
129
|
+
@rest_client.expects(:post) \
|
130
|
+
.with("http://shorten.it/create", {
|
131
|
+
:token => "xyz",
|
132
|
+
:url => "http://www.ruby-doc.org/core/"
|
133
|
+
})
|
134
|
+
url_shortener.shorten("http://www.ruby-doc.org/core/")
|
135
|
+
end
|
106
136
|
end
|
107
|
-
end
|
108
137
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
138
|
+
context "in erroenous situations" do
|
139
|
+
should "raise ClientError upon connection error" do
|
140
|
+
url_shortener = UrlShortener.new(
|
141
|
+
@rest_client,
|
142
|
+
{
|
143
|
+
:method => "post",
|
144
|
+
:service_url => "http://shorten.it/create",
|
145
|
+
:url_param_name => "url",
|
146
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
147
|
+
}
|
148
|
+
)
|
149
|
+
@rest_client.expects(:post) \
|
150
|
+
.with("http://shorten.it/create", {
|
151
|
+
:url => "http://www.ruby-doc.org/core/"
|
152
|
+
}) \
|
153
|
+
.raises(ClientError, "connection error")
|
154
|
+
assert_raise(ClientError) { url_shortener.shorten("http://www.ruby-doc.org/core/") }
|
155
|
+
end
|
123
156
|
end
|
124
157
|
end
|
125
158
|
end
|
data/test/util_test.rb
CHANGED
@@ -4,24 +4,22 @@ require "time"
|
|
4
4
|
module Tweetwine
|
5
5
|
|
6
6
|
class UtilTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal [2, "days"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-03 03:00"))
|
24
|
-
end
|
7
|
+
should "humanize time difference" do
|
8
|
+
assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 00:00:59").to_s, Time.parse("2009-01-01 00:01:00"))
|
9
|
+
assert_equal [0, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:00"))
|
10
|
+
assert_equal [1, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:01"))
|
11
|
+
assert_equal [59, "sec"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:00").to_s, Time.parse("2009-01-01 01:00:59"))
|
12
|
+
assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 01:59"))
|
13
|
+
assert_equal [59, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00:30").to_s, Time.parse("2009-01-01 01:59:00"))
|
14
|
+
assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:00"))
|
15
|
+
assert_equal [56, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:31").to_s, Time.parse("2009-01-01 01:58:00"))
|
16
|
+
assert_equal [57, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:29"))
|
17
|
+
assert_equal [58, "min"], Util.humanize_time_diff(Time.parse("2009-01-01 01:01:00").to_s, Time.parse("2009-01-01 01:58:30"))
|
18
|
+
assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 02:00"))
|
19
|
+
assert_equal [1, "hour"], Util.humanize_time_diff(Time.parse("2009-01-01 02:00").to_s, Time.parse("2009-01-01 01:00"))
|
20
|
+
assert_equal [2, "hours"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-01 03:00"))
|
21
|
+
assert_equal [1, "day"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-02 03:00"))
|
22
|
+
assert_equal [2, "days"], Util.humanize_time_diff(Time.parse("2009-01-01 01:00").to_s, Time.parse("2009-01-03 03:00"))
|
25
23
|
end
|
26
24
|
|
27
25
|
should "symbolize hash keys" do
|
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.2.
|
4
|
+
version: 0.2.4
|
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-09-
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
13
|
default_executable: tweetwine
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,10 +59,11 @@ files:
|
|
59
59
|
- test/util_test.rb
|
60
60
|
has_rdoc: false
|
61
61
|
homepage: http://github.com/tuomas/tweetwine
|
62
|
+
licenses:
|
62
63
|
post_install_message:
|
63
64
|
rdoc_options:
|
64
65
|
- --title
|
65
|
-
- tweetwine 0.2.
|
66
|
+
- tweetwine 0.2.4
|
66
67
|
- --main
|
67
68
|
- README.rdoc
|
68
69
|
- --exclude
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
86
|
requirements: []
|
86
87
|
|
87
88
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.3.5
|
89
90
|
signing_key:
|
90
91
|
specification_version: 3
|
91
92
|
summary: A simple Twitter agent for command line use
|