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.
82 83 84 85 |
# File 'lib/sso.rb', line 82 def initialize(operation, client) @operation = operation @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
77 78 79 |
# File 'lib/sso.rb', line 77 def client @client end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
77 78 79 |
# File 'lib/sso.rb', line 77 def operation @operation end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
77 78 79 |
# File 'lib/sso.rb', line 77 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.
126 127 128 |
# File 'lib/sso.rb', line 126 def body_xml(_body) raise "abstract method not implemented!" end |
#has_header? ⇒ Boolean
114 115 116 |
# File 'lib/sso.rb', line 114 def has_header? true end |
#header_xml(_header) ⇒ Object
Builds the header portion of the SOAP request. Specific service operations must override this method.
120 121 122 |
# File 'lib/sso.rb', line 120 def header_xml(_header) raise "abstract method not implemented!" end |
#invoke ⇒ Object
Invokes the service call represented by this type.
88 89 90 91 92 93 94 |
# File 'lib/sso.rb', line 88 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sso.rb', line 97 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
137 138 139 |
# File 'lib/sso.rb', line 137 def response_hash @response_hash ||= response.to_hash end |
#response_xml ⇒ Object
Gets the response XML content.
131 132 133 134 135 |
# File 'lib/sso.rb', line 131 def response_xml raise "illegal state: response not set yet" if response.nil? @response_xml ||= Nokogiri::XML(response.to_xml) end |