Class: RealPage::Utils::RequestGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/real_page/utils/request_generator.rb

Overview

Generate a SOAP request for a specific action and sections

Constant Summary collapse

ENVELOPE =
{
  'xmlns:soapenv' => 'http://schemas.xmlsoap.org/soap/envelope/',
  'xmlns:tem' => 'http://tempuri.org/'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(soap_action, sections) ⇒ RequestGenerator

Returns a new instance of RequestGenerator.

Parameters:

  • soap_action (String)

    the action to request from RealPage.

  • sections (Array<RequestSection>)

    the section generators that will be used to generate the body of the XML request



17
18
19
20
# File 'lib/real_page/utils/request_generator.rb', line 17

def initialize(soap_action, sections)
  @soap_action = soap_action
  @sections = sections
end

Instance Method Details

#bodyString

Returns the XML request for the specified action and sections.

Returns:

  • (String)

    the XML request for the specified action and sections



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/real_page/utils/request_generator.rb', line 23

def body
  Nokogiri::XML::Builder.new do |xml_builder|
    xml_builder.Envelope(ENVELOPE) do
      namespace = xml_builder.parent.namespace_definitions.first
      xml_builder.parent.namespace = namespace
      xml_builder['soapenv'].Header
      xml_builder['soapenv'].Body do
        xml_builder['tem'].send(soap_action.downcase) do
          sections.each do |section|
            section.generate(xml_builder['tem'])
          end
        end
      end
    end
  end.to_xml
end

#headersObject



40
41
42
43
44
45
# File 'lib/real_page/utils/request_generator.rb', line 40

def headers
  {
    'Content-Type' => 'text/xml; charset=utf-8',
    'SOAPAction' => "http://tempuri.org/IRPXService/#{soap_action.downcase}"
  }
end