class XmlBuilder
Constants
- SPECIAL_CHARACTER_MAP
Attributes
request[R]
Public Class Methods
new(request, attrs={})
click to toggle source
Calls superclass method
# File lib/royal_mail_api/xml_builder.rb, line 15 def initialize(request, attrs={}) @request = request attrs = attrs.reduce({}) do |hash,(k,v)| hash[k]=parse_special_characters(v); hash end super attrs end
Public Instance Methods
build()
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 25 def build envelope end
Private Instance Methods
body()
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 44 def body build_xml("#{request}.xml") end
build_xml(file)
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 35 def build_xml(file) path = File.join(xml_path << file) ERB.new(File.read(path)).result(binding) end
envelope()
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 48 def envelope build_xml('envelope.xml') end
header()
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 40 def header build_xml('security_header.xml') end
parse_special_characters(str)
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 52 def parse_special_characters(str) return str unless str.is_a? String str.gsub(/["&'<>]/, SPECIAL_CHARACTER_MAP) end
xml_path()
click to toggle source
# File lib/royal_mail_api/xml_builder.rb, line 31 def xml_path [RoyalMailApi.root, 'lib', 'xml'] end