Class: Handsoap::Service

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

Constant Summary collapse

@@logger =
nil
@@instance =
{}

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/handsoap/service.rb', line 127

def method_missing(method, *args)
  action = self.class.get_mapping(method)
  if action
    invoke(action, *args)
  else
    super
  end
end

Class Method Details

.endpoint(args = {}) ⇒ Object



83
84
85
86
# File 'lib/handsoap/service.rb', line 83

def self.endpoint(args = {})
  @protocol_version = args[:version] || raise("Missing option :version")
  @uri = args[:uri] || raise("Missing option :uri")
end

.envelope_namespaceObject



87
88
89
90
91
92
# File 'lib/handsoap/service.rb', line 87

def self.envelope_namespace
  if SOAP_NAMESPACE[@protocol_version].nil?
    raise "Unknown protocol version '#{@protocol_version.inspect}'"
  end
  SOAP_NAMESPACE[@protocol_version]
end

.fire_on_create_document(doc) ⇒ Object



105
106
107
108
109
# File 'lib/handsoap/service.rb', line 105

def self.fire_on_create_document(doc)
  if @create_document_callback
    @create_document_callback.call doc
  end
end

.get_mapping(name) ⇒ Object



113
114
115
# File 'lib/handsoap/service.rb', line 113

def self.get_mapping(name)
  @mapping[name] if @mapping
end

.instanceObject



117
118
119
# File 'lib/handsoap/service.rb', line 117

def self.instance
  @@instance[self.to_s] ||= self.new
end

.logger=(io) ⇒ Object



80
81
82
# File 'lib/handsoap/service.rb', line 80

def self.logger=(io)
  @@logger = io
end

.map_method(mapping) ⇒ Object



96
97
98
99
100
101
# File 'lib/handsoap/service.rb', line 96

def self.map_method(mapping)
  if @mapping.nil?
    @mapping = {}
  end
  @mapping.merge! mapping
end

.method_missing(method, *args) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/handsoap/service.rb', line 120

def self.method_missing(method, *args)
  if instance.respond_to?(method)
    instance.__send__ method, *args
  else
    super
  end
end

.on_create_document(&block) ⇒ Object



102
103
104
# File 'lib/handsoap/service.rb', line 102

def self.on_create_document(&block)
  @create_document_callback = block
end

.request_content_typeObject



93
94
95
# File 'lib/handsoap/service.rb', line 93

def self.request_content_type
  @protocol_version == 1 ? "text/xml" : "application/soap+xml"
end

.uriObject



110
111
112
# File 'lib/handsoap/service.rb', line 110

def self.uri
  @uri
end

Instance Method Details

#invoke(action, options = { :soap_action => :auto }, &block) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/handsoap/service.rb', line 135

def invoke(action, options = { :soap_action => :auto }, &block)
	if action
		if options.kind_of? String
			options = { :soap_action => options }
		end
		if options[:soap_action] == :auto
			options[:soap_action] = action.gsub(/^.+:/, "")
		elsif options[:soap_action] == :none
			options[:soap_action] = nil
		end
		doc = make_envelope do |body|
			body.add action
		end
		if block_given?
			yield doc.find(action)
		end
		dispatch(doc, options[:soap_action])
	end
end

#on_before_dispatchObject



154
155
# File 'lib/handsoap/service.rb', line 154

def on_before_dispatch
end

#on_fault(fault) ⇒ Object



156
157
158
# File 'lib/handsoap/service.rb', line 156

def on_fault(fault)
  raise fault
end