Class: Magento::SoapApiV2
- Inherits:
-
Object
- Object
- Magento::SoapApiV2
show all
- Extended by:
- Savon::Model
- Defined in:
- lib/magento/soap_api_v2.rb
Instance Method Summary
collapse
Constructor Details
#initialize(base_url, api_user, api_key) ⇒ SoapApiV2
Returns a new instance of SoapApiV2.
7
8
9
10
11
12
13
|
# File 'lib/magento/soap_api_v2.rb', line 7
def initialize(base_url, api_user, api_key)
super
@api_user = api_user
@api_key = api_key
self.class.client.wsdl.document = "#{base_url}/api/v2_soap?wsdl=1"
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/magento/soap_api_v2.rb', line 65
def method_missing(method, *args, &block)
class_name = self.class.name.snakecase
action = method
action = "#{class_name}_#{method}".to_sym unless client.wsdl.soap_actions.include?(action)
action = "#{class_name}_#{class_name}_#{method}".to_sym unless client.wsdl.soap_actions.include?(action)
action = "#{method.to_s.split('_').first}_#{method}".to_sym unless client.wsdl.soap_actions.include?(action)
puts "SOAP ACTION? #{action}"
if client.wsdl.soap_actions.include?(action)
body = args.first
session_request action, body, &block
else
super
end
end
|
Instance Method Details
#end_session ⇒ Object
61
62
63
|
# File 'lib/magento/soap_api_v2.rb', line 61
def end_session
session_request :end_session
end
|
#session_id(refresh = false) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/magento/soap_api_v2.rb', line 15
def session_id(refresh = false)
@session_id = nil if refresh
unless @session_id
response = client.request :login, :body => { :username => @api_user, :apiKey => @api_key }
@session_id = response[:login_response][:login_return]
end
@session_id
end
|
#session_request(action, body = {}, &block) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/magento/soap_api_v2.rb', line 25
def session_request(action, body = {}, &block)
begin
current_session_id = session_id
response = client.request action, :body => body do
yield soap, wsdl, http, wsse if block
soap.body ||= {}
soap.body[:session] = current_session_id
soap.body[:order!] = soap.body.keys.delete_if {|item| item == :session }.unshift(:session)
puts "SOAP BODY:::: #{soap.body}"
end
response.to_hash["#{action}_response".to_sym].tap do |response|
@retries = 0
end
rescue Savon::SOAP::Fault => error
raise error unless error.to_hash[:fault][:faultcode] == "5" && @retries == 0
puts "SESSION EXPIRED ... TRYING AGAIN"
@retries = 1
session_id(true)
session_request action, body, &block
end
end
|