www-delicious 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +41 -0
- data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
- data/Manifest +49 -0
- data/{README → README.rdoc} +13 -14
- data/Rakefile +36 -118
- data/TODO +4 -0
- data/lib/www/delicious.rb +527 -446
- data/lib/www/delicious/bundle.rb +41 -22
- data/lib/www/delicious/element.rb +72 -0
- data/lib/www/delicious/errors.rb +2 -2
- data/lib/www/delicious/post.rb +71 -61
- data/lib/www/delicious/tag.rb +43 -62
- data/lib/www/delicious/version.rb +1 -1
- data/test/fixtures/net_response_invalid_account.yml +25 -0
- data/test/fixtures/net_response_success.yml +23 -0
- data/test/helper.rb +19 -79
- data/test/test_all.rb +17 -0
- data/test/test_offline.rb +17 -0
- data/test/test_online.rb +19 -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 +62 -0
- data/test/unit/delicious_test.rb +186 -238
- data/test/unit/online/online_test.rb +147 -0
- data/test/unit/post_test.rb +67 -0
- data/test/unit/tag_test.rb +68 -0
- data/www-delicious.gemspec +146 -0
- metadata +85 -31
- data/CHANGELOG +0 -5
- data/test/unit/delicious_bundle_test.rb +0 -90
- data/test/unit/delicious_online_test.rb +0 -143
- data/test/unit/delicious_post_test.rb +0 -102
- data/test/unit/delicious_tag_test.rb +0 -140
data/CHANGELOG
DELETED
@@ -1,90 +0,0 @@
|
|
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
|
-
#
|
11
|
-
#--
|
12
|
-
# SVN: $Id$
|
13
|
-
#++
|
14
|
-
|
15
|
-
|
16
|
-
require File.dirname(__FILE__) + '/../helper'
|
17
|
-
require 'www/delicious/bundle'
|
18
|
-
|
19
|
-
|
20
|
-
class DeliciousBundleTest < Test::Unit::TestCase
|
21
|
-
|
22
|
-
|
23
|
-
# =========================================================================
|
24
|
-
# These tests check object constructor behavior
|
25
|
-
# =========================================================================
|
26
|
-
|
27
|
-
def test_initialize
|
28
|
-
obj = nil
|
29
|
-
assert_nothing_raised() { obj = WWW::Delicious::Bundle.new('name') }
|
30
|
-
assert_instance_of(WWW::Delicious::Bundle, obj)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_initialize_with_tags
|
34
|
-
obj = nil
|
35
|
-
assert_nothing_raised() { obj = WWW::Delicious::Bundle.new('name', []) }
|
36
|
-
assert_instance_of(WWW::Delicious::Bundle, obj)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_initialize_raises_without_name
|
40
|
-
assert_raise(ArgumentError) { WWW::Delicious::Bundle.new() }
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
# =========================================================================
|
45
|
-
# These tests check constructor options
|
46
|
-
# =========================================================================
|
47
|
-
|
48
|
-
def test_initialize_name
|
49
|
-
obj = nil
|
50
|
-
name = 'test_name'
|
51
|
-
assert_nothing_raised() { obj = instance(name) }
|
52
|
-
assert_instance_of(WWW::Delicious::Bundle, obj)
|
53
|
-
assert_equal(name, obj.name)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_initialize_tags
|
57
|
-
obj = nil
|
58
|
-
name = 'test_name'
|
59
|
-
tags = %w(foo bar)
|
60
|
-
assert_nothing_raised() { obj = instance(name, tags) }
|
61
|
-
assert_instance_of(WWW::Delicious::Bundle, obj)
|
62
|
-
assert_equal(tags, obj.tags)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_initialize_raises_without_tags_kind_of_array
|
66
|
-
assert_raise(ArgumentError) { instance('foo', 'foo') }
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
def test_from_rexml
|
71
|
-
xml = '<bundle name="music" tags="ipod mp3 music" />'
|
72
|
-
dom = REXML::Document.new(xml)
|
73
|
-
obj = WWW::Delicious::Bundle.from_rexml(dom.root)
|
74
|
-
assert_instance_of(WWW::Delicious::Bundle, obj)
|
75
|
-
assert_equal('music', obj.name)
|
76
|
-
assert_equal(%w(ipod mp3 music), obj.tags)
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
protected
|
81
|
-
#
|
82
|
-
# Returns a valid instance of <tt>WWW::Delicious::Bundle</tt>
|
83
|
-
# initialized with given +options+.
|
84
|
-
#
|
85
|
-
def instance(name, tags = [], &block)
|
86
|
-
return WWW::Delicious::Bundle.new(name, tags, &block)
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
end
|
@@ -1,143 +0,0 @@
|
|
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
|
-
#
|
11
|
-
#--
|
12
|
-
# SVN: $Id$
|
13
|
-
#++
|
14
|
-
|
15
|
-
|
16
|
-
require File.dirname(__FILE__) + '/../helper'
|
17
|
-
|
18
|
-
|
19
|
-
if TEST_REAL_TESTS
|
20
|
-
puts "*WARNING* Running real online tests with account #{ENV['DUSERNAME']} => #{ENV['DPASSWORD']}."
|
21
|
-
else
|
22
|
-
puts "Real online tests skipped. Set 'DUSERNAME' and 'DPASSWORD' env variables to run them."
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
module Net
|
27
|
-
class HTTP < Protocol
|
28
|
-
# prepare for online tests
|
29
|
-
remove_method :request
|
30
|
-
alias :request :request_online
|
31
|
-
puts 'Changed :request for online tests'
|
32
|
-
end
|
33
|
-
end if TEST_REAL_TESTS
|
34
|
-
|
35
|
-
|
36
|
-
class DeliciousOnlineTest < Test::Unit::TestCase
|
37
|
-
include WWW::Delicious::TestCase
|
38
|
-
|
39
|
-
def test_valid_account
|
40
|
-
obj = instance(:username => 'foo', :password => 'bar')
|
41
|
-
assert(!obj.valid_account?)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_update
|
45
|
-
result = nil
|
46
|
-
assert_nothing_raised() { result = instance.update() }
|
47
|
-
assert_not_nil(result)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_bundles_all
|
51
|
-
result = nil
|
52
|
-
assert_nothing_raised() { result = instance.bundles_all() }
|
53
|
-
assert_not_nil(result)
|
54
|
-
result.each do |bundle|
|
55
|
-
assert_instance_of(WWW::Delicious::Bundle, bundle)
|
56
|
-
assert_not_nil(bundle.name)
|
57
|
-
assert_instance_of(Array, bundle.tags)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_bundles_set
|
62
|
-
bundle = WWW::Delicious::Bundle.new('test_bundle', %w(ruby python).sort)
|
63
|
-
obj = instance()
|
64
|
-
|
65
|
-
# create the bundle
|
66
|
-
assert_nothing_raised() { obj.bundles_set(bundle) }
|
67
|
-
# search for the bundle
|
68
|
-
#assert_not_nil(search_for_bundle(bundle, obj))
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_bundles_delete
|
72
|
-
bundle = WWW::Delicious::Bundle.new('test_bundle', %w(ruby python).sort)
|
73
|
-
obj = instance()
|
74
|
-
|
75
|
-
# search for the bundle
|
76
|
-
#assert_not_nil(search_for_bundle(bundle, obj))
|
77
|
-
# delete the bundle
|
78
|
-
assert_nothing_raised() { obj.bundles_delete(bundle) }
|
79
|
-
# search for the bundle again
|
80
|
-
#assert_nil(search_for_bundle(bundle, obj))
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_tags_get
|
84
|
-
result = nil
|
85
|
-
assert_nothing_raised() { result = instance.tags_get() }
|
86
|
-
assert_not_nil(result)
|
87
|
-
result.each do |tag|
|
88
|
-
assert_instance_of(WWW::Delicious::Tag, tag)
|
89
|
-
assert_not_nil(tag.name)
|
90
|
-
assert_not_nil(tag.count)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_tags_rename
|
95
|
-
ftag = WWW::Delicious::Tag.new(:name => 'old_tag')
|
96
|
-
otag = WWW::Delicious::Tag.new(:name => 'new_tag')
|
97
|
-
obj = instance()
|
98
|
-
|
99
|
-
assert_nothing_raised() { obj.tags_rename(ftag, otag) }
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_posts_get
|
103
|
-
obj = instance()
|
104
|
-
results = nil
|
105
|
-
assert_nothing_raised() { results = obj.posts_get() }
|
106
|
-
|
107
|
-
assert_kind_of(Array, results)
|
108
|
-
results.each do |post|
|
109
|
-
assert_kind_of(WWW::Delicious::Post, result)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_posts_recent
|
114
|
-
obj = instance()
|
115
|
-
results = nil
|
116
|
-
assert_nothing_raised() { results = obj.posts_recent() }
|
117
|
-
|
118
|
-
assert_kind_of(Array, results)
|
119
|
-
results.each do |post|
|
120
|
-
assert_kind_of(WWW::Delicious::Post, result)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
protected
|
126
|
-
def search_for_bundle(bundle, obj)
|
127
|
-
bundles = obj.bundles_all()
|
128
|
-
return bundles.detect { |b| b.name == bundle.name && b.tags.sort == bundle.tags }
|
129
|
-
end
|
130
|
-
|
131
|
-
end if TEST_REAL_TESTS
|
132
|
-
|
133
|
-
|
134
|
-
module Net
|
135
|
-
class HTTP < Protocol
|
136
|
-
# prepare for offline tests
|
137
|
-
remove_method :request
|
138
|
-
alias :request :request_offline
|
139
|
-
puts 'Changed :request for offline tests'
|
140
|
-
end
|
141
|
-
end if TEST_REAL_TESTS
|
142
|
-
|
143
|
-
|
@@ -1,102 +0,0 @@
|
|
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
|
-
#
|
11
|
-
#--
|
12
|
-
# SVN: $Id$
|
13
|
-
#++
|
14
|
-
|
15
|
-
|
16
|
-
require File.dirname(__FILE__) + '/../helper'
|
17
|
-
require 'www/delicious/post'
|
18
|
-
|
19
|
-
|
20
|
-
class DeliciousPostTest < Test::Unit::TestCase
|
21
|
-
|
22
|
-
|
23
|
-
# =========================================================================
|
24
|
-
# These tests check object constructor behavior
|
25
|
-
# =========================================================================
|
26
|
-
|
27
|
-
def test_initialize
|
28
|
-
assert_nothing_raised() do
|
29
|
-
obj = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo')
|
30
|
-
assert_instance_of(WWW::Delicious::Post, obj)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_initialize_with_block
|
35
|
-
assert_nothing_raised() do
|
36
|
-
obj = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo') do |tag|
|
37
|
-
assert_instance_of(WWW::Delicious::Post, tag)
|
38
|
-
end
|
39
|
-
assert_instance_of(WWW::Delicious::Post, obj)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_initialize_raises_without_values
|
44
|
-
assert_raise(ArgumentError) do
|
45
|
-
obj = WWW::Delicious::Post.new()
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_initialize_raises_without_values_hash_or_rexml
|
50
|
-
exception = assert_raise(ArgumentError) do
|
51
|
-
obj = WWW::Delicious::Post.new('foo')
|
52
|
-
end
|
53
|
-
assert_match(/`hash` or `REXML::Element`/i, exception.message)
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
# =========================================================================
|
58
|
-
# These tests check constructor options
|
59
|
-
# =========================================================================
|
60
|
-
|
61
|
-
def test_initialize_values_kind_of_hash
|
62
|
-
params = {
|
63
|
-
# TODO
|
64
|
-
}
|
65
|
-
obj = WWW::Delicious::Post.new(params)
|
66
|
-
assert_instance_of(WWW::Delicious::Post, obj)
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
def test_initialize_values_kind_of_rexml
|
71
|
-
xml = <<-EOS
|
72
|
-
<post href="http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1"
|
73
|
-
description="JavaScript DOM reference"
|
74
|
-
extended="dom reference"
|
75
|
-
hash="c0238dc0c44f07daedd9a1fd9bbdeebd"
|
76
|
-
others="55" tag="dom javascript webdev" time="2005-11-28T05:26:09Z" />
|
77
|
-
EOS
|
78
|
-
dom = REXML::Document.new(xml)
|
79
|
-
obj = WWW::Delicious::Post.new(dom.root)
|
80
|
-
assert_instance_of(WWW::Delicious::Post, obj)
|
81
|
-
# check all attrs
|
82
|
-
assert_equal(URI.parse('http://www.howtocreate.co.uk/tutorials/texterise.php?dom=1'), obj.url)
|
83
|
-
assert_equal("JavaScript DOM reference", obj.title)
|
84
|
-
assert_equal("dom reference", obj.notes)
|
85
|
-
assert_equal("c0238dc0c44f07daedd9a1fd9bbdeebd", obj.uid)
|
86
|
-
assert_equal(55, obj.others)
|
87
|
-
assert_equal(%w(dom javascript webdev), obj.tags)
|
88
|
-
assert_equal(Time.parse("2005-11-28T05:26:09Z"), obj.time)
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
protected
|
93
|
-
#
|
94
|
-
# Returns a valid instance of <tt>WWW::Delicious::Tag</tt>
|
95
|
-
# initialized with given +options+.
|
96
|
-
#
|
97
|
-
def instance(values, &block)
|
98
|
-
return WWW::Delicious::Post.new(values, &block)
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
end
|
@@ -1,140 +0,0 @@
|
|
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
|
-
#
|
11
|
-
#--
|
12
|
-
# SVN: $Id$
|
13
|
-
#++
|
14
|
-
|
15
|
-
|
16
|
-
require File.dirname(__FILE__) + '/../helper'
|
17
|
-
require 'www/delicious/tag'
|
18
|
-
|
19
|
-
|
20
|
-
class DeliciousTagTest < Test::Unit::TestCase
|
21
|
-
|
22
|
-
|
23
|
-
# =========================================================================
|
24
|
-
# These tests check object constructor behavior
|
25
|
-
# =========================================================================
|
26
|
-
|
27
|
-
def test_initialize
|
28
|
-
assert_nothing_raised() do
|
29
|
-
obj = WWW::Delicious::Tag.new(:name => 'name')
|
30
|
-
assert_instance_of(WWW::Delicious::Tag, obj)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_initialize_with_block
|
35
|
-
assert_nothing_raised() do
|
36
|
-
obj = WWW::Delicious::Tag.new(:name => 'name') do |tag|
|
37
|
-
assert_instance_of(WWW::Delicious::Tag, tag)
|
38
|
-
end
|
39
|
-
assert_instance_of(WWW::Delicious::Tag, obj)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_initialize_raises_without_values
|
44
|
-
assert_raise(ArgumentError) do
|
45
|
-
obj = WWW::Delicious::Tag.new()
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_initialize_raises_without_values_hash_or_rexml
|
50
|
-
exception = assert_raise(ArgumentError) do
|
51
|
-
obj = WWW::Delicious::Tag.new('foo')
|
52
|
-
end
|
53
|
-
assert_match(/`hash` or `REXML::Element`/i, exception.message)
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
# =========================================================================
|
58
|
-
# These tests check constructor options
|
59
|
-
# =========================================================================
|
60
|
-
|
61
|
-
def test_initialize_values_kind_of_hash
|
62
|
-
name = 'test'; count = 20
|
63
|
-
assert_nothing_raised() do
|
64
|
-
obj = instance(:name => name, :count => count) do |t|
|
65
|
-
assert_instance_of(WWW::Delicious::Tag, t)
|
66
|
-
assert_equal(name, t.name)
|
67
|
-
assert_equal(count, t.count)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_initialize_values_kind_of_rexml
|
73
|
-
xml = '<tag count="1" tag="activedesktop" />'
|
74
|
-
dom = REXML::Document.new(xml)
|
75
|
-
obj = WWW::Delicious::Tag.new(dom.root)
|
76
|
-
assert_instance_of(WWW::Delicious::Tag, obj)
|
77
|
-
assert_equal('activedesktop', obj.name)
|
78
|
-
assert_equal(1, obj.count)
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
def test_name_setter_getter
|
83
|
-
instance('foo') do |tag|
|
84
|
-
assert_equal('foo', tag.name)
|
85
|
-
tag.name = 12
|
86
|
-
assert_equal('12', tag.name)
|
87
|
-
tag.name = :foo
|
88
|
-
assert_equal('foo', tag.name)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_name_strip_whitespaces
|
93
|
-
[' foo ', 'foo ', ' foo ', ' foo'].each do |v|
|
94
|
-
assert_equal(v.strip, instance(v).name) # => 'foo'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_count_setter_getter
|
99
|
-
instance('foo') do |tag|
|
100
|
-
assert_equal(0, tag.count)
|
101
|
-
tag.count = 12
|
102
|
-
assert_equal(12, tag.count)
|
103
|
-
tag.count = '23'
|
104
|
-
assert_equal(23, tag.count)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_to_s
|
109
|
-
instance('foobar') do |tag|
|
110
|
-
assert_equal('foobar', tag.to_s)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_api_valid
|
115
|
-
['foo', ' foo '].each do |v|
|
116
|
-
assert(instance(v).api_valid?)
|
117
|
-
end
|
118
|
-
['', ' '].each do |v|
|
119
|
-
assert(!instance(v).api_valid?)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
protected
|
125
|
-
#
|
126
|
-
# Returns a valid instance of <tt>WWW::Delicious::Tag</tt>
|
127
|
-
# initialized with given +options+.
|
128
|
-
#
|
129
|
-
def instance(args, &block)
|
130
|
-
values = case args
|
131
|
-
when Hash
|
132
|
-
args
|
133
|
-
else
|
134
|
-
{ :name => args.to_s() }
|
135
|
-
end
|
136
|
-
return WWW::Delicious::Tag.new(values, &block)
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
end
|