Module: ChannelAdvisor::ServiceProxy::ClassMethods

Defined in:
lib/channel_advisor/service_proxy.rb

Instance Method Summary collapse

Instance Method Details

#define_service_methods(service_module, soap_class) ⇒ 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
# File 'lib/channel_advisor/service_proxy.rb', line 25

def define_service_methods(service_module, soap_class)
  const_set(:SERVICE_MODULE, service_module)
  const_set(:SOAP_CLASS, soap_class)

  soap_class::Methods.each do |m|
    method_name = m[1]
    result_method = "#{method_name}Result"
    class_name = method_name[0..0].upcase + method_name[1..-1]

    define_method(method_name) do |*args|
      if args.last.is_a? Hash
        options = args.pop
      else
        options = {:account_id => configatron.channel_advisor.}
      end
      args = args.unshift(options[:account_id])
      client = self.init_client(options[:developer_key], options[:password])
      
      verify_mode = configatron.channel_advisor.ssl_config.retrieve('verify_mode', OpenSSL::SSL::VERIFY_PEER)
      client.streamhandler.client.ssl_config.verify_mode = verify_mode

      request_class = service_module.const_get(class_name)
      request = request_class.new(*args)

      result = client.send(method_name, request)
      response = result.send(result_method)

      check_for_success(response)
      response.resultData
    end

    include ChannelAdvisor::ServiceProxy::InstanceMethods
  end
end