WWW::Delicious¶
- WWW::Delicious
- Requirements
- Download and Installation
- Getting Started
- Last account update
- Reading Posts
- Creating a new Post
- Deleting a Posts
- Tags
- Bundles
- FeedBack and Bug reports
- Resources
- License
WWW::Delicious is a Ruby client for delicious.com XML API.
It provides both read and write functionality. You can read user Posts, Tags and Bundles but you can create new Posts, Tags and Bundles as well.
WWW::Delicious maps all the original del.icio.us API calls and provides some additional convenient methods to perform common tasks. For a full API overview, visit the official Delicious API documentation.
WWW::Delicious is compatible with all delicious.com API constraints, including the requirement to set a valid user agent or wait at least one second between queries. Basically, the main benefit from using this library is that you don't need to take care of all these low level details, if you don't want: WWW::Delicious will try to give you the most with less efforts.
Requirements¶
- Ruby >= 1.8.6
As of release 0.3.0, WWW::Delicious is compatible with Ruby 1.9.
Download and Installation¶
Installing WWW::Delicious as a GEM is probably the best and easiest way.
You must have RubyGems installed for the following instruction to work:
$ sudo gem install www-delicious
To install the library manually grab the source code from the website, navigate to the root library directory and enter:
$ sudo ruby setup.rb
If you need the latest development version you can download the source code from the GIT repositories listed above.
Beware that the code might not as stable as the official release.
Getting Started¶
In order to use this library you need a valid del.icio.us account.
Go to http://del.icio.us/ and register for a new account if you don't already have one.
Then create a valid instance of WWW::Delicious providing your account credentials.
1 require 'www/delicious'
2
3 # create a new instance with given username and password
4 d = WWW::Delicious.new('username', 'password')
Now you can use your instance to interact with the API interface.
Last account update¶
The following example show you how to get the last account update Time.
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 time = d.update # => Fri May 02 18:02:48 UTC 2008
Reading Posts¶
You can fetch your posts in 3 different ways:
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # 1. get all posts
5 posts = d.posts_all
6
7 # 2. get recent posts
8 posts = d.posts_recent
9
10 # 3. get a single post (the latest one if no criteria is given)
11 posts = d.posts_get(:tag => 'ruby')
Each post call accepts some options to refine your search.
For example, you can always search for posts matching a specific tag.
1 posts = d.posts_all(:tag => 'ruby')
2 posts = d.posts_recent(:tag => 'ruby')
3 posts = d.posts_get(:tag => 'ruby')
Creating a new Post¶
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # add a post from options
5 d.posts_add(:url => 'http://www.simonecarletti.com/', :title => 'Cool site!')
6
7 # add a post from WWW::Delicious::Post
8 d.posts_add(WWW::Delicious::Post.new(:url => 'http://www.simonecarletti.com/', :title => 'Cool site!'))
Deleting a Posts¶
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # delete given post (the URL can be either a string or an URI)
5 d.posts_delete('http://www.foobar.com/')
Note. Actually you cannot delete a post from a WWW::Delicious::Post instance.
It means, the following example doesn't work as some ActiveRecord user might expect.
1 post = WWW::Delicious::Post.new(:url => 'http://www.foobar.com/')
2 post.delete
This feature is already in the TODO list. For now, use the following workaround
to delete a given Post.
1 # delete a post from an existing post = WWW::Delicious::Post
2 d.posts_delete(post.url)
Tags¶
Working with tags it's really easy. You can get all your tags or rename an existing tag.
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # get all tags
5 tags = d.tags_get
6
7 # print all tag names
8 tags.each { |t| puts t.name }
9
10 # rename the tag gems to gem
11 d.tags_rename('gems', 'gem')
Bundles¶
WWW::Delicious enables you to get all bundles from given account.
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # get all bundles
5 bundles = d.bundles_all
6
7 # print all bundle names
8 bundles.each { |b| puts b.name }
You can also create new bundles or delete existing ones.
1 require 'www/delicious'
2 d = WWW::Delicious.new('username', 'password')
3
4 # set a new bundle for tags ruby, rails and gem
5 d.bundles_set('MyBundle', %w(ruby rails gem))
6
7 # delete the old bundle
8 d.bundles_delete('OldBundle')
FeedBack and Bug reports¶
Feel free to email "Simone Carletti":weppos@weppos.net with any questions or feedback.
If you have a bug or feature request to report, please perform a quick search for the issue. If it isn't found, then log in and create a new issue.
Resources¶
License¶
Copyright (c) 2008-2009 Simone Carletti, WWW::Delicious is released under the MIT license.