Class: Magento::Connection
- Inherits:
-
Object
- Object
- Magento::Connection
- Defined in:
- lib/magento/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #call(method = nil, *args) ⇒ Object
- #connect ⇒ Object
-
#initialize(config = {}) ⇒ Connection
constructor
A new instance of Connection.
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
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/magento/connection.rb', line 3 def client @client end |
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/magento/connection.rb', line 3 def config @config end |
#logger ⇒ Object
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 |
#connect ⇒ Object
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 |