Class: Savon::Operation

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, wsdl, globals) ⇒ Operation

Returns a new instance of Operation.



34
35
36
37
38
39
40
# File 'lib/savon/operation.rb', line 34

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



11
12
13
14
15
16
17
18
# File 'lib/savon/operation.rb', line 11

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



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

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
end

.ensure_name_is_symbol!(operation_name) ⇒ Object



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

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



42
43
44
45
# File 'lib/savon/operation.rb', line 42

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

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



47
48
49
50
51
52
53
54
55
56
# File 'lib/savon/operation.rb', line 47

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