Class: Magento::XmlApi

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, api_user, api_key, options = {}) ⇒ XmlApi

Returns a new instance of XmlApi.



25
26
27
28
29
30
31
32
# File 'lib/magento/xml_api.rb', line 25

def initialize(base_url, api_user, api_key, options={})
  @url = "#{base_url}/api/xmlrpc/"
  @api_user = api_user
  @api_key = api_key
  @timeout = options[:timeout] || 60
  @proxy = options[:proxy] || nil 
  @debug = options[:debug] || false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/magento/xml_api.rb', line 82

def method_missing(method, *args, &block)
  # convert the method name to an XMLRPC action name e.g. "sales_order.list"
  parts = method.to_s.snakecase.split('_')
  action = "#{parts[0..-2].join('_')}.#{parts.last}" if parts.size > 1
  
  if action
    call action, *args, &block
  else
    super
  end
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/magento/xml_api.rb', line 23

def api_key
  @api_key
end

#api_userObject

Returns the value of attribute api_user.



23
24
25
# File 'lib/magento/xml_api.rb', line 23

def api_user
  @api_user
end

#urlObject

Returns the value of attribute url.



23
24
25
# File 'lib/magento/xml_api.rb', line 23

def url
  @url
end

Instance Method Details

#call(method, *arguments) ⇒ Object



34
35
36
# File 'lib/magento/xml_api.rb', line 34

def call(method, *arguments)
  request('call', session_id, method, arguments)
end