Class: Amsi::Utils::RequestGenerator

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

Overview

Generate a SOAP request for a specific action and sections

Constant Summary collapse

ENVELOPE_ATTRIBUTES =
{
  'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
}.freeze
ACTION_ATTRIBUTES =
{
  'xmlns' => 'http://tempuri.org/'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, soap_action:, sections:) ⇒ RequestGenerator

Returns a new instance of RequestGenerator.

Parameters:

  • url: (String)

    the URL to POST to

  • soap_action: (String)

    the PascalCase action to request from AMSI.

  • sections: (Array<RequestSection>)

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



19
20
21
22
23
# File 'lib/amsi/utils/request_generator.rb', line 19

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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



47
48
49
# File 'lib/amsi/utils/request_generator.rb', line 47

def url
  @url
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



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/amsi/utils/request_generator.rb', line 33

def body
  Nokogiri::XML::Builder.new do |xml_builder|
    xml_builder['soap'].Envelope(ENVELOPE_ATTRIBUTES) do
      xml_builder['soap'].Body do
        xml_builder.send(soap_action, ACTION_ATTRIBUTES) do
          sections.each do |section|
            section.generate(xml_builder)
          end
        end
      end
    end
  end.to_xml
end

#headersObject



25
26
27
28
29
30
# File 'lib/amsi/utils/request_generator.rb', line 25

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