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



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

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#operationObject (readonly)

Returns the value of attribute operation.



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

def operation
  @operation
end

#responseObject (readonly)

Returns the value of attribute response.



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

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.



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

def body_xml
  raise "abstract method not implemented!"
end

#invokeObject

Invokes the service call represented by this type.



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

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.



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

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



246
247
248
# File 'lib/lookup_service_helper.rb', line 246

def response_hash
  @response_hash ||= response.to_hash
end

#response_xmlObject

Gets the response XML content.



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

def response_xml
  raise "illegal state: response not set yet" if response.nil?

  @response_xml ||= Nokogiri::XML(response.to_xml)
end