laco-www-delicious 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.rdoc +61 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE.rdoc +25 -0
  4. data/Manifest +47 -0
  5. data/README.rdoc +201 -0
  6. data/Rakefile +57 -0
  7. data/laco-www-delicious.gemspec +41 -0
  8. data/lib/www/delicious/bundle.rb +73 -0
  9. data/lib/www/delicious/element.rb +73 -0
  10. data/lib/www/delicious/errors.rb +46 -0
  11. data/lib/www/delicious/post.rb +123 -0
  12. data/lib/www/delicious/tag.rb +101 -0
  13. data/lib/www/delicious/version.rb +33 -0
  14. data/lib/www/delicious.rb +947 -0
  15. data/setup.rb +1585 -0
  16. data/test/bundle_test.rb +63 -0
  17. data/test/delicious_test.rb +370 -0
  18. data/test/fixtures/net_response_invalid_account.yml +25 -0
  19. data/test/fixtures/net_response_success.yml +23 -0
  20. data/test/online_test.rb +147 -0
  21. data/test/post_test.rb +68 -0
  22. data/test/tag_test.rb +69 -0
  23. data/test/test_all.rb +19 -0
  24. data/test/test_helper.rb +43 -0
  25. data/test/testcases/element/bundle.xml +1 -0
  26. data/test/testcases/element/invalid_root.xml +2 -0
  27. data/test/testcases/element/post.xml +2 -0
  28. data/test/testcases/element/post_unshared.xml +2 -0
  29. data/test/testcases/element/tag.xml +1 -0
  30. data/test/testcases/response/bundles_all.xml +5 -0
  31. data/test/testcases/response/bundles_all_empty.xml +2 -0
  32. data/test/testcases/response/bundles_delete.xml +2 -0
  33. data/test/testcases/response/bundles_set.xml +2 -0
  34. data/test/testcases/response/bundles_set_error.xml +2 -0
  35. data/test/testcases/response/posts_add.xml +2 -0
  36. data/test/testcases/response/posts_all.xml +12 -0
  37. data/test/testcases/response/posts_dates.xml +14 -0
  38. data/test/testcases/response/posts_dates_with_tag.xml +14 -0
  39. data/test/testcases/response/posts_delete.xml +2 -0
  40. data/test/testcases/response/posts_get.xml +7 -0
  41. data/test/testcases/response/posts_get_with_tag.xml +6 -0
  42. data/test/testcases/response/posts_recent.xml +19 -0
  43. data/test/testcases/response/posts_recent_with_tag.xml +19 -0
  44. data/test/testcases/response/tags_get.xml +5 -0
  45. data/test/testcases/response/tags_get_empty.xml +2 -0
  46. data/test/testcases/response/tags_rename.xml +2 -0
  47. data/test/testcases/response/update.delicious1.xml +2 -0
  48. data/test/testcases/response/update.xml +3 -0
  49. metadata +161 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = Changelog
2
+
3
+
4
+ == julienXX release 0.3.1
5
+
6
+ * FIXED: tags are now written in del.icio.us
7
+
8
+ == master
9
+
10
+ * FIXED: A trivial bug causes the test `test_request_waits_necessary_time_between_requests` to fail in case the subsequent request is sent exactly 1 second after the prior one.
11
+
12
+ * FIXED: Object#blank? is always redefined regardless already defined before.
13
+
14
+
15
+ == Release 0.3.0
16
+
17
+ * FIXED: Compatibility fixes for Ruby 1.9. WWW::Delicious is now 100% compatible with 1.9. You should remember to define the proper content encoding with magic comments when working with UTF-8/MultiByte XML or Ruby files, see http://redmine.ruby-lang.org/wiki/ruby-19/ScriptEncoding (closes #142).
18
+
19
+ * FIXED: Forced Rakefile to require Echoe >= 3.1 to prevent outdated .gemspec files (closes #143).
20
+
21
+ * CHANGED: Don't use File.dirname(__FILE__) in require statement to prevent recursive inclusions.
22
+
23
+
24
+ == Release 0.2.0
25
+
26
+ * ADDED: :base_uri initialization option allows to create a new instance specifying a custom base_uri for all API calls. This is useful, for example, if you want to use ma.gno.lia Mirror'd APIs (http://wiki.ma.gnolia.com/Mirror%27d_API) instead the del.icio.us one (thanks to Jörg Battermann).
27
+
28
+ * ADDED: two new REXML::Element core extension elements to enhance interaction with node elements.
29
+
30
+ * FIXED: a wrong indentation in README file causes all list items to be rendered as source code.
31
+
32
+ * FIXED: Missing WWW::Delicious::Bundle#to_s method causes a class ID representation to be returned.
33
+
34
+ * FIXED: Missing unit tests for post_ calls (closes #18).
35
+
36
+ * FIXED: Added test for `shared` Post attribute and fixed an issue with duplicate `replace` method definition (closes #11).
37
+
38
+ * CHANGED: improved documentation and added more examples (closes #21).
39
+
40
+ * CHANGED: REXML::Element#attribute_value core extension has been renamed to REXML::Element#if_attribute_value.
41
+
42
+ * CHANGED: Renamed TESTCASE_PATH to TESTCASES_PATH.
43
+
44
+ * CHANGED: WWW::Delicious::Tag, WWW::Delicious::Bundle, WWW::Delicious::Post now extend WWW::Delicious::Element. Simplified classes.
45
+
46
+ * CHANGED: WWW::Delicious::Tag#to_s always returns a string even if name is nil.
47
+
48
+ * CHANGED: WWW::Delicious::Tag :count attribute is now stored and returned as Fixnum instead of String.
49
+
50
+ * CHANGED: Unit test reorganization (closes #22).
51
+
52
+ * CHANGED: Simplified and tidyfied test system with Mocha (closes #19).
53
+
54
+ * CHANGED: Various internal API methods have been renamed for coherence with their new scope.
55
+
56
+ * CHANGED: Integrated Echoe, cleaned Rakefile (closes #23).
57
+
58
+
59
+ == Release 0.1.0 (2008-05-11)
60
+
61
+ * Initial public release.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://gemcutter.org"
2
+ source "http://gems.github.com"
3
+
4
+ gem 'rake'
5
+ gem 'echoe', '>= 3.1'
6
+ gem 'mocha'
7
+ gem 'gemcutter'
data/LICENSE.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = License
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2008-2009 Simone Carletti <weppos@weppos.net>
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
data/Manifest ADDED
@@ -0,0 +1,47 @@
1
+ CHANGELOG.rdoc
2
+ Gemfile
3
+ LICENSE.rdoc
4
+ Manifest
5
+ README.rdoc
6
+ Rakefile
7
+ lib/www/delicious.rb
8
+ lib/www/delicious/bundle.rb
9
+ lib/www/delicious/element.rb
10
+ lib/www/delicious/errors.rb
11
+ lib/www/delicious/post.rb
12
+ lib/www/delicious/tag.rb
13
+ lib/www/delicious/version.rb
14
+ setup.rb
15
+ test/bundle_test.rb
16
+ test/delicious_test.rb
17
+ test/fixtures/net_response_invalid_account.yml
18
+ test/fixtures/net_response_success.yml
19
+ test/online_test.rb
20
+ test/post_test.rb
21
+ test/tag_test.rb
22
+ test/test_all.rb
23
+ test/test_helper.rb
24
+ test/testcases/element/bundle.xml
25
+ test/testcases/element/invalid_root.xml
26
+ test/testcases/element/post.xml
27
+ test/testcases/element/post_unshared.xml
28
+ test/testcases/element/tag.xml
29
+ test/testcases/response/bundles_all.xml
30
+ test/testcases/response/bundles_all_empty.xml
31
+ test/testcases/response/bundles_delete.xml
32
+ test/testcases/response/bundles_set.xml
33
+ test/testcases/response/bundles_set_error.xml
34
+ test/testcases/response/posts_add.xml
35
+ test/testcases/response/posts_all.xml
36
+ test/testcases/response/posts_dates.xml
37
+ test/testcases/response/posts_dates_with_tag.xml
38
+ test/testcases/response/posts_delete.xml
39
+ test/testcases/response/posts_get.xml
40
+ test/testcases/response/posts_get_with_tag.xml
41
+ test/testcases/response/posts_recent.xml
42
+ test/testcases/response/posts_recent_with_tag.xml
43
+ test/testcases/response/tags_get.xml
44
+ test/testcases/response/tags_get_empty.xml
45
+ test/testcases/response/tags_rename.xml
46
+ test/testcases/response/update.delicious1.xml
47
+ test/testcases/response/update.xml
data/README.rdoc ADDED
@@ -0,0 +1,201 @@
1
+ = WWW::Delicious
2
+
3
+ WWW::Delicious is a Ruby client for http://del.icio.us XML API.
4
+
5
+ It provides both read and write functionality. You can read user Posts, Tags
6
+ and Bundles but you can create new Posts, Tags and Bundles as well.
7
+
8
+
9
+ == Overview
10
+
11
+ WWW::Delicious maps all the original del.icio.us API calls and provides some
12
+ additional convenient methods to perform common tasks.
13
+ Please read the official documentation (http://del.icio.us/help/api/)
14
+ to learn more about del.icio.us API.
15
+
16
+ WWW::Delicious is 100% compatible with all del.icio.us API constraints,
17
+ including the requirement to set a valid user agent or wait at least
18
+ one second between queries.
19
+ Basically, the main benefit from using this library is that you don't need
20
+ to take care of all these low level details, if you don't want:
21
+ WWW::Delicious will try to give you the most with less efforts.
22
+
23
+
24
+ == Dependencies
25
+
26
+ * Ruby >= 1.8.6 (not tested with previous versions)
27
+
28
+ As of release 0.3.0, WWW::Delicious is compatible with Ruby 1.9.1.
29
+
30
+
31
+ == Download and Installation
32
+
33
+ RubyGems[http://rubyforge.org/projects/rubygems/] is the preferred install method.
34
+ To get the latest version, simply type the following instruction into your command prompt:
35
+
36
+ $ sudo gem install www-delicious
37
+
38
+ Depending on your system, you might need su privileges.
39
+
40
+ To install the library manually, downlad the latest version from
41
+ navigate to the root library directory and enter:
42
+
43
+ $ sudo ruby setup.rb
44
+
45
+ If you need the latest development version you can download the source code
46
+ from one of the GIT repositories listed above.
47
+ Beware that the code might not be as stable as the official release.
48
+
49
+
50
+ == Getting Started
51
+
52
+ In order to use this library you need a valid del.icio.us account.
53
+ Go to http://del.icio.us and register for a new account if you don't already have one.
54
+
55
+ Then create a valid instance of WWW::Delicious providing your account credentials.
56
+
57
+ require 'www/delicious'
58
+
59
+ # create a new instance with given username and password
60
+ d = WWW::Delicious.new('username', 'password')
61
+
62
+ Now you can use your instance to interact with the API interface.
63
+
64
+
65
+ === Last account update
66
+
67
+ The following example show you how to get the last account update Time.
68
+
69
+ require 'www/delicious'
70
+ d = WWW::Delicious.new('username', 'password')
71
+
72
+ time = d.update # => Fri May 02 18:02:48 UTC 2008
73
+
74
+
75
+ === Reading Posts
76
+
77
+ You can fetch your posts in 3 different ways:
78
+
79
+ require 'www/delicious'
80
+ d = WWW::Delicious.new('username', 'password')
81
+
82
+ # 1. get all posts
83
+ posts = d.posts_all
84
+
85
+ # 2. get recent posts
86
+ posts = d.posts_recent
87
+
88
+ # 3. get a single post (the latest one if no criteria is given)
89
+ posts = d.posts_get(:tag => 'ruby')
90
+
91
+ Each post call accepts some options to refine your search.
92
+ For example, you can always search for posts matching a specific tag.
93
+
94
+ posts = d.posts_all(:tag => 'ruby')
95
+ posts = d.posts_recent(:tag => 'ruby')
96
+ posts = d.posts_get(:tag => 'ruby')
97
+
98
+
99
+ === Creating a new Post
100
+
101
+ require 'www/delicious'
102
+ d = WWW::Delicious.new('username', 'password')
103
+
104
+ # add a post from options
105
+ d.posts_add(:url => 'http://www.simonecarletti.com/', :title => 'Cool site!')
106
+
107
+ # add a post from WWW::Delicious::Post
108
+ d.posts_add(WWW::Delicious::Post.new(:url => 'http://www.simonecarletti.com/', :title => 'Cool site!'))
109
+
110
+
111
+ === Deleting a Posts
112
+
113
+ require 'www/delicious'
114
+ d = WWW::Delicious.new('username', 'password')
115
+
116
+ # delete given post (the URL can be either a string or an URI)
117
+ d.posts_delete('http://www.foobar.com/')
118
+
119
+ Note. Actually you cannot delete a post from a WWW::Delicious::Post instance.
120
+ It means, the following example doesn't work as some ActiveRecord user might expect.
121
+
122
+ post = WWW::Delicious::Post.new(:url => 'http://www.foobar.com/')
123
+ post.delete
124
+
125
+ This feature is already in the TODO list. For now, use the following workaround
126
+ to delete a given Post.
127
+
128
+ # delete a post from an existing post = WWW::Delicious::Post
129
+ d.posts_delete(post.url)
130
+
131
+
132
+ === Tags
133
+
134
+ Working with tags it's really easy. You can get all your tags or rename an existing tag.
135
+
136
+ require 'www/delicious'
137
+ d = WWW::Delicious.new('username', 'password')
138
+
139
+ # get all tags
140
+ tags = d.tags_get
141
+
142
+ # print all tag names
143
+ tags.each { |t| puts t.name }
144
+
145
+ # rename the tag gems to gem
146
+ d.tags_rename('gems', 'gem')
147
+
148
+
149
+ === Bundles
150
+
151
+ WWW::Delicious enables you to get all bundles from given account.
152
+
153
+ require 'www/delicious'
154
+ d = WWW::Delicious.new('username', 'password')
155
+
156
+ # get all bundles
157
+ bundles = d.bundles_all
158
+
159
+ # print all bundle names
160
+ bundles.each { |b| puts b.name }
161
+
162
+ You can also create new bundles or delete existing ones.
163
+
164
+ require 'www/delicious'
165
+ d = WWW::Delicious.new('username', 'password')
166
+
167
+ # set a new bundle for tags ruby, rails and gem
168
+ d.bundles_set('MyBundle', %w(ruby rails gem))
169
+
170
+ # delete the old bundle
171
+ d.bundles_delete('OldBundle')
172
+
173
+
174
+ == Credits
175
+
176
+ Author:: {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
177
+
178
+
179
+ == Resources
180
+
181
+ * {Homepage}[http://code.simonecarletti.com/www-delicious]
182
+ * {API}[http://www-delicious.rubyforge.org/]
183
+ * {GitHub}[http://github.com/weppos/www-delicious/]
184
+ * {RubyForge}[http://rubyforge.org/projects/www-delicious/]
185
+
186
+
187
+ == FeedBack and Bug reports
188
+
189
+ Feel free to email {Simone Carletti}[mailto:weppos@weppos.net] with any questions or feedback.
190
+ Please use the {Ticket System}[http://code.simonecarletti.com/projects/show/www-delicious] to submit bug reports or feature request.
191
+
192
+
193
+ == Changelog
194
+
195
+ See the CHANGELOG.rdoc file for details.
196
+
197
+
198
+ == License
199
+
200
+ Copyright (c) 2008-2009 Simone Carletti, WWW::Delicious is released under the MIT license.
201
+
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ gem 'echoe', '>= 3.1'
5
+ require 'echoe'
6
+
7
+ $:.unshift(File.dirname(__FILE__) + "/lib")
8
+ require 'www/delicious'
9
+
10
+
11
+ # Common package properties
12
+ PKG_NAME = ENV['PKG_NAME'] || WWW::Delicious::GEM
13
+ PKG_VERSION = ENV['PKG_VERSION'] || WWW::Delicious::VERSION
14
+ PKG_SUMMARY = "Ruby client for del.icio.us API."
15
+ PKG_FILES = FileList.new("{lib,test}/**/*.rb") do |files|
16
+ files.include %w(README.rdoc CHANGELOG.rdoc LICENSE.rdoc)
17
+ files.include %w(Rakefile setup.rb)
18
+ end
19
+ RUBYFORGE_PROJECT = 'laco-www-delicious'
20
+
21
+ if ENV['SNAPSHOT'].to_i == 1
22
+ PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+
26
+ Echoe.new(PKG_NAME, PKG_VERSION) do |p|
27
+ p.author = "Simone Carletti"
28
+ p.email = "weppos@weppos.net"
29
+ p.summary = PKG_SUMMARY
30
+ p.description = <<-EOD
31
+ WWW::Delicious is a del.icio.us API client implemented in Ruby. \
32
+ It provides access to all available del.icio.us API queries \
33
+ and returns the original XML response as a friendly Ruby object.
34
+ EOD
35
+ p.url = "http://code.simonecarletti.com/www-delicious"
36
+ p.project = RUBYFORGE_PROJECT
37
+
38
+ p.need_zip = true
39
+ p.rcov_options = ["--main << README.rdoc -x Rakefile -x mocha -x rcov"]
40
+ p.rdoc_pattern = /^(lib|CHANGELOG.rdoc|README.rdoc)/
41
+
42
+ p.development_dependencies += ["rake >=0.8",
43
+ "echoe >=3.1",
44
+ "mocha >=0.9"]
45
+ end
46
+
47
+
48
+ begin
49
+ require 'code_statistics'
50
+ desc "Show library's code statistics"
51
+ task :stats do
52
+ CodeStatistics.new(["WWW::Delicious", "lib"],
53
+ ["Tests", "test"]).to_s
54
+ end
55
+ rescue LoadError
56
+ puts "CodeStatistics (Rails) is not available"
57
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{laco-www-delicious}
5
+ s.version = "0.3.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Simone Carletti"]
9
+ s.date = %q{2010-05-11}
10
+ s.description = %q{ WWW::Delicious is a del.icio.us API client implemented in Ruby. It provides access to all available del.icio.us API queries and returns the original XML response as a friendly Ruby object.
11
+ }
12
+ s.email = %q{weppos@weppos.net}
13
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/www/delicious.rb", "lib/www/delicious/bundle.rb", "lib/www/delicious/element.rb", "lib/www/delicious/errors.rb", "lib/www/delicious/post.rb", "lib/www/delicious/tag.rb", "lib/www/delicious/version.rb"]
14
+ s.files = ["CHANGELOG.rdoc", "Gemfile", "LICENSE.rdoc", "Manifest", "README.rdoc", "Rakefile", "lib/www/delicious.rb", "lib/www/delicious/bundle.rb", "lib/www/delicious/element.rb", "lib/www/delicious/errors.rb", "lib/www/delicious/post.rb", "lib/www/delicious/tag.rb", "lib/www/delicious/version.rb", "setup.rb", "test/bundle_test.rb", "test/delicious_test.rb", "test/fixtures/net_response_invalid_account.yml", "test/fixtures/net_response_success.yml", "test/online_test.rb", "test/post_test.rb", "test/tag_test.rb", "test/test_all.rb", "test/test_helper.rb", "test/testcases/element/bundle.xml", "test/testcases/element/invalid_root.xml", "test/testcases/element/post.xml", "test/testcases/element/post_unshared.xml", "test/testcases/element/tag.xml", "test/testcases/response/bundles_all.xml", "test/testcases/response/bundles_all_empty.xml", "test/testcases/response/bundles_delete.xml", "test/testcases/response/bundles_set.xml", "test/testcases/response/bundles_set_error.xml", "test/testcases/response/posts_add.xml", "test/testcases/response/posts_all.xml", "test/testcases/response/posts_dates.xml", "test/testcases/response/posts_dates_with_tag.xml", "test/testcases/response/posts_delete.xml", "test/testcases/response/posts_get.xml", "test/testcases/response/posts_get_with_tag.xml", "test/testcases/response/posts_recent.xml", "test/testcases/response/posts_recent_with_tag.xml", "test/testcases/response/tags_get.xml", "test/testcases/response/tags_get_empty.xml", "test/testcases/response/tags_rename.xml", "test/testcases/response/update.delicious1.xml", "test/testcases/response/update.xml", "laco-www-delicious.gemspec"]
15
+ s.homepage = %q{http://code.simonecarletti.com/www-delicious}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Laco-www-delicious", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{laco-www-delicious}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.summary = %q{Ruby client for del.icio.us API.}
21
+ s.test_files = ["test/test_all.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<rake>, [">= 0.8"])
29
+ s.add_development_dependency(%q<echoe>, [">= 3.1"])
30
+ s.add_development_dependency(%q<mocha>, [">= 0.9"])
31
+ else
32
+ s.add_dependency(%q<rake>, [">= 0.8"])
33
+ s.add_dependency(%q<echoe>, [">= 3.1"])
34
+ s.add_dependency(%q<mocha>, [">= 0.9"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<rake>, [">= 0.8"])
38
+ s.add_dependency(%q<echoe>, [">= 3.1"])
39
+ s.add_dependency(%q<mocha>, [">= 0.9"])
40
+ end
41
+ 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
+ #
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
+ #
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
+ #
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