Class: LSQS::XMLTemplate
- Inherits:
-
Object
- Object
- LSQS::XMLTemplate
- Defined in:
- lib/lsqs/xml_template.rb
Constant Summary collapse
- TEMPLATE_DIR =
File.('../../../config', __FILE__)
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize ⇒ XMLTemplate
constructor
A new instance of XMLTemplate.
-
#render(action) ⇒ String
Renders the XML that is required as a body response.
-
#render_error(error) ⇒ String
Renders the XML that is required for an error response.
-
#request_id ⇒ String
Generates a request ID.
Constructor Details
#initialize ⇒ XMLTemplate
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
#template ⇒ Object (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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/lsqs/xml_template.rb', line 19 def render(action) = { 'action' => action.name, 'content' => action.to_xml, 'request_id' => request_id } template.render() end |
#render_error(error) ⇒ String
Renders the XML that is required for an error response
36 37 38 39 40 41 42 43 |
# File 'lib/lsqs/xml_template.rb', line 36 def render_error(error) = { 'error' => error, 'request_id' => request_id } template.render() end |
#request_id ⇒ String
Generates a request ID.
50 51 52 |
# File 'lib/lsqs/xml_template.rb', line 50 def request_id SecureRandom.uuid end |