Class: Betfair::SOAPRenderer

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(service, soap_name) ⇒ SOAPRenderer

Returns a new instance of SOAPRenderer.

Parameters:

  • service, (String)

    one of ‘exchange’ or ‘global’

  • soap_name (String)

    name of the soap request to render



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.

Parameters:

  • content (Hash)

    hash of values to include in XML request

Returns:

  • (String)

    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