Ruby del.icio.us sample


/ Published in: Ruby
Save to your folder(s)

Sample snip for my diu helper.


Copy this code and paste it in your HTML
  1. require 'diu'
  2.  
  3. class Exporter
  4. def to_html(object)
  5. case object
  6. when Diu::Posts::Post
  7. str = ""
  8. str << "<p><a href=\"%s\">%s</a></p>\n" % [object.href, object.description]
  9. str << "<p>%s</p>\n" % [object.extended] if object.extended
  10. if object.tag
  11. if @tag_link
  12. tags = object.tag.split(" ")
  13. tag_str = tags.map {|tag| "<a href=\"#{@tag_link}#{tag}\">#{tag}</a>"}.join("\n")
  14. else
  15. tag_str = object.tag
  16. end
  17. str << "<p>(tags: %s)</p>\n" % [tag_str]
  18. end
  19. when Array
  20. "<ul>\n%s</ul>\n" % [object.map { |p| "<li>\n%s</li>\n" % [to_html(p)]}.join]
  21. end
  22. end
  23.  
  24. attr_writer :tag_link
  25. end
  26.  
  27. def test_diu(username, password)
  28. conn = Diu::Connection.new(username, password)
  29. res = conn.posts.find("recent", "tag" => "to-blog")
  30. exp = Exporter.new()
  31. exp.tag_link = "http://del.icio.us/#{username}/"
  32. print exp.to_html(res)
  33. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.