Delicious API with HTTParty Gem


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # From: http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited
  2. # Author: John Nunemaker
  3.  
  4. # Delicious API with HTTParty Gem
  5.  
  6. require 'rubygems'
  7. require 'httparty'
  8.  
  9. class Delicious
  10. include HTTParty
  11. base_uri 'https://api.del.icio.us/v1'
  12.  
  13. def initialize(auth)
  14. @auth = auth
  15. end
  16.  
  17. # query params that filter the posts are:
  18. # tag (optional). Filter by this tag.
  19. # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
  20. # url (optional). Filter by this url.
  21. # ie: posts(:query => {:tag => 'ruby'})
  22. def posts(options={})
  23. options.merge!({:basic_auth => @auth})
  24. # get posts and convert to structs so we can do .key instead of ['key'] with results
  25. self.class.get('/posts/get', options)
  26. end
  27.  
  28. # query params that filter the posts are:
  29. # tag (optional). Filter by this tag.
  30. # count (optional). Number of items to retrieve (Default:15, Maximum:100).
  31. def recent(options={})
  32. options.merge!({:basic_auth => @auth})
  33. self.class.get('/posts/recent', options)
  34. end
  35. end
  36.  
  37. # CHANGE USERNAME & PASS !!!
  38. delicious = Delicious.new( :username => 'username', :password => 'password' )
  39. puts delicious.posts(:query => {:tag => 'ruby'}).inspect
  40. puts
  41. puts delicious.recent.inspect

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.