/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# From: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited # Author: John Nunemaker # Delicious API with HTTParty Gem require 'rubygems' require 'httparty' class Delicious include HTTParty base_uri 'https://api.del.icio.us/v1' def initialize(auth) @auth = auth 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={}) options.merge!({:basic_auth => @auth}) # get posts and convert to structs so we can do .key instead of ['key'] with results self.class.get('/posts/get', options) 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={}) options.merge!({:basic_auth => @auth}) self.class.get('/posts/recent', options) end end # CHANGE USERNAME & PASS !!! delicious = Delicious.new( :username => 'username', :password => 'password' ) puts delicious.posts(:query => {:tag => 'ruby'}).inspect puts puts delicious.recent.inspect
URL: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited