Class: Deliruby::Bookmarks

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HTTParty::Icebox
Defined in:
lib/deliruby.rb

Overview

Provides instance methods to access the public feeds of delicious.com, returning an array of Bookmark instances

Class Method Summary collapse

Methods included from HTTParty::Icebox

included

Class Method Details

.by_tags(tags = []) ⇒ Object Also known as: tagged

Get the recent bookmarks tagged with a combination of tags Params:

tags

an Array of tags; notice that the search is for bookmarks that include them all, not just a subset



68
69
70
# File 'lib/deliruby.rb', line 68

def self.by_tags(tags=[])        
    return self.get_feed("/tag/#{tags.join('+')}")
end

.for_url(url) ⇒ Object

Get the recent bookmarks for a specific url Params:

url

the url for which to get recent bookmarks



105
106
107
# File 'lib/deliruby.rb', line 105

def self.for_url(url)
    return self.get_feed("/url/#{Digest::MD5.hexdigest(url)}")
end

.for_user(user, tags = []) ⇒ Object Also known as: for

Get the recent bookmarks of a user, by tags Params:

user

the delicious username of the queried user

tags

an Array of tags, if not provided, just gets the recent bookmarks of the user



83
84
85
# File 'lib/deliruby.rb', line 83

def self.for_user(user, tags=[])
    return self.get_feed("/#{user}/#{tags.join('+')}")
end

.get_feed(url = "/") ⇒ Object Also known as: hotlist

Base method for all the calls to the delicious api Params:

url

the sub-url to access



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/deliruby.rb', line 48

def self.get_feed(url="/") 
    res = get(url)
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    bookmarks = []
    return [] unless res['rss']['channel'].has_key?('item')
    res['rss']['channel']['item'].each do |item|
        bookmarks.push DeliciousBookmark.new(item['link'], item['title'], item['pubDate'], item['dc:creator'],
                                             item['category']) rescue next
    end
    return bookmarks
end

.network(user, tags = []) ⇒ Object Also known as: for_network

Get the recent bookmarks of a user’s network, by tags Params:

user

the delicious username

tags

an optional array of tags to filter by



98
99
100
# File 'lib/deliruby.rb', line 98

def self.network(user, tags=[])
    return self.get_feed("/network/#{user}/#{tags.join('+')}")
end

Get the most recent popular bookmarks (optionally) by tag Params:

tag

the tag to get popular bookmarks for; if not provided, just gets the globally popular bookmarks



75
76
77
# File 'lib/deliruby.rb', line 75

def self.popular(tag="")
    return self.get_feed("/popular#{"/"+tag if tag}")
end

.recentObject

Get the recent bookmarks on delicious



61
62
63
# File 'lib/deliruby.rb', line 61

def self.recent
    return self.get_feed('/recent')
end

.subscripted(user) ⇒ Object Also known as: for_subscriptions

Get the recent bookmarks of a user’s subscriptions Params:

user

the delicious username of the user



90
91
92
# File 'lib/deliruby.rb', line 90

def self.subscripted(user)
    return self.get_feed("/subscriptions/#{user}")
end