Class: Soap::Base

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

Constant Summary collapse

SUB_CLASSES =
%i[request client response].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wsdl:, namespace:, endpoint: nil) ⇒ Base

Returns a new instance of Base.



49
50
51
52
53
# File 'lib/soap.rb', line 49

def initialize(wsdl:, namespace:, endpoint: nil)
  @wsdl = wsdl
  @namespace = namespace
  @endpoint = endpoint
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



47
48
49
# File 'lib/soap.rb', line 47

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



46
47
48
# File 'lib/soap.rb', line 46

def namespace
  @namespace
end

#wsdlObject (readonly)

Returns the value of attribute wsdl.



45
46
47
# File 'lib/soap.rb', line 45

def wsdl
  @wsdl
end

Instance Method Details

#buildObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/soap.rb', line 55

def build
  ns_module =
    if Object.const_defined?(namespace)
      Object.const_get(namespace)
    else
      Object.const_set(namespace, Module.new)
    end
  parser.soap_actions.each do |action|
    build_klass(ns_module, action, parser.soap_action(action), endpoint)
  end
  true
end

#build_custom_klass(mod, type_klass, action_klass) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/soap.rb', line 98

def build_custom_klass(mod, type_klass, action_klass)
  klass = Class.new(Object.const_get("Soap::Webservice::#{type_klass}")) do
    define_singleton_method :body_attributes do
      action_klass[:types][:body]
    end

    define_singleton_method :header_attributes do
      action_klass[:types][:header]
    end
  end

  mod.const_set(type_klass.to_s, klass)
end

#build_klass(mod, name, action, endpoint) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/soap.rb', line 68

def build_klass(mod, name, action, endpoint)
  service_name = parser.service[:base_endpoint]
  k_mod = mod.const_set(Soap.to_camelcase(name), Module.new)
  build_custom_klass(k_mod, "Request", action[:input])
  build_custom_klass(k_mod, "Response", action[:output])

  klass = Class.new(Soap::Webservice::Client) do
    define_singleton_method :namespace do
      if !endpoint.blank?
        endpoint
      else
        service_name
      end
    end

    define_singleton_method :action do
      action[:input][:port_type][:name]
    end

    define_method :response do
      @response ||= k_mod.const_get("Response")
    end

    # rubocop:disable all
    private :response
    # rubocop:enable all
  end
  k_mod.const_set("Client", klass)
end