class ActionKitApi::Connection

Public Class Methods

new(user, password, host) click to toggle source
# File lib/action_kit_api/connection.rb, line 53
def initialize(user, password, host)
  # Build the arguments for the XMLRPC::Client object
  conn_args = {
      :user => user,
      :password => password,
      :host => host,
      :use_ssl => true,
      :path => "/api"
    }

  @connection = XMLRPC::Client.new_from_hash(conn_args)

  # Unfortunately XMLRPC::Client does not expose it's SSL settings so
  # we need to dive into it's instance methods to set SSL verification
  # and add a CA to authenticate against
  @connection.instance_variable_get("@http").verify_mode = OpenSSL::SSL::VERIFY_PEER
  @connection.instance_variable_get("@http").ca_file = File.join(File.dirname(__FILE__), "actionkit_ca_chain.pem")

  return nil
end

Public Instance Methods

call(command, args) click to toggle source
# File lib/action_kit_api/connection.rb, line 74
def call(command, args)
  # XMLRPC::Client doesn't flush it's IO buffer which occasionally
  # causes a second command on the same connection to fail with an
  # EOFError. Using the _async version of this causes XMLRPC::Client
  # to use a new connection each time eliminating this issue
  @connection.call_async(command, args)
end
version() click to toggle source
# File lib/action_kit_api/connection.rb, line 82
def version
  self.call("version", {})
end