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



85
86
87
88
# File 'lib/sso.rb', line 85

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



80
81
82
# File 'lib/sso.rb', line 80

def client
  @client
end

#operationObject (readonly)

Returns the value of attribute operation.



80
81
82
# File 'lib/sso.rb', line 80

def operation
  @operation
end

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

Returns:

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

#invokeObject

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_xmlObject

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_hashObject



139
140
141
# File 'lib/sso.rb', line 139

def response_hash
    @response_hash ||= response.to_hash
end

#response_xmlObject

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