laco-www-delicious 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +61 -0
- data/Gemfile +7 -0
- data/LICENSE.rdoc +25 -0
- data/Manifest +47 -0
- data/README.rdoc +201 -0
- data/Rakefile +57 -0
- data/laco-www-delicious.gemspec +41 -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/lib/www/delicious.rb +947 -0
- data/setup.rb +1585 -0
- data/test/bundle_test.rb +63 -0
- data/test/delicious_test.rb +370 -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
- metadata +161 -0
@@ -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
|
+
#
|
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
|
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
|
+
#
|
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
|
+
#
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
module WWW
|
18
|
+
class Delicious
|
19
|
+
|
20
|
+
module Version
|
21
|
+
MAJOR = 0
|
22
|
+
MINOR = 3
|
23
|
+
TINY = 2
|
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
|