Return to Snippet

Revision: 2781
at April 15, 2007 08:50 by felipec


Initial Code
require 'rest'
require 'rexml/document'

module Diu
	URL = "https://api.del.icio.us/v1/"

	class Connection
		def initialize(username, password)
			@conn = REST::Connection.new(URL, :username => username, :password => password)
			@posts = Posts.new(@conn)
		end

		attr_reader :posts
	end

	class Posts
		class Post
			def initialize(xml_item)
				@href = xml_item.attributes["href"]
				@time = xml_item.attributes["time"]
				@hash = xml_item.attributes["hash"]
				@tag = xml_item.attributes["tag"]
				@description = xml_item.attributes["description"]
				@extended = xml_item.attributes["extended"]
			end

			attr_reader :href, :time, :hash, :tag, :description, :extended
		end

		def initialize(conn)
			@conn = conn
		end

		def find(method, args = nil)
			resource = "posts/%s" % [method]
			request = @conn.request_get(resource, args)

			posts = Array.new
			doc = REXML::Document.new(request)
			doc.elements.each("//post") do |xml_post|
				posts << Post.new(xml_post)
			end
			posts
		end
	end
end

Initial URL


Initial Description
Provides a little bit of functionality to access del.icio.us bookmarks.

Initial Title
Ruby del.icio.us

Initial Tags


Initial Language
Ruby