/ Published in: Ruby
Provides a little bit of functionality to access del.icio.us bookmarks.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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