Skip to content
This repository
Newer
Older
100644 46 lines (34 sloc) 1.371 kb
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
1 dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
1d48da03 »
2008-07-28 Renamed to HTTParty which is way more fun and unique than boring old …
2 require File.join(dir, 'httparty')
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
3 require 'pp'
4 config = YAML::load(File.read(File.join(ENV['HOME'], '.delicious')))
5
6 class Delicious
1d48da03 »
2008-07-28 Renamed to HTTParty which is way more fun and unique than boring old …
7 include HTTParty
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
8
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
9 # sets the base url for each request
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
10 base_uri 'https://api.del.icio.us/v1'
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
11
12 # parse xml automatically
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
13 format :xml
14
15 def initialize(user, pass)
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
16 # set basic http authentication for all requests
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
17 self.class.basic_auth(user, pass)
18 end
19
20 # query params that filter the posts are:
21 # tag (optional). Filter by this tag.
22 # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
23 # url (optional). Filter by this url.
24 # ie: posts(:query => {:tag => 'ruby'})
25 def posts(options={})
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
26 # get posts and convert to structs so we can do .key instead of ['key'] with results
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
27 self.class.get('/posts/get', options)['posts']['post'].map { |b| b.to_struct }
28 end
29
30 # query params that filter the posts are:
31 # tag (optional). Filter by this tag.
32 # count (optional). Number of items to retrieve (Default:15, Maximum:100).
33 def recent(options={})
34 self.class.get('/posts/recent', options)['posts']['post'].map { |b| b.to_struct }
35 end
36 end
37
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
38 delicious = Delicious.new(config['username'], config['password'])
39
40 pp delicious.posts(:query => {:tag => 'ruby'})
41
42 puts '', '*' * 50, ''
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
43
aafde867 »
2008-07-28 Documented and tweaked the examples a bit.
44 pp delicious.recent
99cd89d3 »
2008-07-27 added delicious example and tweaked the twitter example
45
Something went wrong with that request. Please try again.