Class: ActionKitApi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/action_kit_api/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, password, host) ⇒ Connection

Returns a new instance of Connection.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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

Instance Method Details

#call(command, args) ⇒ Object



74
75
76
77
78
79
80
# 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

#versionObject



82
83
84
# File 'lib/action_kit_api/connection.rb', line 82

def version
  self.call("version", {})
end