Class: ONVIF::Action

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

Instance Method Summary collapse

Constructor Details

#initialize(client, username, password) ⇒ Action

Returns a new instance of Action.



5
6
7
8
9
# File 'lib/ruby_onvif_client/action.rb', line 5

def initialize client, username, password
    @client = client
    @username = username
    @password = password
end

Instance Method Details

#attribute(xml_doc, xpath) ⇒ Object



29
30
31
32
33
# File 'lib/ruby_onvif_client/action.rb', line 29

def attribute xml_doc, xpath
    node = xml_doc[xpath]
    return node unless node.nil?
    ''
end

#callback(cb, *args) ⇒ Object



19
20
21
22
# File 'lib/ruby_onvif_client/action.rb', line 19

def callback cb, *args
    return if cb.class != Proc
    cb.call *args
end

#create_media_onvif_message(options = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ruby_onvif_client/action.rb', line 35

def create_media_onvif_message options = {}
    namespaces = {
        :'xmlns:wsdl' => "http://www.onvif.org/ver10/media/wsdl"
    }.merge(options[:namespaces] || {})
    options[:namespaces] = namespaces
    Message.new options
end

#create_ptz_onvif_message(options = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/ruby_onvif_client/action.rb', line 42

def create_ptz_onvif_message options = {}
    namespaces = {
        :'xmlns:wsdl' => "http://www.onvif.org/ver20/ptz/wsdl"
    }.merge(options[:namespaces] || {})
    options[:namespaces] = namespaces
    Message.new options
end

#send_message(message) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ruby_onvif_client/action.rb', line 11

def send_message message
    message.username = @username
    message.password = @password
    @client.send message.to_s do |success, result|
        yield success, result
    end
end

#value(xml_doc, xpath) ⇒ Object



24
25
26
27
28
# File 'lib/ruby_onvif_client/action.rb', line 24

def value xml_doc, xpath
    node = xml_doc.at_xpath(xpath)
    return node.content unless node.nil?
    ''
end