Class: Sekken::Operation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#bodyObject

Public: Sets the request body Hash.



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

def body
  @body
end

#encodingObject

Public: Accessor for the encoding. Defaults to 'UTF-8'.



36
37
38
# File 'lib/sekken/operation.rb', line 36

def encoding
  @encoding
end

#endpointObject

Public: Accessor for the SOAP endpoint.



27
28
29
# File 'lib/sekken/operation.rb', line 27

def endpoint
  @endpoint
end

#headerObject

Public: Sets the request header Hash.



60
61
62
# File 'lib/sekken/operation.rb', line 60

def header
  @header
end

#http_headersObject

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_actionObject

Public: Accessor for the SOAPAction HTTP header.



33
34
35
# File 'lib/sekken/operation.rb', line 33

def soap_action
  @soap_action
end

#soap_versionObject

Public: Accessor for the SOAP version.



30
31
32
# File 'lib/sekken/operation.rb', line 30

def soap_version
  @soap_version
end

#xml_envelopeObject

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_partsObject

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

#buildObject

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

#callObject

Public: Call the operation.



89
90
91
92
93
94
# File 'lib/sekken/operation.rb', line 89

def call
  message = (xml_envelope != nil ? xml_envelope : build)

  raw_response = @http.post(endpoint, http_headers, message)
  Response.new(raw_response)
end

#example_bodyObject

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_headerObject

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_styleObject

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_styleObject

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