Return to Snippet

Revision: 8868
at October 11, 2008 08:13 by pmd


Updated Code
# 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

Revision: 8867
at October 11, 2008 08:08 by pmd


Updated Code
# From: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited
# Author: John Nunemaker

# Delicious API with HTTParty Gem
# ¡¡¡ CHANGE USERNAME & PASS

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

Revision: 8866
at October 11, 2008 08:06 by pmd


Initial Code
# From: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited
# Author: John Nunemaker

# Delicious API with HTTParty Gem
# ¡¡¡ CHANGE USERNAME & PASS

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

Initial URL
http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited

Initial Description

                                

Initial Title
Delicious API with HTTParty Gem

Initial Tags
http

Initial Language
Ruby