Class: Savon::Operation
- Inherits:
-
Object
- Object
- Savon::Operation
- Defined in:
- lib/savon/operation.rb
Constant Summary collapse
- SOAP_REQUEST_TYPE =
{ 1 => "text/xml", 2 => "application/soap+xml" }
- SOAP_REQUEST_TYPE_MTOM =
"application/xop+xml"
Class Method Summary collapse
- .create(operation_name, wsdl, globals) ⇒ Object
- .ensure_exists!(operation_name, wsdl) ⇒ Object
- .ensure_name_is_symbol!(operation_name) ⇒ Object
Instance Method Summary collapse
- #build(locals = {}, &block) ⇒ Object
- #call(locals = {}, &block) ⇒ Object
-
#initialize(name, wsdl, globals) ⇒ Operation
constructor
A new instance of Operation.
- #request(locals = {}, &block) ⇒ Object
Constructor Details
#initialize(name, wsdl, globals) ⇒ Operation
Returns a new instance of Operation.
47 48 49 50 51 52 53 |
# File 'lib/savon/operation.rb', line 47 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
22 23 24 25 26 27 28 29 |
# File 'lib/savon/operation.rb', line 22 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
31 32 33 34 35 36 37 38 |
# File 'lib/savon/operation.rb', line 31 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
40 41 42 43 44 45 |
# File 'lib/savon/operation.rb', line 40 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
55 56 57 58 |
# File 'lib/savon/operation.rb', line 55 def build(locals = {}, &block) set_locals(locals, block) Builder.new(@name, @wsdl, @globals, @locals) end |
#call(locals = {}, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/savon/operation.rb', line 60 def call(locals = {}, &block) builder = build(locals, &block) response = Savon.notify_observers(@name, builder, @globals, @locals) response ||= call_with_logging build_connection(builder) raise_expected_faraday_response! unless response.kind_of?(Faraday::Response) create_response(response) end |
#request(locals = {}, &block) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/savon/operation.rb', line 71 def request(locals = {}, &block) builder = build(locals, &block) connection = build_connection(builder) connection.build_request(:post) do |req| req.url(@globals[:endpoint]) req.body = @locals[:body] end end |