/examples/delicious.rb

http://github.com/jnunemaker/httparty · Ruby · 37 lines · 23 code · 6 blank · 8 comment · 0 complexity · 6bb901076dba7f8e9da7dcfdf35d9c03 MD5 · raw file

  1. dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
  2. require File.join(dir, 'httparty')
  3. require 'pp'
  4. config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
  5. class Delicious
  6. include HTTParty
  7. base_uri 'https://api.del.icio.us/v1'
  8. def initialize(u, p)
  9. @auth = { username: u, password: p }
  10. end
  11. # query params that filter the posts are:
  12. # tag (optional). Filter by this tag.
  13. # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
  14. # url (optional). Filter by this url.
  15. # ie: posts(query: {tag: 'ruby'})
  16. def posts(options = {})
  17. options.merge!({ basic_auth: @auth })
  18. self.class.get('/posts/get', options)
  19. end
  20. # query params that filter the posts are:
  21. # tag (optional). Filter by this tag.
  22. # count (optional). Number of items to retrieve (Default:15, Maximum:100).
  23. def recent(options = {})
  24. options.merge!({ basic_auth: @auth })
  25. self.class.get('/posts/recent', options)
  26. end
  27. end
  28. delicious = Delicious.new(config['username'], config['password'])
  29. pp delicious.posts(query: { tag: 'ruby' })
  30. pp delicious.recent
  31. delicious.recent['posts']['post'].each { |post| puts post['href'] }