Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby -w
- # delicious-sax.rb
- require 'open-uri'
- require 'rexml/parsers/sax2parser'
- def print_my_recent_bookmarks(username, password)
- # Make an HTTPS request and read the entity-body as an XML document.
- xml = open('https://api.del.icio.us/v1/posts/recent',
- :http_basic_authentication => [username, password])
- # Create a SAX parser whose destiny is to parse the XML entity-body.
- parser = REXML::Parsers::SAX2Parser.new(xml)
- # When the SAX parser encounters a 'post' tag...
- parser.listen(:start_element, ["post"]) do |uri, tag, fqtag, attributes|
- # ...it should print out information about the tag.
- puts "#{attributes['description']}: #{attributes['href']}"
- end
- # Make the parser fulfil its destiny to parse the XML entity-body.
- parser.parse
- end
- # Main program.
- username, password = ARGV
- unless username and password
- puts "Usage: #{$0} [USERNAME] [PASSWORD]"
- exit
- end
- print_my_recent_bookmarks(username, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement