Authenticating with Pagekite API using Ruby

If you’re using pagekite, you probably have read this document.

It tells you how to connect to pagekite’s XMLRPC service to perform actions such as creating a new kite, checking your accounts etc.

Their example is in python and if you’re like me, trying to figure out how to get it to work in Ruby, here’s my snippet:

  # lets do this - test.rb
  require 'xmlrpc/client'
  server = XMLRPC::Client.new_from_uri('https://pagekite.net/xmlrpc/') 
  # note that you really need that trailing slash after /xmlrpc.

  # next you need to ensure that you add the http_header_extra header configuration
  # else you'll end up with a 'Wrong size. Was X, should be Y' error when making calls.

  server.http_header_extra = {'accept-encoding' => 'identity'}

  # now just login!
  ok, (a, c)= server.call('login', '<your pagekite identifier>', 'password', '')

  # follow the API as you would!
  ok, data = server.call('get_account_info', a, c, 0)

  # enjoy!