Class: LSQS::XMLTemplate

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

Constant Summary collapse

TEMPLATE_DIR =
File.expand_path('../../../config', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXMLTemplate

Returns a new instance of XMLTemplate.



7
8
9
10
# File 'lib/lsqs/xml_template.rb', line 7

def initialize
  xml = File.read("#{TEMPLATE_DIR}/template.xml.liquid")
  @template = Liquid::Template.parse(xml)
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



3
4
5
# File 'lib/lsqs/xml_template.rb', line 3

def template
  @template
end

Instance Method Details

#render(action) ⇒ String

Renders the XML that is required as a body response.

Parameters:

Returns:

  • (String)


19
20
21
22
23
24
25
26
27
# File 'lib/lsqs/xml_template.rb', line 19

def render(action)
  options = { 
    'action'     => action.name,
    'content'    => action.to_xml,
    'request_id' => request_id
  }
  
  template.render(options)
end

#render_error(error) ⇒ String

Renders the XML that is required for an error response

Parameters:

  • error (String)

Returns:

  • (String)


36
37
38
39
40
41
42
43
# File 'lib/lsqs/xml_template.rb', line 36

def render_error(error)
  options = {
    'error'      => error,
    'request_id' => request_id
  }
  
  template.render(options)
end

#request_idString

Generates a request ID.

Returns:

  • (String)


50
51
52
# File 'lib/lsqs/xml_template.rb', line 50

def request_id
  SecureRandom.uuid
end