module Thoth::Plugin::Pinboard

Pinboard plugin for Thoth.

Constants

FEED_URL

Public Class Methods

recent_bookmarks(username, options = {}) click to toggle source

Gets recent Pinboard bookmarks for the specified username. The return value of this method is cached to improve performance.

Available options:

:count

Number of bookmarks to return (default is 5)

# File lib/thoth/plugin/thoth_pinboard.rb, line 60
def recent_bookmarks(username, options = {})
  cache   = Ramaze::Cache.plugin
  options = {:count => 5}.merge(options)
  request = FEED_URL.gsub('{username}', ::CGI.escape(username)).
              gsub('{limit}', options[:count].to_s)

  if value = cache[request]
    return value
  end

  response = []

  Timeout.timeout(Config.pinboard['request_timeout'], StandardError) do
    response = JSON.parse(open(request).read)
  end

  # Parse the response into a more friendly format.
  data = []

  response['query']['results']['item'].each do |item|
    data << {
      :url   => item['link'],
      :title => item['title'].strip,
      :note  => (item['description'] || '').strip,
      :tags  => (item['subject'] || '').strip.split(' ')
    }
  end

  return cache.store(request, data, :ttl => Config.pinboard['cache_ttl'])

rescue => e
  Ramaze::Log.error "Thoth::Plugin::Pinboard: #{e.message}"
  return []
end