Class: Betfair::SOAPRenderer
- Inherits:
-
Object
- Object
- Betfair::SOAPRenderer
- Defined in:
- lib/em-betfair/soap_renderer.rb
Overview
Utility class to render a SOAP request from a haml file, embedding data elements as necessary
Instance Method Summary collapse
-
#initialize(service, soap_name) ⇒ SOAPRenderer
constructor
A new instance of SOAPRenderer.
-
#render(content) ⇒ String
Xml request body.
Constructor Details
#initialize(service, soap_name) ⇒ SOAPRenderer
Returns a new instance of SOAPRenderer.
12 13 14 15 16 17 18 19 20 |
# File 'lib/em-betfair/soap_renderer.rb', line 12 def initialize service, soap_name base = Pathname.new(__FILE__).realpath.parent file = "#{base}/views/#{service}/#{soap_name}.haml" unless File.exists?( file ) $log.error "Cannot find HAML: #{file}" unless $log.nil? raise "Cannot find HAML: #{file}" end @engine = Haml::Engine.new( File.read( file ) ) # this is quite expensive, might be better to keep a hash of renderers end |
Instance Method Details
#render(content) ⇒ String
Returns xml request body.
24 25 26 27 28 29 |
# File 'lib/em-betfair/soap_renderer.rb', line 24 def render content content.each do |key,value| self.instance_variable_set( "@#{key}", value ) end @engine.render( self ) end |