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'
|
2015-04-18 08:38:40 -04:00
|
|
|
config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
|
2008-07-27 19:13:44 -04:00
|
|
|
|
|
|
|
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'
|
2013-04-18 08:09:21 -04:00
|
|
|
|
2008-07-31 00:05:36 -04:00
|
|
|
def initialize(u, p)
|
2016-11-08 09:20:36 -05:00
|
|
|
@auth = { username: u, password: p }
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
2013-04-18 08:09:21 -04:00
|
|
|
|
2008-07-27 19:13:44 -04:00
|
|
|
# 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.
|
2014-05-15 16:45:32 -04:00
|
|
|
# ie: posts(query: {tag: 'ruby'})
|
2015-04-18 06:27:50 -04:00
|
|
|
def posts(options = {})
|
2016-11-08 09:20:36 -05:00
|
|
|
options.merge!({ basic_auth: @auth })
|
2008-07-31 00:05:36 -04:00
|
|
|
self.class.get('/posts/get', options)
|
2008-07-27 19:13:44 -04:00
|
|
|
end
|
2013-04-18 08:09:21 -04:00
|
|
|
|
2008-07-27 19:13:44 -04:00
|
|
|
# query params that filter the posts are:
|
|
|
|
# tag (optional). Filter by this tag.
|
|
|
|
# count (optional). Number of items to retrieve (Default:15, Maximum:100).
|
2015-04-18 06:27:50 -04:00
|
|
|
def recent(options = {})
|
2016-11-08 09:20:36 -05:00
|
|
|
options.merge!({ basic_auth: @auth })
|
2008-07-31 00:05:36 -04:00
|
|
|
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'])
|
2016-11-08 09:20:36 -05:00
|
|
|
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
|
|
|
|
2013-04-18 08:09:21 -04:00
|
|
|
delicious.recent['posts']['post'].each { |post| puts post['href'] }
|