class PaApi::PBA

Provides a connection to the default PBA API as configued in ENV

Public Class Methods

new(host: ENV['PBA_API'], path: '/RPC2', port: 5224) click to toggle source
# File lib/pa_api.rb, line 28
def initialize(host: ENV['PBA_API'], path: '/RPC2', port: 5224)
  @conn = XMLRPC::Client.new3(host: host, path: path, port: port)
end

Public Instance Methods

call(method, params = [], server = 'BM') click to toggle source

Makes a call to the PBA API, with the method param being the full method name, as a string, and an optional params Array. The server param can also be supplied for API calls that do not use 'BM'. Returns a Hash result.

# File lib/pa_api.rb, line 36
def call(method, params = [], server = 'BM')
  begin
    {
      status: 0,
      result:  @conn.call(
                :Execute,
                Method: method,
                Server: server,
                Params: params
              )['Result'][0]
    }
  rescue XMLRPC::FaultException => e
    {
      error_message: Base64.decode64(e.faultString).strip,
      status:       -1,
      method:       method,
      params:       params,
      result:       nil
    }
  rescue => e
    {
      status:       -1,
      result:        nil,
      method:        method,
      params:        params,
      error_message: e
    }
  end
end