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'
BEZNY_REZIM =
0
DATE_FORMAT =
'%FT%T%:z'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Message

Returns a new instance of Message.



21
22
23
24
25
# File 'lib/eet/message.rb', line 21

def initialize(attributes = {})
  attributes.each do |k, v|
    public_send("#{k}=", v)
  end
end

Instance Attribute Details

#bkpObject

Returns the value of attribute bkp.



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

def bkp
  @bkp
end

#celk_trzbaObject

Returns the value of attribute celk_trzba.



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

def celk_trzba
  @celk_trzba
end

#cerp_zuctObject

Returns the value of attribute cerp_zuct.



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

def cerp_zuct
  @cerp_zuct
end

#cest_sluzObject

Returns the value of attribute cest_sluz.



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

def cest_sluz
  @cest_sluz
end

#dan1Object

Returns the value of attribute dan1.



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

def dan1
  @dan1
end

#dan2Object

Returns the value of attribute dan2.



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

def dan2
  @dan2
end

#dan3Object

Returns the value of attribute dan3.



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

def dan3
  @dan3
end

#dat_odeslObject



72
73
74
# File 'lib/eet/message.rb', line 72

def dat_odesl
  @dat_odesl ||= Time.now.strftime(DATE_FORMAT)
end

#dat_trzbyObject

Returns the value of attribute dat_trzby.



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

def dat_trzby
  @dat_trzby
end

#dic_poplObject

Returns the value of attribute dic_popl.



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

def dic_popl
  @dic_popl
end

#dic_poverujicihoObject

Returns the value of attribute dic_poverujiciho.



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

def dic_poverujiciho
  @dic_poverujiciho
end

#id_poklObject

Returns the value of attribute id_pokl.



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

def id_pokl
  @id_pokl
end

#id_provozObject

Returns the value of attribute id_provoz.



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

def id_provoz
  @id_provoz
end

#overeniObject

Returns the value of attribute overeni.



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

def overeni
  @overeni
end

#pkpObject

Returns the value of attribute pkp.



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

def pkp
  @pkp
end

#porad_cisObject

Returns the value of attribute porad_cis.



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

def porad_cis
  @porad_cis
end

#pouzit_zboz1Object

Returns the value of attribute pouzit_zboz1.



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

def pouzit_zboz1
  @pouzit_zboz1
end

#pouzit_zboz2Object

Returns the value of attribute pouzit_zboz2.



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

def pouzit_zboz2
  @pouzit_zboz2
end

#pouzit_zboz3Object

Returns the value of attribute pouzit_zboz3.



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

def pouzit_zboz3
  @pouzit_zboz3
end

#prvni_zaslaniObject



76
77
78
# File 'lib/eet/message.rb', line 76

def prvni_zaslani
  @prvni_zaslani.nil? ? true : @prvni_zaslani
end

#rezimObject



80
81
82
# File 'lib/eet/message.rb', line 80

def rezim
  @rezim ||= BEZNY_REZIM
end

#urceno_cerp_zuctObject

Returns the value of attribute urceno_cerp_zuct.



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

def urceno_cerp_zuct
  @urceno_cerp_zuct
end

#uuid_zpravyObject



68
69
70
# File 'lib/eet/message.rb', line 68

def uuid_zpravy
  @uuid_zpravy ||= SecureRandom.uuid
end

#zakl_dan1Object

Returns the value of attribute zakl_dan1.



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

def zakl_dan1
  @zakl_dan1
end

#zakl_dan2Object

Returns the value of attribute zakl_dan2.



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

def zakl_dan2
  @zakl_dan2
end

#zakl_dan3Object

Returns the value of attribute zakl_dan3.



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

def zakl_dan3
  @zakl_dan3
end

#zakl_nepodl_dphObject

Returns the value of attribute zakl_nepodl_dph.



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

def zakl_nepodl_dph
  @zakl_nepodl_dph
end

Instance Method Details

#bodyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eet/message.rb', line 27

def body
  Nokogiri::XML::Builder.new('encoding' => 'UTF-8') do |xml|
    xml.Trzba(xmlns: 'http://fs.mfcr.cz/eet/schema/v3') do
      xml.Hlavicka(head_attributes)

      xml.Data(data_attributes)

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

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

#data_attributesObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/eet/message.rb', line 96

def data_attributes
  { dic_popl: dic_popl,
    dic_poverujiciho: dic_poverujiciho,
    id_provoz: id_provoz,
    id_pokl: id_pokl,
    porad_cis: porad_cis,
    dat_trzby: dat_trzby,
    celk_trzba: celk_trzba,
    zakl_nepodl_dph: zakl_nepodl_dph,
    zakl_dan1: zakl_dan1,
    dan1: dan1,
    zakl_dan2: zakl_dan2,
    dan2: dan2,
    zakl_dan3: zakl_dan3,
    dan3: dan3,
    cest_sluz: cest_sluz,
    pouzit_zboz1: pouzit_zboz1,
    pouzit_zboz2: pouzit_zboz2,
    pouzit_zboz3: pouzit_zboz3,
    urceno_cerp_zuct: urceno_cerp_zuct,
    cerp_zuct: cerp_zuct,
    rezim: rezim,
  }.reject { |_, v| v.nil? }
end

#envelopeObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/eet/message.rb', line 47

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

#head_attributesObject



88
89
90
91
92
93
94
# File 'lib/eet/message.rb', line 88

def head_attributes
  { uuid_zpravy: uuid_zpravy,
    dat_odesl: dat_odesl,
    prvni_zaslani: prvni_zaslani,
    overeni: overeni
  }.reject { |_, v| v.nil? }
end

#to_xmlObject



60
61
62
63
64
65
66
# File 'lib/eet/message.rb', line 60

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

  msg
end