Created
August 22, 2009 14:10
-
-
Save kaiwren/172794 to your computer and use it in GitHub Desktop.
Delicious example from http://github.com/kaiwren/wrest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'wrest' | |
require 'pp' | |
Wrest.logger = Logger.new(STDOUT) | |
Wrest.logger.level = Logger::DEBUG # Set this to Logger::INFO or higher to disable request logging | |
# This example demonstrates the usage of GET, POST, PUT and | |
# DELETE over HTTPS. Its also shows how Wrest::Uris can have | |
# paths extended making accessing an API easy as pie. | |
# | |
# API reference: http://delicious.com/help/api | |
class Delicious | |
def initialize(options) | |
@uri = "https://api.del.icio.us/v1/posts".to_uri(options) | |
end | |
def bookmarks(parameters = {}) | |
@uri['/get'].get(parameters) | |
end | |
def recent(parameters = {}) | |
@uri['/recent'].get(parameters) | |
end | |
def bookmark(parameters) | |
@uri['/add'].post('', {}, parameters) | |
end | |
def delete(parameters) | |
@uri['/delete'].delete(parameters) | |
end | |
end | |
account = Delicious.new :username => 'kaiwren', :password => 'fupupp1es' | |
pp account.bookmark( | |
:url => 'http://blog.sidu.in/search/label/ruby', | |
:description => 'The Ruby related posts on my blog!', | |
:extended => "All posts tagged with 'ruby'", | |
:tags => 'ruby hacking' | |
) | |
puts '', '*'*70, '' | |
pp account.bookmarks(:tag => 'rails', :dt => '20090712').deserialise | |
puts '', '*'*70, '' | |
pp recently_saved_uris = account.recent(:tag => 'ruby').deserialise["posts"]["post"].collect{|bookmark| bookmark['href']} | |
puts '', '*'*70, '' | |
pp account.delete(:url => 'http://blog.sidu.in/search/label/ruby') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment