Sha256: b32400836d843437e98168215e427a51a160cb45a8d26a94314cf663f0f540f8

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

# frozen_string_literal: true

require 'builder'

module Arbetsformedlingen
  # SOAP Envelope XML builder
  class SOAPBuilder
    # SOAP attributes
    SOAP_ATTRIBUTES = {
      'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
      'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
      'xmlns:soap12' => 'http://www.w3.org/2003/05/soap-envelope',
    }.freeze

    # Wrap block
    # @see #wrap
    def self.wrap(&block)
      new.wrap(&block)
    end

    # Initialize object
    def initialize
      @builder = Builder::XmlMarkup.new(indent: 2)
      @builder.instruct!

      yield self if block_given?
    end

    # Wrap block in SOAP envelope
    # @return [SOAPBuilder]
    def wrap
      @builder.soap12(:Envelope, SOAP_ATTRIBUTES) do |envelope|
        envelope.soap12(:Body) { |body| yield(body) }
      end

      self
    end

    def to_xml
      @builder.target!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arbetsformedlingen-0.7.0 lib/arbetsformedlingen/soap_builder.rb