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
|
|
|
|
2008-07-28 12:58:40 -04:00
|
|
|
# sets the base url for each request
|
2008-07-27 19:13:44 -04:00
|
|
|
base_uri 'https://api.del.icio.us/v1'
|
2008-07-28 12:58:40 -04:00
|
|
|
|
|
|
|
# parse xml automatically
|
2008-07-27 19:13:44 -04:00
|
|
|
format :xml
|
|
|
|
|
|
|
|
def initialize(user, pass)
|
2008-07-28 12:58:40 -04:00
|
|
|
# set basic http authentication for all requests
|
2008-07-27 19:13:44 -04:00
|
|
|
self.class.basic_auth(user, pass)
|
|
|
|
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-28 12:58:40 -04:00
|
|
|
# get posts and convert to structs so we can do .key instead of ['key'] with results
|
2008-07-27 19:13:44 -04:00
|
|
|
self.class.get('/posts/get', options)['posts']['post'].map { |b| b.to_struct }
|
|
|
|
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={})
|
|
|
|
self.class.get('/posts/recent', options)['posts']['post'].map { |b| b.to_struct }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-28 12:58:40 -04:00
|
|
|
delicious = Delicious.new(config['username'], config['password'])
|
|
|
|
|
|
|
|
pp delicious.posts(:query => {:tag => 'ruby'})
|
|
|
|
|
|
|
|
puts '', '*' * 50, ''
|
2008-07-27 19:13:44 -04:00
|
|
|
|
2008-07-28 12:58:40 -04:00
|
|
|
pp delicious.recent
|
2008-07-27 19:13:44 -04:00
|
|
|
|