Class: Deliruby::PublicInfo

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

Overview

access the public information that’s not necesarily bookmarks because the information varies, it returns hashes or arrays of hashes instead of a class instance

Class Method Summary collapse

Methods included from HTTParty::Icebox

included

Class Method Details

.alertsObject

Get a the site alerts Params

url

the url to retrieve



130
131
132
133
134
135
136
137
138
139
# File 'lib/deliruby.rb', line 130

def self.alerts
    res = get("/alerts")
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    return [] unless res['rss']['channel'].has_key?('item')
    alerts = []
    res['rss']['channel']['item'].each do |item|
        alerts.push item rescue next
    end
    return alerts
end

.network(user) ⇒ Object Also known as: network_for, network_for_user

Get a list of the network members for a user Params:

user

the user to peruse



174
175
176
177
178
179
180
181
182
183
# File 'lib/deliruby.rb', line 174

def self.network(user)
    res = get("/networkmembers/#{user}")
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    return [] unless res['rss']['channel'].has_key?('item')
    members = []
    res['rss']['channel']['item'].each do |item|
        members.push({:user => item['title'], :profile=>item['link']}) rescue next
    end
    return members
end

.network_fans(user) ⇒ Object Also known as: network_fans_for, network_fans_for_user

Get a list of the network fans for a user Params:

user

the user to peruse



188
189
190
191
192
193
194
195
196
197
# File 'lib/deliruby.rb', line 188

def self.network_fans(user)
    res = get("/networkfans/#{user}")
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    return [] unless res['rss']['channel'].has_key?('item')
    members = []
    res['rss']['channel']['item'].each do |item|
        members.push({:user => item['title'], :profile=>item['link']}) rescue next
    end
    return members
end

.tags(user, tags = []) ⇒ Object Also known as: tags_for_user, tags_for

Get the top public tags of a user and how many items are bookmarked with them and also get the related tags if a filtering array of tags is provided Params:

user

the user to peruse



160
161
162
163
164
165
166
167
168
169
# File 'lib/deliruby.rb', line 160

def self.tags(user, tags=[])
    res = get("/tags/#{user}/#{tags.join('+')}")
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    return [] unless res['rss']['channel'].has_key?('item')
    info = []
    res['rss']['channel']['item'].each do |item|
        info.push({item['title']=>item['description']}) rescue next
    end
    return info
end

.url(url) ⇒ Object Also known as: for_url, urlinfo, url_info

Return summary information for a given url



200
201
202
203
204
# File 'lib/deliruby.rb', line 200

def self.url(url)
    #for some reason, the cache screws this one up
    get_without_caching("/urlinfo/#{Digest::MD5.hexdigest(url)}",:format => :json, 
                    :base_uri => self.default_options[:base_uri].gsub('xml', 'json')).parsed_response[0]
end

.user_info(user) ⇒ Object Also known as: for_user, userinfo

Get public info for a user: the number of bookmarks, network members and network fans Params

user

the user



144
145
146
147
148
149
150
151
152
153
# File 'lib/deliruby.rb', line 144

def self.(user)
    res = get("/userinfo/#{user}")
    raise "Communication error with delicious server: #{res.response['status']}" if res.response['status'] =~ /^[45]/
    return [] unless res['rss']['channel'].has_key?('item')
    info = {}
    res['rss']['channel']['item'].each do |item|
        info[item['title']] = item['description'] rescue next
    end
    return info
end