Class: Savon::Operation

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

Constant Summary collapse

SOAP_REQUEST_TYPE =
{
  1 => "text/xml",
  2 => "application/soap+xml"
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, wsdl, globals) ⇒ Operation

Returns a new instance of Operation.



44
45
46
47
48
49
50
# File 'lib/savon/operation.rb', line 44

def initialize(name, wsdl, globals)
  @name = name
  @wsdl = wsdl
  @globals = globals

  @logger = RequestLogger.new(globals)
end

Class Method Details

.create(operation_name, wsdl, globals) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/savon/operation.rb', line 19

def self.create(operation_name, wsdl, globals)
  if wsdl.document?
    ensure_name_is_symbol! operation_name
    ensure_exists! operation_name, wsdl
  end

  new(operation_name, wsdl, globals)
end

.ensure_exists!(operation_name, wsdl) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/savon/operation.rb', line 28

def self.ensure_exists!(operation_name, wsdl)
  unless wsdl.soap_actions.include? operation_name
    raise UnknownOperationError, "Unable to find SOAP operation: #{operation_name.inspect}\n" \
                                 "Operations provided by your service: #{wsdl.soap_actions.inspect}"
  end
rescue Wasabi::Resolver::HTTPError => e
  raise HTTPError.new(e.response)
end

.ensure_name_is_symbol!(operation_name) ⇒ Object



37
38
39
40
41
42
# File 'lib/savon/operation.rb', line 37

def self.ensure_name_is_symbol!(operation_name)
  unless operation_name.kind_of? Symbol
    raise ArgumentError, "Expected the first parameter (the name of the operation to call) to be a symbol\n" \
                         "Actual: #{operation_name.inspect} (#{operation_name.class})"
  end
end

Instance Method Details

#build(locals = {}, &block) ⇒ Object



52
53
54
55
# File 'lib/savon/operation.rb', line 52

def build(locals = {}, &block)
  set_locals(locals, block)
  Builder.new(@name, @wsdl, @globals, @locals)
end

#call(locals = {}, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/savon/operation.rb', line 57

def call(locals = {}, &block)
  builder = build(locals, &block)

  response = Savon.notify_observers(@name, builder, @globals, @locals)
  response ||= call_with_logging build_request(builder)

  raise_expected_httpi_response! unless response.kind_of?(HTTPI::Response)

  create_response(response)
end

#request(locals = {}, &block) ⇒ Object



68
69
70
71
# File 'lib/savon/operation.rb', line 68

def request(locals = {}, &block)
  builder = build(locals, &block)
  build_request(builder)
end