Class: ONVIF::Service

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

Direct Known Subclasses

DeviceManagement, Event, Media, Ptz

Instance Method Summary collapse

Constructor Details

#initialize(address, username = 'admin', password = 'admin') ⇒ Service

Returns a new instance of Service.



6
7
8
9
10
11
12
# File 'lib/ruby_onvif_client/service.rb', line 6

def initialize address, username = 'admin', password = 'admin'
    @client = ONVIF::Client.new(
        address: address
    )
    @username = username
    @password = password
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &blcok) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_onvif_client/service.rb', line 14

def method_missing(m, *args, &blcok)
    action_class = ONVIF.const_get(%Q{#{self.class.name}Action}).const_get(m.to_s.camelize) rescue nil
    unless action_class.nil?
        self.class.class_exec do
            define_method m do |*r|
                action_class.new(@client, @username, @password).run(*r)
            end
        end
        self.send m, *args
    else
        super
    end
end

Instance Method Details

#respond_to?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'lib/ruby_onvif_client/service.rb', line 28

def respond_to?(m, include_private = false)
    action_class = ONVIF.const_get(%Q{#{self.class.name}Action}).const_get(m.to_s.camelize) rescue nil
    unless action_class.nil?
        true
    else
        super
    end
end