ideaoforder-www-delicious 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +46 -0
- data/Manifest +49 -0
- data/README.rdoc +209 -0
- data/Rakefile +55 -0
- data/lib/www/delicious/bundle.rb +73 -0
- data/lib/www/delicious/element.rb +73 -0
- data/lib/www/delicious/errors.rb +46 -0
- data/lib/www/delicious/post.rb +123 -0
- data/lib/www/delicious/tag.rb +101 -0
- data/lib/www/delicious/version.rb +29 -0
- data/lib/www/delicious.rb +949 -0
- data/setup.rb +1585 -0
- data/test/fixtures/net_response_invalid_account.yml +25 -0
- data/test/fixtures/net_response_success.yml +23 -0
- data/test/helper.rb +49 -0
- data/test/test_all.rb +18 -0
- data/test/test_offline.rb +18 -0
- data/test/test_online.rb +20 -0
- data/test/testcases/element/bundle.xml +1 -0
- data/test/testcases/element/invalid_root.xml +2 -0
- data/test/testcases/element/post.xml +2 -0
- data/test/testcases/element/post_unshared.xml +2 -0
- data/test/testcases/element/tag.xml +1 -0
- data/test/testcases/response/bundles_all.xml +5 -0
- data/test/testcases/response/bundles_all_empty.xml +2 -0
- data/test/testcases/response/bundles_delete.xml +2 -0
- data/test/testcases/response/bundles_set.xml +2 -0
- data/test/testcases/response/bundles_set_error.xml +2 -0
- data/test/testcases/response/posts_add.xml +2 -0
- data/test/testcases/response/posts_all.xml +12 -0
- data/test/testcases/response/posts_dates.xml +14 -0
- data/test/testcases/response/posts_dates_with_tag.xml +14 -0
- data/test/testcases/response/posts_delete.xml +2 -0
- data/test/testcases/response/posts_get.xml +7 -0
- data/test/testcases/response/posts_get_with_tag.xml +6 -0
- data/test/testcases/response/posts_recent.xml +19 -0
- data/test/testcases/response/posts_recent_with_tag.xml +19 -0
- data/test/testcases/response/tags_get.xml +5 -0
- data/test/testcases/response/tags_get_empty.xml +2 -0
- data/test/testcases/response/tags_rename.xml +2 -0
- data/test/testcases/response/update.delicious1.xml +2 -0
- data/test/testcases/response/update.xml +3 -0
- data/test/unit/bundle_test.rb +63 -0
- data/test/unit/delicious_test.rb +369 -0
- data/test/unit/online/online_test.rb +148 -0
- data/test/unit/post_test.rb +68 -0
- data/test/unit/tag_test.rb +69 -0
- data/www-delicious.gemspec +146 -0
- metadata +143 -0
@@ -0,0 +1,369 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/../helper'
|
18
|
+
|
19
|
+
|
20
|
+
class DeliciousTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
TEST_USERNAME = 'username'
|
23
|
+
TEST_PASSWORD = 'password'
|
24
|
+
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@delicious = instance
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def test_initialize_raises_without_account
|
32
|
+
assert_raise(ArgumentError) { WWW::Delicious.new() }
|
33
|
+
assert_raise(ArgumentError) { WWW::Delicious.new(TEST_USERNAME) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_initialize_account
|
37
|
+
assert_equal(TEST_USERNAME, @delicious.username)
|
38
|
+
assert_equal(TEST_PASSWORD, @delicious.password)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_initialize_option_user_agent
|
42
|
+
useragent = 'MyClass/1.0 (Foo/Bar +http://foo.com/)'
|
43
|
+
delicious = instance(:user_agent => useragent)
|
44
|
+
assert_equal(useragent, delicious.user_agent)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_initialize_option_user_agent_default
|
48
|
+
useragent = instance.user_agent
|
49
|
+
assert_match("Ruby/#{RUBY_VERSION}", useragent)
|
50
|
+
assert_match("#{WWW::Delicious::NAME}/#{WWW::Delicious::VERSION}", useragent)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_initialize_option_base_uri
|
54
|
+
base_uri = 'https://ma.gnolia.com/api/mirrord'
|
55
|
+
delicious = instance(:base_uri => base_uri)
|
56
|
+
assert_equal(URI.parse(base_uri), delicious.base_uri)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_initialize_option_base_uri_default
|
60
|
+
base_uri = instance.base_uri
|
61
|
+
assert_equal(URI.parse('https://api.del.icio.us'), base_uri)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# =========================================================================
|
66
|
+
# HTTP Request common checks
|
67
|
+
# =========================================================================
|
68
|
+
|
69
|
+
def test_request_raises_without_http_client
|
70
|
+
@delicious.http_client = nil
|
71
|
+
assert_raise(WWW::Delicious::Error) { @delicious.update }
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_request_waits_necessary_time_between_requests
|
75
|
+
@delicious.expects(:make_request).times(4).returns(load_fixture('/net_response_success.yml'))
|
76
|
+
@delicious.valid_account? # 1st request
|
77
|
+
3.times do |time|
|
78
|
+
lr = @delicious.instance_variable_get(:@last_request)
|
79
|
+
@delicious.valid_account? # N request
|
80
|
+
nr = @delicious.instance_variable_get(:@last_request)
|
81
|
+
assert((nr - lr) > WWW::Delicious::SECONDS_BEFORE_NEW_REQUEST)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def test_valid_account
|
87
|
+
@delicious.expects(:make_request).once.returns(load_fixture('/net_response_success.yml'))
|
88
|
+
assert(@delicious.valid_account?)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_invalid_account
|
92
|
+
@delicious.expects(:make_request).once.returns(load_fixture('/net_response_invalid_account.yml'))
|
93
|
+
assert(!@delicious.valid_account?)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# =========================================================================
|
98
|
+
# Update
|
99
|
+
# =========================================================================
|
100
|
+
|
101
|
+
def test_update
|
102
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
103
|
+
assert_equal(@delicious.update, Time.parse("2008-08-02T11:55:35Z"))
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_update_raises_without_update_root_node
|
107
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all.xml'))
|
108
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
109
|
+
@delicious.update
|
110
|
+
end
|
111
|
+
assert_match(/`update`/, error.message)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_update_delicious1
|
115
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.delicious1.xml'))
|
116
|
+
assert_equal(@delicious.update, Time.parse("2008-03-12T08:41:20Z"))
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# =========================================================================
|
121
|
+
# Bundles
|
122
|
+
# =========================================================================
|
123
|
+
|
124
|
+
def test_bundles_all
|
125
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all.xml'))
|
126
|
+
expected = [ ['music', %w(ipod mp3 music)], ['pc', %w(computer software hardware)] ]
|
127
|
+
|
128
|
+
results = @delicious.bundles_all
|
129
|
+
assert_instance_of(Array, results)
|
130
|
+
assert_equal(2, results.length)
|
131
|
+
|
132
|
+
results.each_with_index do |bundle, index|
|
133
|
+
assert_instance_of(WWW::Delicious::Bundle, bundle)
|
134
|
+
name, tags = expected[index]
|
135
|
+
assert_equal(name, bundle.name)
|
136
|
+
assert_equal(tags, bundle.tags)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_bundles_all_empty
|
141
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_all_empty.xml'))
|
142
|
+
results = @delicious.bundles_all
|
143
|
+
assert_instance_of(Array, results)
|
144
|
+
assert_equal(0, results.length)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_bundles_all_raises_without_bundles_root_node
|
148
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
149
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
150
|
+
@delicious.bundles_all
|
151
|
+
end
|
152
|
+
assert_match(/`bundles`/, error.message)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def test_bundles_set
|
157
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_set.xml'))
|
158
|
+
assert(@delicious.bundles_set('name', %w(foo bar)))
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_bundles_set_raises_with_response_error
|
162
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_set_error.xml'))
|
163
|
+
error = assert_raise(WWW::Delicious::Error) do
|
164
|
+
@delicious.bundles_set('name', %w(foo bar))
|
165
|
+
end
|
166
|
+
assert_match(/you must supply a bundle name/, error.message)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_bundles_set_raises_without_result_root_node
|
170
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
171
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
172
|
+
@delicious.bundles_set('name', %w(foo bar))
|
173
|
+
end
|
174
|
+
assert_match(/`result`/, error.message)
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
def test_bundles_delete
|
179
|
+
@delicious.expects(:request).once.returns(mock_response('/response/bundles_delete.xml'))
|
180
|
+
assert(@delicious.bundles_delete('name'))
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_bundles_delete_raises_without_result_root_node
|
184
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
185
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
186
|
+
@delicious.bundles_delete('name')
|
187
|
+
end
|
188
|
+
assert_match(/`result`/, error.message)
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
# =========================================================================
|
193
|
+
# Tags
|
194
|
+
# =========================================================================
|
195
|
+
|
196
|
+
def test_tags_get
|
197
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_get.xml'))
|
198
|
+
expected = [ ['activedesktop', 1], ['business', 14] ]
|
199
|
+
|
200
|
+
results = @delicious.tags_get
|
201
|
+
assert_instance_of(Array, results)
|
202
|
+
assert_equal(2, results.length)
|
203
|
+
|
204
|
+
results.each_with_index do |tag, index|
|
205
|
+
assert_instance_of(WWW::Delicious::Tag, tag)
|
206
|
+
name, count = expected[index]
|
207
|
+
assert_equal(name, tag.name)
|
208
|
+
assert_equal(count, tag.count)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_tags_get_empty
|
213
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_get_empty.xml'))
|
214
|
+
results = @delicious.tags_get
|
215
|
+
assert_instance_of(Array, results)
|
216
|
+
assert_equal(0, results.length)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_tags_get_raises_without_bundles_root_node
|
220
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
221
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
222
|
+
@delicious.tags_get
|
223
|
+
end
|
224
|
+
assert_match(/`tags`/, error.message)
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
def test_tags_rename
|
229
|
+
@delicious.expects(:request).once.returns(mock_response('/response/tags_rename.xml'))
|
230
|
+
assert(@delicious.tags_rename('old', 'new'))
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_tags_rename_raises_without_result_root_node
|
234
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
235
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
236
|
+
@delicious.tags_rename('foo', 'bar')
|
237
|
+
end
|
238
|
+
assert_match(/`result`/, error.message)
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# =========================================================================
|
243
|
+
# Posts
|
244
|
+
# =========================================================================
|
245
|
+
|
246
|
+
def test_posts_get
|
247
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_get.xml'))
|
248
|
+
results = @delicious.posts_get
|
249
|
+
assert_instance_of(Array, results)
|
250
|
+
assert_equal(3, results.length)
|
251
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
252
|
+
assert_equal('.c( whytheluckystiff )o. -- The Fully Upturned Bin', results.last.title)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_posts_get_raises_without_posts_root_node
|
256
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
257
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
258
|
+
@delicious.posts_get
|
259
|
+
end
|
260
|
+
assert_match(/`posts`/, error.message)
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
def test_posts_recent
|
265
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_recent.xml'))
|
266
|
+
results = @delicious.posts_recent
|
267
|
+
assert_instance_of(Array, results)
|
268
|
+
assert_equal(15, results.length)
|
269
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
270
|
+
assert_equal('RichText | Lightview for modal dialogs on Rails', results.last.title)
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_posts_recent_raises_without_posts_root_node
|
274
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
275
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
276
|
+
@delicious.posts_recent
|
277
|
+
end
|
278
|
+
assert_match(/`posts`/, error.message)
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
def test_posts_all
|
283
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_all.xml'))
|
284
|
+
results = @delicious.posts_all
|
285
|
+
assert_instance_of(Array, results)
|
286
|
+
assert_equal(8, results.length)
|
287
|
+
assert_equal('New to Git? — GitHub', results.first.title)
|
288
|
+
assert_equal('ASP 101 - Object Oriented ASP: Using Classes in Classic ASP', results.last.title)
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_posts_all_raises_without_posts_root_node
|
292
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
293
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
294
|
+
@delicious.posts_all
|
295
|
+
end
|
296
|
+
assert_match(/`posts`/, error.message)
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
def test_posts_dates
|
301
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_dates.xml'))
|
302
|
+
results = @delicious.posts_dates
|
303
|
+
assert_instance_of(Hash, results)
|
304
|
+
assert_equal(10, results.length)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_posts_dates_raises_without_dates_root_node
|
308
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
309
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
310
|
+
@delicious.posts_dates
|
311
|
+
end
|
312
|
+
assert_match(/`dates`/, error.message)
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
def test_posts_add
|
317
|
+
params = {:url => 'http://localhost', :title => 'Just a test'}
|
318
|
+
@delicious.expects(:request).times(2).returns(mock_response('/response/posts_add.xml'))
|
319
|
+
assert(@delicious.posts_add(WWW::Delicious::Post.new(params)))
|
320
|
+
assert(@delicious.posts_add(params))
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
def test_posts_delete
|
325
|
+
@delicious.expects(:request).once.returns(mock_response('/response/posts_delete.xml'))
|
326
|
+
assert(@delicious.posts_delete('test'))
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_posts_delete_raises_without_result_root_node
|
330
|
+
@delicious.expects(:request).once.returns(mock_response('/response/update.xml'))
|
331
|
+
error = assert_raise(WWW::Delicious::ResponseError) do
|
332
|
+
@delicious.posts_delete('test')
|
333
|
+
end
|
334
|
+
assert_match(/`result`/, error.message)
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
protected
|
340
|
+
|
341
|
+
# returns a stub instance
|
342
|
+
def instance(options = {}, &block)
|
343
|
+
WWW::Delicious.new(TEST_USERNAME, TEST_PASSWORD, options, &block)
|
344
|
+
end
|
345
|
+
|
346
|
+
def load_testcase(file)
|
347
|
+
File.read(TESTCASES_PATH + file)
|
348
|
+
end
|
349
|
+
|
350
|
+
def load_fixture(file)
|
351
|
+
YAML.load(File.read(FIXTURES_PATH + file))
|
352
|
+
end
|
353
|
+
|
354
|
+
def mock_response(file_or_content)
|
355
|
+
content = case
|
356
|
+
when file_or_content =~ /\.xml$/
|
357
|
+
load_testcase(file_or_content)
|
358
|
+
when file_or_content =~ /\.yml$/
|
359
|
+
load_fixture(file_or_content)
|
360
|
+
else
|
361
|
+
file_or_content.to_s
|
362
|
+
end
|
363
|
+
|
364
|
+
response = mock()
|
365
|
+
response.expects(:body).at_least(1).returns(content)
|
366
|
+
response
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/../../helper'
|
18
|
+
|
19
|
+
|
20
|
+
# overwrite if file is called alone
|
21
|
+
RUN_ONLINE_TESTS = ($0 == __FILE__) unless defined? RUN_ONLINE_TESTS and RUN_ONLINE_TESTS
|
22
|
+
|
23
|
+
puts "Online test #{__FILE__} skipped.\n" +
|
24
|
+
"Use `ONLINE=1` to run online tests.\n" unless RUN_ONLINE_TESTS
|
25
|
+
|
26
|
+
|
27
|
+
class OnlineTest < Test::Unit::TestCase
|
28
|
+
|
29
|
+
def setup
|
30
|
+
init_account
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_update
|
35
|
+
response = @delicious.update
|
36
|
+
assert_instance_of(Time, response)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_bundles_all
|
41
|
+
response = @delicious.bundles_all
|
42
|
+
assert_kind_of(Array, response)
|
43
|
+
|
44
|
+
response.each do |bundle|
|
45
|
+
assert_instance_of(WWW::Delicious::Bundle, bundle)
|
46
|
+
assert_instance_of(Array, bundle.tags)
|
47
|
+
assert_not_nil(bundle.name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_bundles_set
|
52
|
+
bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle', :tags => %w(ruby python).sort)
|
53
|
+
assert_nothing_raised() { @delicious.bundles_set(bundle) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_bundles_delete
|
57
|
+
bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle')
|
58
|
+
assert_nothing_raised() { @delicious.bundles_delete(bundle) }
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def test_tags_get
|
63
|
+
response = @delicious.tags_get
|
64
|
+
assert_kind_of(Array, response)
|
65
|
+
|
66
|
+
response.each do |tag|
|
67
|
+
assert_instance_of(WWW::Delicious::Tag, tag)
|
68
|
+
assert_not_nil(tag.name)
|
69
|
+
assert_not_nil(tag.count)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_tags_rename
|
74
|
+
ftag = WWW::Delicious::Tag.new(:name => 'old_tag')
|
75
|
+
otag = WWW::Delicious::Tag.new(:name => 'new_tag')
|
76
|
+
assert_nothing_raised() { @delicious.tags_rename(ftag, otag) }
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def test_post_add
|
81
|
+
# TODO
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_post_all
|
85
|
+
response = @delicious.posts_get
|
86
|
+
assert_kind_of(Array, response)
|
87
|
+
|
88
|
+
response.each do |post|
|
89
|
+
assert_kind_of(WWW::Delicious::Post, post)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_post_dates
|
94
|
+
response = @delicious.posts_dates
|
95
|
+
assert_kind_of(Hash, response)
|
96
|
+
|
97
|
+
response.each do |item, value|
|
98
|
+
assert_match(/[\d]{4}-[\d]{2}-[\d]{2}/, item)
|
99
|
+
assert_match(/[\d]+/, value.to_s)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_post_delete
|
104
|
+
# TODO
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_posts_get
|
108
|
+
response = @delicious.posts_get
|
109
|
+
assert_kind_of(Array, response)
|
110
|
+
|
111
|
+
response.each do |post|
|
112
|
+
assert_kind_of(WWW::Delicious::Post, post)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_posts_recent
|
117
|
+
response = @delicious.posts_recent
|
118
|
+
assert_kind_of(Array, response)
|
119
|
+
|
120
|
+
response.each do |post|
|
121
|
+
assert_kind_of(WWW::Delicious::Post, post)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
protected
|
127
|
+
|
128
|
+
def init_account(options = {}, &block)
|
129
|
+
@delicious_username ||= ENV['DELICIOUS_USERNAME'] || self.class.prompt('Delicious Username') { |value| abort('Value cannot be blank') if value.blank?; value }
|
130
|
+
@delicious_password ||= ENV['DELICIOUS_PASSWORD'] || self.class.prompt('Delicious Password') { |value| abort('Value cannot be blank') if value.blank?; value }
|
131
|
+
@delicious = WWW::Delicious.new(@delicious_username, @delicious_password, options, &block)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Convenient method for collecting user input
|
135
|
+
def self.prompt(text, options = {}, &block)
|
136
|
+
default = options[:default] || ''
|
137
|
+
value = nil
|
138
|
+
while value.blank?
|
139
|
+
print "#{text} [#{default}]: "
|
140
|
+
value = STDIN.gets.chomp!
|
141
|
+
value = default if value.blank?
|
142
|
+
value = yield value if block_given?
|
143
|
+
value
|
144
|
+
end
|
145
|
+
value
|
146
|
+
end
|
147
|
+
|
148
|
+
end if RUN_ONLINE_TESTS
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/../helper'
|
18
|
+
require 'www/delicious/post'
|
19
|
+
|
20
|
+
|
21
|
+
class PostTest < Test::Unit::TestCase
|
22
|
+
|
23
|
+
def test_post
|
24
|
+
expected = { :title => 'JavaScript DOM reference', :url => URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1') }
|
25
|
+
assert_attributes(instance(expected), expected)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_post_shared_defaults_to_true
|
29
|
+
assert(instance(:title => 'Foo').shared)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_post_shared_is_false
|
33
|
+
assert(!instance(:title => 'Foo', :shared => false).shared)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_post_from_rexml
|
37
|
+
dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/post.xml'))
|
38
|
+
element = WWW::Delicious::Post.from_rexml(dom.root)
|
39
|
+
|
40
|
+
assert_equal(URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1'), element.url)
|
41
|
+
assert_equal("JavaScript DOM reference", element.title)
|
42
|
+
assert_equal("dom reference", element.notes)
|
43
|
+
assert_equal("c0238dc0c44f07daedd9a1fd9bbdeebd", element.uid)
|
44
|
+
assert_equal(55, element.others)
|
45
|
+
assert_equal(%w(dom javascript webdev), element.tags)
|
46
|
+
assert_equal(Time.parse("2005-11-28T05:26:09Z"), element.time)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_post_from_rexml_not_shared
|
50
|
+
dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/post_unshared.xml'))
|
51
|
+
element = WWW::Delicious::Post.from_rexml(dom.root)
|
52
|
+
|
53
|
+
assert(!element.shared)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# def test_valid
|
58
|
+
# end
|
59
|
+
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
# returns a stub instance
|
64
|
+
def instance(values = {}, &block)
|
65
|
+
WWW::Delicious::Post.new(values)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# = WWW::Delicious
|
3
|
+
#
|
4
|
+
# Ruby client for del.icio.us API.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: WWW
|
8
|
+
# Package:: WWW::Delicious
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/../helper'
|
18
|
+
require 'www/delicious/tag'
|
19
|
+
|
20
|
+
|
21
|
+
class TagTest < Test::Unit::TestCase
|
22
|
+
|
23
|
+
def test_tag
|
24
|
+
expected = { :name => 'MyTag', :count => 2 }
|
25
|
+
assert_attributes(instance(expected), expected)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tag_from_rexml
|
29
|
+
dom = REXML::Document.new(File.read(TESTCASES_PATH + '/element/tag.xml'))
|
30
|
+
expected = { :count => 1, :name => 'activedesktop' }
|
31
|
+
|
32
|
+
element = WWW::Delicious::Tag.from_rexml(dom.root)
|
33
|
+
assert_attributes(element, expected)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def test_tag_name_strips_whitespaces
|
38
|
+
[' foo ', 'foo ', ' foo ', ' foo'].each do |v|
|
39
|
+
assert_equal('foo', instance(:name => v).name) # => 'foo'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_to_s_returns_name_as_string
|
44
|
+
assert_equal('foobar', instance(:name => 'foobar', :count => 4).to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_s_returns_empty_string_with_name_nil
|
48
|
+
assert_equal('', instance(:name => nil).to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# def test_api_valid
|
53
|
+
# ['foo', ' foo '].each do |v|
|
54
|
+
# assert(instance(v).api_valid?)
|
55
|
+
# end
|
56
|
+
# ['', ' '].each do |v|
|
57
|
+
# assert(!instance(v).api_valid?)
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
# returns a stub instance
|
65
|
+
def instance(values = {}, &block)
|
66
|
+
WWW::Delicious::Tag.new(values)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|