Class: SSO::SoapInvocable Abstract
- Inherits:
-
Object
- Object
- SSO::SoapInvocable
- Defined in:
- lib/sso.rb
Overview
Base class for invocable service calls.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#body_xml(body) ⇒ Object
Builds the body portion of the SOAP request.
- #has_header? ⇒ Boolean
-
#header_xml(header) ⇒ Object
Builds the header portion of the SOAP request.
-
#initialize(operation, client) ⇒ SoapInvocable
constructor
Constructs a new instance.
-
#invoke ⇒ Object
Invokes the service call represented by this type.
-
#request_xml ⇒ Object
Builds the request XML content.
- #response_hash ⇒ Object
-
#response_xml ⇒ Object
Gets the response XML content.
Constructor Details
#initialize(operation, client) ⇒ SoapInvocable
Constructs a new instance.
85 86 87 88 |
# File 'lib/sso.rb', line 85 def initialize(operation, client) @operation = operation @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
80 81 82 |
# File 'lib/sso.rb', line 80 def client @client end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
80 81 82 |
# File 'lib/sso.rb', line 80 def operation @operation end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
80 81 82 |
# File 'lib/sso.rb', line 80 def response @response end |
Instance Method Details
#body_xml(body) ⇒ Object
Builds the body portion of the SOAP request. Specific service operations must override this method.
129 130 131 |
# File 'lib/sso.rb', line 129 def body_xml(body) raise 'abstract method not implemented!' end |
#has_header? ⇒ Boolean
117 118 119 |
# File 'lib/sso.rb', line 117 def has_header? true end |
#header_xml(header) ⇒ Object
Builds the header portion of the SOAP request. Specific service operations must override this method.
123 124 125 |
# File 'lib/sso.rb', line 123 def header_xml(header) raise 'abstract method not implemented!' end |
#invoke ⇒ Object
Invokes the service call represented by this type.
91 92 93 94 95 96 97 |
# File 'lib/sso.rb', line 91 def invoke request = request_xml.to_s puts "request = #{request}" if ENV['DEBUG'] @response = client.call(operation, xml:request) puts "response = #{response}" if ENV['DEBUG'] self # for chaining with new end |
#request_xml ⇒ Object
Builds the request XML content.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sso.rb', line 100 def request_xml builder = Builder::XmlMarkup.new() builder.instruct!(:xml, encoding: "UTF-8") builder.tag!("S:Envelope", NAMESPACES) do |envelope| if has_header? envelope.tag!("S:Header") do |header| header_xml(header) end end envelope.tag!("S:Body") do |body| body_xml(body) end end builder.target! end |
#response_hash ⇒ Object
139 140 141 |
# File 'lib/sso.rb', line 139 def response_hash @response_hash ||= response.to_hash end |
#response_xml ⇒ Object
Gets the response XML content.
134 135 136 137 |
# File 'lib/sso.rb', line 134 def response_xml raise 'illegal state: response not set yet' if response.nil? @response_xml ||= Nokogiri::XML(response.to_xml) end |