Hatena::Diary::Client

なんか長いので、自分用にラッパクラス作ってみた:

module Atompub
  ...
end

module Hatena
  module Diary
    class Client
      def initialize(user, pass)
        @auth = Atompub::Auth::Wsse.new(:username => user, :password => pass)
        @ap_client = Atompub::HatenaClient.new(:auth => @auth)
        uri_fmt = 'http://d.hatena.ne.jp/%s/atom'
        @service = @ap_client.get_service(uri_fmt % user)
        @collection_uri = @service.workspace.collections[1].href
      end

      def create_newentry(entry)
        @ap_client.create_entry(@collection_uri, entry)
      end
    end
  end
end

if __FILE__ == $0
  user = "myhoney0079"
  pass = "xxxx"
  
  cl = Hatena::Diary::Client.new(user, pass)
  entry = Atom::Entry.new(:title=>"title", :content=>"test")
  cl.create_newentry(entry)
end