Class: Sekken::Operation
- Inherits:
-
Object
- Object
- Sekken::Operation
- Defined in:
- lib/sekken/operation.rb
Constant Summary collapse
- ENCODING =
'UTF-8'
- CONTENT_TYPE =
{ '1.1' => 'text/xml', '1.2' => 'application/soap+xml' }
Instance Attribute Summary collapse
-
#body ⇒ Object
Public: Sets the request body Hash.
-
#encoding ⇒ Object
Public: Accessor for the encoding.
-
#endpoint ⇒ Object
Public: Accessor for the SOAP endpoint.
-
#header ⇒ Object
Public: Sets the request header Hash.
-
#http_headers ⇒ Object
Public: Returns a Hash of HTTP headers to send.
-
#soap_action ⇒ Object
Public: Accessor for the SOAPAction HTTP header.
-
#soap_version ⇒ Object
Public: Accessor for the SOAP version.
-
#xml_envelope ⇒ Object
Public: Sets the request envelope XML.
Instance Method Summary collapse
-
#body_parts ⇒ Object
Public: Returns the input body parts used to build the request body.
-
#build ⇒ Object
Public: Build the request XML for this operation.
-
#call ⇒ Object
Public: Call the operation.
-
#example_body ⇒ Object
Public: Create an example request body Hash.
-
#example_header ⇒ Object
Public: Create an example request header Hash.
-
#initialize(operation, wsdl, http) ⇒ Operation
constructor
A new instance of Operation.
-
#input_style ⇒ Object
Public: Returns the input style for this operation.
-
#output_style ⇒ Object
Public: Returns the output style for this operation.
Constructor Details
#initialize(operation, wsdl, http) ⇒ Operation
Returns a new instance of Operation.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sekken/operation.rb', line 15 def initialize(operation, wsdl, http) @operation = operation @wsdl = wsdl @http = http @endpoint = operation.endpoint @soap_version = operation.soap_version @soap_action = operation.soap_action @encoding = ENCODING end |
Instance Attribute Details
#body ⇒ Object
Public: Sets the request body Hash.
68 69 70 |
# File 'lib/sekken/operation.rb', line 68 def body @body end |
#encoding ⇒ Object
Public: Accessor for the encoding. Defaults to 'UTF-8'.
36 37 38 |
# File 'lib/sekken/operation.rb', line 36 def encoding @encoding end |
#endpoint ⇒ Object
Public: Accessor for the SOAP endpoint.
27 28 29 |
# File 'lib/sekken/operation.rb', line 27 def endpoint @endpoint end |
#header ⇒ Object
Public: Sets the request header Hash.
60 61 62 |
# File 'lib/sekken/operation.rb', line 60 def header @header end |
#http_headers ⇒ Object
Public: Returns a Hash of HTTP headers to send.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sekken/operation.rb', line 39 def http_headers return @http_headers if @http_headers headers = {} content_type = [ CONTENT_TYPE[soap_version], "charset=#{encoding}" ] case soap_version when '1.1' headers['SOAPAction'] = soap_action.nil? ? '' : %{"#{soap_action}"} when '1.2' content_type << %{action="#{soap_action}"} if soap_action && !soap_action.empty? end headers['Content-Type'] = content_type.join(';') @http_headers = headers end |
#soap_action ⇒ Object
Public: Accessor for the SOAPAction HTTP header.
33 34 35 |
# File 'lib/sekken/operation.rb', line 33 def soap_action @soap_action end |
#soap_version ⇒ Object
Public: Accessor for the SOAP version.
30 31 32 |
# File 'lib/sekken/operation.rb', line 30 def soap_version @soap_version end |
#xml_envelope ⇒ Object
Public: Sets the request envelope XML. Use in place of body().
86 87 88 |
# File 'lib/sekken/operation.rb', line 86 def xml_envelope @xml_envelope end |
Instance Method Details
#body_parts ⇒ Object
Public: Returns the input body parts used to build the request body.
76 77 78 |
# File 'lib/sekken/operation.rb', line 76 def body_parts @operation.input.body_parts.inject([]) { |memo, part| memo + part.to_a } end |
#build ⇒ Object
Public: Build the request XML for this operation.
81 82 83 |
# File 'lib/sekken/operation.rb', line 81 def build @build ||= Envelope.new(@operation, header, body).to_s end |
#call ⇒ Object
Public: Call the operation.
89 90 91 92 93 94 |
# File 'lib/sekken/operation.rb', line 89 def call = (xml_envelope != nil ? xml_envelope : build) raw_response = @http.post(endpoint, http_headers, ) Response.new(raw_response) end |
#example_body ⇒ Object
Public: Create an example request body Hash.
71 72 73 |
# File 'lib/sekken/operation.rb', line 71 def example_body ExampleMessage.build(@operation.input.body_parts) end |
#example_header ⇒ Object
Public: Create an example request header Hash.
63 64 65 |
# File 'lib/sekken/operation.rb', line 63 def example_header ExampleMessage.build(@operation.input.header_parts) end |
#input_style ⇒ Object
Public: Returns the input style for this operation.
97 98 99 |
# File 'lib/sekken/operation.rb', line 97 def input_style @input_style ||= @operation.input_style end |
#output_style ⇒ Object
Public: Returns the output style for this operation.
102 103 104 |
# File 'lib/sekken/operation.rb', line 102 def output_style @output_style ||= @operation.output_style end |