Advertisement
Guest User

Sam Joseph

a guest
Sep 14th, 2010
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.98 KB | None | 0 0
  1. #!/usr/bin/ruby -w
  2. # delicious-sax.rb
  3. require 'open-uri'
  4. require 'rexml/parsers/sax2parser'
  5.  
  6. def print_my_recent_bookmarks(username, password)
  7.   # Make an HTTPS request and read the entity-body as an XML document.
  8.   xml = open('https://api.del.icio.us/v1/posts/recent',
  9.              :http_basic_authentication => [username, password])
  10.  
  11.   # Create a SAX parser whose destiny is to parse the XML entity-body.
  12.   parser = REXML::Parsers::SAX2Parser.new(xml)
  13.  
  14.   # When the SAX parser encounters a 'post' tag...
  15.   parser.listen(:start_element, ["post"]) do |uri, tag, fqtag, attributes|
  16.     # ...it should print out information about the tag.
  17.     puts "#{attributes['description']}: #{attributes['href']}"
  18.   end
  19.  
  20.   # Make the parser fulfil its destiny to parse the XML entity-body.
  21.   parser.parse
  22. end
  23.  
  24. # Main program.
  25. username, password = ARGV
  26. unless username and password
  27.   puts "Usage: #{$0} [USERNAME] [PASSWORD]"  
  28.   exit
  29. end
  30. print_my_recent_bookmarks(username, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement