class GxG::Networking::SoapClient

Public Class Methods

new() click to toggle source

Standard:

# File lib/gxg/net_clients.rb, line 2236
def initialize()
  @client = nil
  self
end

Public Instance Methods

callmethod(*args) click to toggle source
# File lib/gxg/net_clients.rb, line 2265
def callmethod(*args)
  result = nil
  begin
    if args.size == 1
      the_method = args[0].to_s
      arguments = {}
    else
      if args.size > 1
        the_method = args[0].to_s
        unless args[1].is_any?(::Hash, ::Array)
          raise ArgumentError, "You MUST provide a Hash or Array to specify parameters for this method."
        end
        arguments = args[1]
      else
        raise ArgumentError, "You MUST provide a valid SOAP method."
      end
    end
    if @client
      response_tag = (the_method.gsub(/^.+:/, "") + "Response")
      response = @client.invoke(the_method) do |message|
        if arguments.is_a?(::Hash)
          arguments.each_pair do |the_key, the_value|
            message.add(the_key.to_s, the_value)
          end
        end
        if arguments.is_a?(::Array)
          arguments.each do |the_value|
            message.add("literal", the_value)
          end
        end
      end
      data = ::Oga::parse_xml(response.to_xml).css(response_tag)
      if data
        found_numbers = data.text.numeric_values
        found_value = []
        if found_numbers.is_a?(::Array)
          found_numbers.each do |the_subarray|
            if the_subarray.is_a?(::Array)
              if the_subarray[0].is_a?(::Hash)
                the_key = the_subarray[0].keys[0]
                found_value << the_subarray[0][(the_key)]
              end
            end
          end
        end
        result = {}
        result[(response_tag.to_sym)] = data.text
        #              if found_value.size > 0
        #                if found_value.size == 1
        #                  result[(response_tag.to_sym)] = found_value[0]
        #                else
        #                  result[(response_tag.to_sym)] = found_value
        #                end
        #              else
        #                result[(response_tag.to_sym)] = data.text
        #              end
      else
        raise Exception, "Failed to interpret response data. Data: #{data.inspect}"
      end
    end
  rescue Exception => the_error
    log_error({:error => the_error, :parameters => {:method => the_method, :arguments => arguments}})
  end
  result
end
closed?() click to toggle source
# File lib/gxg/net_clients.rb, line 2257
def closed?()
  if @client
    false
  else
    true
  end
end
interface() click to toggle source
# File lib/gxg/net_clients.rb, line 2331
def interface()
  if @client
    @client.interface
  end
end
login(the_url=nil, options={}) click to toggle source
# File lib/gxg/net_clients.rb, line 2241
def login(the_url=nil, options={})
  result = false
  begin
    @client = ::GxG::Networking::SoapDriver.new(the_url)
    result = true
  rescue Exception => the_error
    log_error({:error => the_error, :parameters => {:url => the_url}})
  end
  result
end
logout() click to toggle source
# File lib/gxg/net_clients.rb, line 2252
def logout()
  @client = nil
  true
end