module Thoth::Plugin::Delicious
Del.icio.us plugin for Thoth
.
Constants
- FEED_URL
Public Class Methods
recent_bookmarks(username, options = {})
click to toggle source
Gets recent del.icio.us bookmarks for the specified username. The return value of this method is cached to improve performance and to avoid pounding del.icio.us with excess traffic.
Available options:
:count
-
Number of bookmarks to return (default is 5)
:tags
-
Array of tags to filter by. Only bookmarks with the specified tags will be returned.
# File lib/thoth/plugin/thoth_delicious.rb, line 66 def recent_bookmarks(username, options = {}) cache = Ramaze::Cache.plugin options = {:count => 5}.merge(options) request = "#{FEED_URL}/#{::CGI.escape(username)}" << (options[:tags] ? '/' << ::CGI.escape(options[:tags].join(' ')) : '') << "?raw&count=#{options[:count]}" if value = cache[request] return value end response = [] Timeout.timeout(Config.delicious['request_timeout'], StandardError) do response = JSON.parse(open(request).read) end # Parse the response into a more friendly format. data = [] response.each do |item| data << { :url => item['u'], :desc => item['d'], :note => item['n'] ? item['n'] : '', :tags => item['t'] ? item['t'] : [] } end return cache.store(request, data, :ttl => Config.delicious['cache_ttl']) rescue => e Ramaze::Log.error "Thoth::Plugin::Delicious: #{e.message}" return [] end