module Thoth::Plugin::Flickr

Flickr plugin for Thoth.

Public Class Methods

recent_photos(username, limit = 4) click to toggle source

Gets recent Flickr photos (up to limit) for the specified username. The return value of this method is cached to improve performance and to avoid abusing the Flickr API.

# File lib/thoth/plugin/thoth_flickr.rb, line 60
def recent_photos(username, limit = 4)
  cache = Ramaze::Cache.plugin
  key   = "recent_photos_#{username}_#{limit}"

  if value = cache[key]
    return value
  end

  @flickr ||= Net::Flickr.new(Config.flickr['api_key'])

  begin
    Timeout.timeout(Config.flickr['request_timeout'].to_i, StandardError) do
      value = cache.store(key, @flickr.people.find_by_username(username).
          photos(:per_page => limit), :ttl => Config.flickr['cache_ttl'])
    end
  rescue => e
    Ramaze::Log.error "Thoth::Plugin::Flickr: #{e.message}"
    return []
  else
    value
  end
end