WWW::Mechanizeã使ã£ã¦del.icio.usã«Postããã¹ã¯ãªãã
ã¨ãããããã¹ãçãªãããã使ã£ã¦PRaggerã®publish::deliciousãã©ã°ã¤ã³ã«ã§ãã¾ã¨ããããªããã¤ã³ãã¯BASICèªè¨¼ã使ã£ã¦ããã¨ãããã¨ãã£ã¦ã調ã¹ãããã£ããåããã¾ããã§ããproxyã¨ãæ¸ãã¦ãããã©å®éã«ããã¯ã·ä½¿ã£ã¦ã®åä½ç¢ºèªã¯ã¾ã ãã¦ãã¾ããã
require 'rubygems' require 'mechanize' require 'kconv' class Delicious def initialize username, password, proxy=nil @username = username @password = password @agent = WWW::Mechanize.new @agent.basic_auth(@username, @password) if proxy && proxy.is_a?(Hash) && proxy['proxy_addr'] && proxy['proxy_port'] @agent.set_proxy(proxy['proxy_addr'], proxy['proxy_port'], proxy['proxy_user'], proxy['proxy_pass']) end end def post url, desc, option=nil params = {} post_url = 'https://api.del.icio.us/v1/posts/add?' params[:url] = url params[:description] = desc req_url = [] params.each do |k,v| req_url << k.to_s.toutf8 + '=' + v.toutf8 end puts req_url.join('&') result = @agent.get(post_url + req_url.join('&')) end end agent = Delicious.new('username','password') agent.post 'http://www.google.co.jp/', 'google'
usernameã¨passwordã ãèªåã®ã¨æ¸ãæãã¦ãã ãããã
TODO
- ã³ã¡ã³ãã¨ãã¿ã°ã¨ããå ¥ããããããã«ï¼ãã¹ãä¸ã«del.icio.usè½ã¡ãorzï¼