Module: Thoth::Plugin::Delicious
- Defined in:
- lib/thoth/plugin/thoth_delicious.rb
Overview
Del.icio.us plugin for Thoth.
Constant Summary collapse
- FEED_URL =
'http://feeds.delicious.com/feeds/json'
Class Method Summary collapse
-
.recent_bookmarks(username, options = {}) ⇒ Object
Gets recent del.icio.us bookmarks for the specified username.
Class Method Details
.recent_bookmarks(username, options = {}) ⇒ Object
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/thoth/plugin/thoth_delicious.rb', line 66 def recent_bookmarks(username, = {}) cache = Ramaze::Cache.plugin = {:count => 5}.merge() request = "#{FEED_URL}/#{::CGI.escape(username)}" << ([:tags] ? '/' << ::CGI.escape([: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 |