Class: ONVIF::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Message

Returns a new instance of Message.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby_onvif_client/message.rb', line 9

def initialize options = {}
    @options = {
        username: 'admin',
        password: 'admin',
        namespaces: {}
    }.merge(options)

    @namespaces = {
        :'xmlns:soap' => "http://www.w3.org/2003/05/soap-envelope",
        :'xmlns:wsdl' => "http://www.onvif.org/ver10/device/wsdl"
    }.merge(@options[:namespaces])
end

Instance Attribute Details

#body=(value) ⇒ Object (writeonly)

Sets the attribute body

Parameters:

  • value

    the value to set the attribute body to.



7
8
9
# File 'lib/ruby_onvif_client/message.rb', line 7

def body=(value)
  @body = value
end

Instance Method Details

#headerObject



22
23
24
25
26
27
# File 'lib/ruby_onvif_client/message.rb', line 22

def header
    wsse = Akami.wsse
    wsse.credentials(@options[:username], @options[:password])
    wsse.created_at = Time.now
    wsse.to_xml
end

#to_sObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_onvif_client/message.rb', line 29

def to_s
    Builder::XmlMarkup.new(indent: 4).soap(:Envelope, @namespaces) do |xml|
        xml.soap(:Header) do
            xml << header
        end
        xml.soap(:Body) do
            @body.call(xml) if @body.class == Proc
        end
    end
end