Class: Amsi::Utils::RequestGenerator
- Inherits:
-
Object
- Object
- Amsi::Utils::RequestGenerator
- 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
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#body ⇒ String
The XML request for the specified action and sections.
- #headers ⇒ Object
-
#initialize(url:, soap_action:, sections:) ⇒ RequestGenerator
constructor
A new instance of RequestGenerator.
Constructor Details
#initialize(url:, soap_action:, sections:) ⇒ RequestGenerator
Returns a new instance of RequestGenerator.
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
#url ⇒ Object (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
#body ⇒ String
Returns 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 |
#headers ⇒ Object
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 |