Class: SSO::SoapInvocable Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sso.rb

Overview

This class is abstract.

Base class for invocable service calls.

Direct Known Subclasses

RequestSecurityToken

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, client) ⇒ SoapInvocable

Constructs a new instance.

Parameters:

  • operation (Symbol)

    the SOAP operation name (in Symbol form)

  • client (Savon::Client)

    the client



82
83
84
85
# File 'lib/sso.rb', line 82

def initialize(operation, client)
  @operation = operation
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



77
78
79
# File 'lib/sso.rb', line 77

def client
  @client
end

#operationObject (readonly)

Returns the value of attribute operation.



77
78
79
# File 'lib/sso.rb', line 77

def operation
  @operation
end

#responseObject (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

Returns:

  • (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

#invokeObject

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_xmlObject

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_hashObject



137
138
139
# File 'lib/sso.rb', line 137

def response_hash
  @response_hash ||= response.to_hash
end

#response_xmlObject

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