2008-07-27 19:13:44 -04:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2008-07-28 10:49:53 -04:00
|
|
|
require File.join(dir, 'httparty')
|
2008-07-27 19:13:44 -04:00
|
|
|
require 'pp'
|
|
|
|
config = YAML::load(File.read(File.join(ENV['HOME'], '.delicious')))
|
|
|
|
|
|
|
|
class Delicious
|
2008-07-28 10:49:53 -04:00
|
|
|
include HTTParty
|
2008-07-27 19:13:44 -04:00
|
|
|
base_uri 'https://api.del.icio.us/v1'
|
|
|
|
|
2008-07-31 00:05:36 -04:00
|
|
|
def initialize(u, p)
|
|
|
|
@auth = {:username => u, :password => p}
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# query params that filter the posts are:
|
|
|
|
# tag (optional). Filter by this tag.
|
|
|
|
# dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
|
|
|
|
# url (optional). Filter by this url.
|
|
|
|
# ie: posts(:query => {:tag => 'ruby'})
|
|
|
|
def posts(options={})
|
2008-07-31 00:05:36 -04:00
|
|
|
options.merge!({:basic_auth => @auth})
|
|
|
|
self.class.get('/posts/get', options)
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# query params that filter the posts are:
|
|
|
|
# tag (optional). Filter by this tag.
|
|
|
|
# count (optional). Number of items to retrieve (Default:15, Maximum:100).
|
|
|
|
def recent(options={})
|
2008-07-31 00:05:36 -04:00
|
|
|
options.merge!({:basic_auth => @auth})
|
|
|
|
self.class.get('/posts/recent', options)
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-28 12:58:40 -04:00
|
|
|
delicious = Delicious.new(config['username'], config['password'])
|
|
|
|
pp delicious.posts(:query => {:tag => 'ruby'})
|
2008-12-06 23:41:28 -05:00
|
|
|
pp delicious.recent
|
2008-07-27 19:13:44 -04:00
|
|
|
|
2009-01-29 04:20:55 -05:00
|
|
|
delicious.recent['posts']['post'].each { |post| puts post['href'] }
|