From 32644c0ac9b9d738db8487eaaafefeb3f1a667d4 Mon Sep 17 00:00:00 2001 From: Paolo Oliveira Date: Wed, 17 Jul 2024 13:25:56 -0300 Subject: [PATCH] #10532 add GetNTP --- lib/devices/get_ntp.ex | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/devices/get_ntp.ex diff --git a/lib/devices/get_ntp.ex b/lib/devices/get_ntp.ex new file mode 100644 index 0000000..baee9eb --- /dev/null +++ b/lib/devices/get_ntp.ex @@ -0,0 +1,31 @@ +defmodule Onvif.Devices.GetNTP do + import SweetXml + import XmlBuilder + + alias Onvif.Device + + def soap_action, do: "http://www.onvif.org/ver10/device/wsdl/GetNTP" + + @spec request(Device.t()) :: {:ok, any} | {:error, map()} + def request(device) do + Onvif.Devices.request(device, __MODULE__) + end + + def request_body do + element(:"s:Body", [element(:"tds:GetNTP")]) + end + + def response(xml_response_body) do + xml_response_body + |> parse(namespace_conformant: true, quiet: true) + |> xpath( + ~x"//s:Envelope/s:Body/tds:GetNTPResponse/tds:NTPInformation"e + |> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope") + |> add_namespace("tds", "http://www.onvif.org/ver10/device/wsdl") + |> add_namespace("tt", "http://www.onvif.org/ver10/schema") + ) + |> Onvif.Devices.NTP.parse() + |> Onvif.Devices.NTP.to_struct() + end + +end