Class: Eet::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/eet/message.rb

Constant Summary collapse

SOAP_ENV_SCHEMA =
"http://schemas.xmlsoap.org/soap/envelope/"
WSSE_SCHEMA =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
WSU_SCHEMA =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
WSU_ID =
'artificial_id'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = { already_issued: false, first_send: true }) ⇒ Message

Returns a new instance of Message.



15
16
17
18
# File 'lib/eet/message.rb', line 15

def initialize(data, options = { already_issued: false, first_send: true })
  @data = data
  @options = options
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



13
14
15
# File 'lib/eet/message.rb', line 13

def data
  @data
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/eet/message.rb', line 13

def options
  @options
end

Instance Method Details

#bodyObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eet/message.rb', line 20

def body
  Nokogiri::XML::Builder.new('encoding' => 'UTF-8') do |xml|
    xml.Trzba(xmlns: 'http://fs.mfcr.cz/eet/schema/v3') do
      xml.Hlavicka(dat_odesl: data[:timestamp], prvni_zaslani: @options[:first_send], uuid_zpravy: SecureRandom.uuid)

      xml.Data(data[:data])

      xml.KontrolniKody do
        xml.pkp(cipher: 'RSA2048', digest: 'SHA256', encoding: 'base64') do
          xml.text(data[:pkp])
        end

        xml.bkp(digest: 'SHA1', encoding: 'base16') do
          xml.text(data[:bkp])
        end
      end
    end
  end.doc
end

#envelopeObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/eet/message.rb', line 40

def envelope
  Nokogiri::XML::Builder.new('encoding' => 'UTF-8') do |xml|
    xml['soap'].Envelope('xmlns:soap' => "http://schemas.xmlsoap.org/soap/envelope/") do
      xml['SOAP-ENV'].Header('xmlns:SOAP-ENV' => SOAP_ENV_SCHEMA) do
        xml['wsse'].Security('xmlns:wsse' => WSSE_SCHEMA, 'xmlns:wsu' => WSU_SCHEMA, 'soap:mustUnderstand' => '1')
      end

      xml['soap'].Body('xmlns:wsu' => WSU_SCHEMA, 'wsu:Id' => WSU_ID) do
      end
    end
  end.doc
end

#to_xmlObject



53
54
55
56
57
58
59
# File 'lib/eet/message.rb', line 53

def to_xml
  msg = envelope.dup
  body = msg.at_xpath('//soap:Body')
  body.add_child(self.body.root)

  msg
end