lgs-www-delicious 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +52 -0
- data/LICENSE.rdoc +25 -0
- data/Manifest +48 -0
- data/README.rdoc +206 -0
- data/Rakefile +55 -0
- data/init.rb +1 -0
- data/lib/www/delicious.rb +942 -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 +33 -0
- data/setup.rb +1585 -0
- data/test/bundle_test.rb +63 -0
- data/test/delicious_test.rb +369 -0
- data/test/fixtures/net_response_invalid_account.yml +25 -0
- data/test/fixtures/net_response_success.yml +23 -0
- data/test/online_test.rb +147 -0
- data/test/post_test.rb +68 -0
- data/test/tag_test.rb +69 -0
- data/test/test_all.rb +19 -0
- data/test/test_helper.rb +43 -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/www-delicious.gemspec +44 -0
- metadata +148 -0
@@ -0,0 +1,73 @@
|
|
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 'www/delicious/element'
|
18
|
+
|
19
|
+
|
20
|
+
module WWW
|
21
|
+
class Delicious
|
22
|
+
|
23
|
+
#
|
24
|
+
# = Delicious Bundle
|
25
|
+
#
|
26
|
+
# Represents a single Bundle element.
|
27
|
+
#
|
28
|
+
class Bundle < Element
|
29
|
+
|
30
|
+
# The name of the bundle.
|
31
|
+
attr_accessor :name
|
32
|
+
|
33
|
+
# The collection of <tt>WWW::Delicious::Tags</tt>.
|
34
|
+
attr_accessor :tags
|
35
|
+
|
36
|
+
|
37
|
+
# Returns value for <tt>name</tt> attribute.
|
38
|
+
# Value is always normalized as lower string.
|
39
|
+
def name
|
40
|
+
@name.to_s.strip unless @name.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Returns a string representation of this Bundle.
|
45
|
+
# In case name is nil this method will return an empty string.
|
46
|
+
#
|
47
|
+
def to_s
|
48
|
+
name.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class << self
|
53
|
+
|
54
|
+
#
|
55
|
+
# Creates and returns new instance from a REXML +element+.
|
56
|
+
#
|
57
|
+
# Implements Element#from_rexml.
|
58
|
+
#
|
59
|
+
def from_rexml(element)
|
60
|
+
raise ArgumentError, "`element` expected to be a `REXML::Element`" unless element.kind_of? REXML::Element
|
61
|
+
self.new do |instance|
|
62
|
+
instance.name = element.if_attribute_value(:name)
|
63
|
+
# FIXME: value must be converted to array of Tag
|
64
|
+
instance.tags = element.if_attribute_value(:tags) { |value| value.split(' ') }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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
|
+
module WWW
|
18
|
+
class Delicious
|
19
|
+
|
20
|
+
#
|
21
|
+
# = Abstract structure
|
22
|
+
#
|
23
|
+
# Represent the most basic structure all Struc(s) must inherith from.
|
24
|
+
#
|
25
|
+
class Element
|
26
|
+
|
27
|
+
#
|
28
|
+
# Initializes a new instance and populate attributes from +attrs+.
|
29
|
+
#
|
30
|
+
# class User < Element
|
31
|
+
# attr_accessor :first_name
|
32
|
+
# attr_accessor :last_name
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# User.new
|
36
|
+
# User.new(:first_name => 'foo')
|
37
|
+
# User.new(:first_name => 'John', :last_name => 'Doe')
|
38
|
+
#
|
39
|
+
# You can even use a block.
|
40
|
+
# The following statements are equals:
|
41
|
+
#
|
42
|
+
# User.new(:first_name => 'John', :last_name => 'Doe')
|
43
|
+
#
|
44
|
+
# User.new do |user|
|
45
|
+
# user.first_name => 'John'
|
46
|
+
# user.last_name => 'Doe'
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# Warning. In order to set an attribute a valid attribute writer must be available,
|
50
|
+
# otherwise this method will raise an exception.
|
51
|
+
#
|
52
|
+
def initialize(attrs = {}, &block)
|
53
|
+
attrs.each { |key, value| self.send("#{key}=".to_sym, value) }
|
54
|
+
yield self if block_given?
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class << self
|
60
|
+
|
61
|
+
#
|
62
|
+
# Creates and returns new instance from a REXML +element+.
|
63
|
+
#
|
64
|
+
def from_rexml(element, options)
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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
|
+
module WWW
|
18
|
+
class Delicious
|
19
|
+
|
20
|
+
|
21
|
+
#
|
22
|
+
# = WWW::Delicious::Error
|
23
|
+
#
|
24
|
+
# Base exception for all WWW::Delicious errors.
|
25
|
+
#
|
26
|
+
class Error < StandardError; end
|
27
|
+
|
28
|
+
#
|
29
|
+
# = WWW::Delicious::HTTPError
|
30
|
+
#
|
31
|
+
# HTTP connection related error.
|
32
|
+
# Raised when an HTTP request fails or in case of unexpected behavior.
|
33
|
+
#
|
34
|
+
class HTTPError < Error; end
|
35
|
+
|
36
|
+
#
|
37
|
+
# = WWW::Delicious::ResponseError
|
38
|
+
#
|
39
|
+
# Response related error.
|
40
|
+
# Usually raised in case of a malformed, invalid or empty XML response.
|
41
|
+
#
|
42
|
+
class ResponseError < Error; end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,123 @@
|
|
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 'www/delicious/element'
|
18
|
+
|
19
|
+
|
20
|
+
module WWW
|
21
|
+
class Delicious
|
22
|
+
|
23
|
+
class Post < Element
|
24
|
+
|
25
|
+
# The Post URL
|
26
|
+
attr_accessor :url
|
27
|
+
|
28
|
+
# The title of the Post
|
29
|
+
attr_accessor :title
|
30
|
+
|
31
|
+
# The extended description for the Post
|
32
|
+
attr_accessor :notes
|
33
|
+
|
34
|
+
# The number of other users who saved this Post
|
35
|
+
attr_accessor :others
|
36
|
+
|
37
|
+
# The unique Id for this Post
|
38
|
+
attr_accessor :uid
|
39
|
+
|
40
|
+
# Tags for this Post
|
41
|
+
attr_accessor :tags
|
42
|
+
|
43
|
+
# Timestamp this Post was last saved at
|
44
|
+
attr_accessor :time
|
45
|
+
|
46
|
+
# Whether this Post must replace previous version of the same Post.
|
47
|
+
attr_accessor :replace
|
48
|
+
|
49
|
+
# Whether this Post is private
|
50
|
+
attr_accessor :shared
|
51
|
+
|
52
|
+
|
53
|
+
# Returns the value for <tt>shared</tt> attribute.
|
54
|
+
def shared
|
55
|
+
!(@shared == false)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the value for <tt>replace</tt> attribute.
|
59
|
+
def replace
|
60
|
+
!(@replace == false)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns a params-style representation suitable for API calls.
|
64
|
+
def to_params()
|
65
|
+
params = {}
|
66
|
+
params[:url] = url
|
67
|
+
params[:description] = title
|
68
|
+
params[:extended] = notes if notes
|
69
|
+
params[:shared] = shared
|
70
|
+
params[:tags] = tags.join(' ') if tags.respond_to? :join
|
71
|
+
params[:replace] = replace
|
72
|
+
params[:dt] = WWW::Delicious::TIME_CONVERTER.call(time) if time
|
73
|
+
params
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
#
|
78
|
+
# Returns whether this object is valid for an API request.
|
79
|
+
#
|
80
|
+
# To be valid +url+ and +title+ must not be empty.
|
81
|
+
#
|
82
|
+
# === Examples
|
83
|
+
#
|
84
|
+
# post = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo')
|
85
|
+
# post.api_valid?
|
86
|
+
# # => true
|
87
|
+
#
|
88
|
+
# post = WWW::Delicious::Post.new(:url => 'http://localhost')
|
89
|
+
# post.api_valid?
|
90
|
+
# # => false
|
91
|
+
#
|
92
|
+
def api_valid?
|
93
|
+
return !(url.nil? or url.empty? or title.nil? or title.empty?)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
class << self
|
98
|
+
|
99
|
+
#
|
100
|
+
# Creates and returns new instance from a REXML +element+.
|
101
|
+
#
|
102
|
+
# Implements Element#from_rexml.
|
103
|
+
#
|
104
|
+
def from_rexml(element)
|
105
|
+
raise ArgumentError, "`element` expected to be a `REXML::Element`" unless element.kind_of? REXML::Element
|
106
|
+
self.new do |instance|
|
107
|
+
instance.url = element.if_attribute_value(:href) { |v| URI.parse(v) }
|
108
|
+
instance.title = element.if_attribute_value(:description)
|
109
|
+
instance.notes = element.if_attribute_value(:extended)
|
110
|
+
instance.others = element.if_attribute_value(:others).to_i # cast nil to 0
|
111
|
+
instance.uid = element.if_attribute_value(:hash)
|
112
|
+
instance.tags = element.if_attribute_value(:tag) { |v| v.split(' ') }.to_a
|
113
|
+
instance.time = element.if_attribute_value(:time) { |v| Time.parse(v) }
|
114
|
+
instance.shared = element.if_attribute_value(:shared) { |v| v == 'no' ? false : true }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,101 @@
|
|
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 'www/delicious/element'
|
18
|
+
|
19
|
+
|
20
|
+
module WWW
|
21
|
+
class Delicious
|
22
|
+
|
23
|
+
#
|
24
|
+
# = Delicious Tag
|
25
|
+
#
|
26
|
+
# Represents a single Tag element.
|
27
|
+
#
|
28
|
+
class Tag < Element
|
29
|
+
|
30
|
+
# The name of the tag.
|
31
|
+
attr_accessor :name
|
32
|
+
|
33
|
+
# The number of links tagged with this tag.
|
34
|
+
# It should be set only from an API response.
|
35
|
+
attr_accessor :count
|
36
|
+
|
37
|
+
|
38
|
+
# Returns value for <tt>name</tt> attribute.
|
39
|
+
# Value is always normalized as lower string.
|
40
|
+
def name
|
41
|
+
@name.to_s.strip unless @name.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns value for <tt>count</tt> attribute.
|
45
|
+
# Value is always normalized to Fixnum.
|
46
|
+
def count
|
47
|
+
@count.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Returns a string representation of this Tag.
|
52
|
+
# In case name is nil this method will return an empty string.
|
53
|
+
#
|
54
|
+
def to_s
|
55
|
+
name.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
public
|
60
|
+
#
|
61
|
+
# Returns wheter this object is valid for an API request.
|
62
|
+
#
|
63
|
+
# To be valid +name+ must not be empty.
|
64
|
+
# +count+ can be 0.
|
65
|
+
#
|
66
|
+
# === Examples
|
67
|
+
#
|
68
|
+
# tag = WWW::Delicious::Tag.new(:name => 'foo')
|
69
|
+
# tag.api_api_valid?
|
70
|
+
# # => true
|
71
|
+
#
|
72
|
+
# tag = WWW::Delicious::Tag.new(:name => ' ')
|
73
|
+
# tag.api_api_valid?
|
74
|
+
# # => false
|
75
|
+
#
|
76
|
+
def api_valid?
|
77
|
+
return !name.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
class << self
|
82
|
+
|
83
|
+
#
|
84
|
+
# Creates and returns new instance from a REXML +element+.
|
85
|
+
#
|
86
|
+
# Implements Element#from_rexml.
|
87
|
+
#
|
88
|
+
def from_rexml(element)
|
89
|
+
raise ArgumentError, "`element` expected to be a `REXML::Element`" unless element.kind_of? REXML::Element
|
90
|
+
self.new do |instance|
|
91
|
+
instance.name = element.if_attribute_value(:tag)
|
92
|
+
instance.count = element.if_attribute_value(:count) { |value| value.to_i }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
module WWW
|
18
|
+
class Delicious
|
19
|
+
|
20
|
+
module Version
|
21
|
+
MAJOR = 0
|
22
|
+
MINOR = 2
|
23
|
+
TINY = 0
|
24
|
+
|
25
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
26
|
+
end
|
27
|
+
|
28
|
+
VERSION = Version::STRING
|
29
|
+
STATUS = 'beta'
|
30
|
+
BUILD = ''.match(/(\d+)/).to_a.first
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|