Skip to content

Instantly share code, notes, and snippets.

@masutaka
Created February 3, 2014 14:20
Show Gist options
  • Save masutaka/8784655 to your computer and use it in GitHub Desktop.
Save masutaka/8784655 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
require 'xmlrpc/client'
# http://d.hatena.ne.jp/snaka72/20110702/1309595184
# slobby patch for Hatena bookmark API
module Net
module HTTPHeader
alias :old_hash :[]
def [](key)
key == 'Content-Type' ? 'text/xml' : old_hash(key)
end
end
end
target_uri = 'http://masutaka.net/chalow/'
counter_api = XMLRPC::Client.new('b.hatena.ne.jp', '/xmlrpc')
current = counter_api.call('bookmark.getTotalCount', target_uri)
p current
# Occur!!
# /Users/masutaka/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/xmlrpc/client.rb:506:in `do_rpc': Wrong size. Was 136, should be 116 (RuntimeError)
# from /Users/masutaka/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/xmlrpc/client.rb:281:in `call2'
# from /Users/masutaka/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/xmlrpc/client.rb:262:in `call'
# from /Users/masutaka/test/ruby/test.rb:19:in `<main>'
@masutaka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment