Class: Magento::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Connection

Returns a new instance of Connection.



4
5
6
7
8
# File 'lib/magento/connection.rb', line 4

def initialize(config = {})
  @logger ||= Logger.new(STDOUT)
  @config = config
  self
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/magento/connection.rb', line 3

def client
  @client
end

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/magento/connection.rb', line 3

def config
  @config
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/magento/connection.rb', line 3

def logger
  @logger
end

Instance Method Details

#call(method = nil, *args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/magento/connection.rb', line 15

def call(method = nil, *args)
  @logger.debug "call: #{method}, #{args.inspect}"
  connect
  @client.call("call", @session, method, args)
rescue XMLRPC::FaultException => e
  @logger.debug "exception: #{e.faultCode} -> #{e.faultString}"
  raise Magento::ApiError, "#{e.faultCode} -> #{e.faultString}"
end

#connectObject



10
11
12
13
# File 'lib/magento/connection.rb', line 10

def connect
  @client = XMLRPC::Client.new(config[:host], config[:path], config[:port])
  @session = @client.call("login", config[:username], config[:api_key])
end