Module: Thoth::Plugin::Pinboard
- Defined in:
- lib/thoth/plugin/thoth_pinboard.rb
Overview
Pinboard plugin for Thoth.
Constant Summary collapse
- FEED_URL =
'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Ffeeds.pinboard.in%2Frss%2Fu%3A{username}%22%20limit%20{limit}&format=json'
Class Method Summary collapse
-
.recent_bookmarks(username, options = {}) ⇒ Object
Gets recent Pinboard bookmarks for the specified username.
Class Method Details
.recent_bookmarks(username, options = {}) ⇒ Object
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)
60 61 62 63 64 65 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 |
# File 'lib/thoth/plugin/thoth_pinboard.rb', line 60 def recent_bookmarks(username, = {}) cache = Ramaze::Cache.plugin = {:count => 5}.merge() request = FEED_URL.gsub('{username}', ::CGI.escape(username)). gsub('{limit}', [: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.}" return [] end |