Class: Invocable Abstract

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

Overview

This class is abstract.

Base class for invocable service calls.

Direct Known Subclasses

List, RetrieveServiceContent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, client) ⇒ Invocable

Constructs a new instance.

Parameters:

  • operation (Symbol)

    the operation name

  • client (Savon::Client)

    the client



204
205
206
207
# File 'lib/lookup_service_helper.rb', line 204

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



199
200
201
# File 'lib/lookup_service_helper.rb', line 199

def client
  @client
end

#operationObject (readonly)

Returns the value of attribute operation.



199
200
201
# File 'lib/lookup_service_helper.rb', line 199

def operation
  @operation
end

#responseObject (readonly)

Returns the value of attribute response.



199
200
201
# File 'lib/lookup_service_helper.rb', line 199

def response
  @response
end

Instance Method Details

#body_xmlObject

Builds the body portion of the request XML content. Specific service operations must override this method.



234
235
236
# File 'lib/lookup_service_helper.rb', line 234

def body_xml
    raise 'abstract method not implemented!'
end

#invokeObject

Invokes the service call represented by this type.



210
211
212
213
214
215
216
# File 'lib/lookup_service_helper.rb', line 210

def invoke
    request = request_xml.to_s
    Base.log.debug(request)
    @response = client.call(operation, xml:request)
    Base.log.debug(response)
    self # for chaining with new
end

#request_xmlObject

Builds the request XML content.



219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/lookup_service_helper.rb', line 219

def request_xml
    builder = Builder::XmlMarkup.new()
    builder.instruct!(:xml, encoding: "UTF-8")

    builder.tag!("S:Envelope",
                 "xmlns:S" => "http://schemas.xmlsoap.org/soap/envelope/") do |envelope|
        envelope.tag!("S:Body") do |body|
            body_xml(body)
        end
    end
    builder.target!
end

#response_hashObject



244
245
246
# File 'lib/lookup_service_helper.rb', line 244

def response_hash
    @response_hash ||= response.to_hash
end

#response_xmlObject

Gets the response XML content.



239
240
241
242
# File 'lib/lookup_service_helper.rb', line 239

def response_xml
    raise 'illegal state: response not set yet' if response.nil?
    @response_xml ||= Nokogiri::XML(response.to_xml)
end