Class: ONVIF::DeviceManagementAction::GetSystemDateAndTime

Inherits:
Action
  • Object
show all
Defined in:
lib/ruby_onvif_client/device_management/get_system_date_and_time.rb

Instance Method Summary collapse

Methods inherited from Action

#attribute, #callback, #create_event_onvif_message, #create_media_onvif_message, #create_ptz_onvif_message, #initialize, #send_message, #value

Constructor Details

This class inherits a constructor from ONVIF::Action

Instance Method Details

#run(cb) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_onvif_client/device_management/get_system_date_and_time.rb', line 6

def run cb
    message = Message.new
    message.body =  ->(xml) do
        xml.wsdl(:GetSystemDateAndTime)
    end
    send_message message do |success, result|
        if success
            xml_doc = Nokogiri::XML(result[:content])
            xml_utc = xml_doc.xpath('//tt:UTCDateTime')
            xml_local = xml_doc.xpath('//tt:LocalDateTime')
            utc_data_time = {
                time: {
                    hour: value(xml_utc, '//tt:Hour'),
                    minute: value(xml_utc, '//tt:Minute'),
                    second: value(xml_utc, '//tt:Second')
                },
                date: {
                    year: value(xml_utc, '//tt:Year'),
                    month: value(xml_utc, '//tt:Month'),
                    day: value(xml_utc, '//tt:Day')
                }
            }
            local_date_time = {
                time: {
                    hour: value(xml_local, '//tt:Hour'),
                    minute: value(xml_local, '//tt:Minute'),
                    second: value(xml_local, '//tt:Second')
                },
                date: {
                    year: value(xml_local, '//tt:Year'),
                    month: value(xml_local, '//tt:Month'),
                    day: value(xml_local, '//tt:Day')
                }
            }
            date_time = {
                date_time_type: value(xml_doc, '//tt:DateTimeType'),
                daylight_savings: value(xml_doc, '//tt:DaylightSavings'),
                time_zone: {
                    tz: value(xml_doc, '//tt:TZ'),
                },
                extension: value(xml_doc, '//tt:Extension')
            }
            xml_utc_time = xml_doc.at_xpath('//tt:UTCDateTime')
            xml_local_time = xml_doc.at_xpath('//tt:LocalDateTime')
            date_time[:utc_date_time] = utc_data_time unless xml_utc_time.nil?
            date_time[:local_date_time] = local_date_time unl unless xml_local_time.nil?
            callback cb, success, date_time
        else
            callback cb, success, result
        end
    end
end