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.



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

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])
    self.username = @options[:username]
    self.password = @options[:password]
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

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#headerObject



25
26
27
28
29
30
31
# File 'lib/ruby_onvif_client/message.rb', line 25

def header
    wsse = Akami.wsse
    wsse.credentials(username, password)
    wsse.created_at = Time.now
    wsse.to_xml
    %Q{<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-31"><wsse:Username>#{username}</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">#{password}</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">vwqgTTRK/D2IeOTP76JHBw==</wsse:Nonce><wsu:Created>2013-08-06T10:22:17.028Z</wsu:Created></wsse:UsernameToken></wsse:Security>}
end

#to_sObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_onvif_client/message.rb', line 33

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