Skip to content

Commit

Permalink
add GetRecordingSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloo committed Dec 13, 2024
1 parent 7eb743a commit ffd72a2
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/search/get_recording_summary.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Onvif.Search.GetRecordingSummary do
import SweetXml
import XmlBuilder
require Logger

def soap_action, do: "http://www.onvif.org/ver10/search/wsdl/GetRecordingSummary"

def request(device) do
Onvif.Search.request(device, __MODULE__)
end

def request_body() do
element(:"s:Body", [
element(:"tse:GetRecordingSummary")
])
end

def response(xml_response_body) do
doc = parse(xml_response_body, namespace_conformant: true, quiet: true)

parsed_result =
xpath(
doc,
~x"//s:Envelope/s:Body/tse:GetRecordingSummaryResponse/tse:Summary"
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope")
|> add_namespace("tse", "http://www.onvif.org/ver10/search/wsdl")
|> add_namespace("tt", "http://www.onvif.org/ver10/schema"),
data_from: ~x"//tt:DataFrom/text()"so,
data_until: ~x"//tt:DataUntil/text()"so,
number_recordings: ~x"//tt:NumberRecordings/text()"so
)

{:ok, parsed_result}
end
end
57 changes: 57 additions & 0 deletions test/search/fixtures/get_recording_summary__success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/tns.xsd"
xmlns:tns1="http://www.onvif.org/ver10/topics"
xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsa5="http://www.w3.org/2005/08/addressing"
xmlns:xmime5="http://tempuri.org/xmime5.xsd"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:tplt="http://www.onvif.org/ver10/plus/schema"
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2"
xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:tanae="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding"
xmlns:tanre="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding"
xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"
xmlns:tds="http://www.onvif.org/ver10/device/wsdl"
xmlns:tes-cppb="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding"
xmlns:tes-e="http://www.onvif.org/ver10/events/wsdl/EventBinding"
xmlns:tes-nc="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding"
xmlns:tes-np="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"
xmlns:tes-ppb="http://www.onvif.org/ver10/events/wsdl/PullPointBinding"
xmlns:tes-pps="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"
xmlns:tev="http://www.onvif.org/ver10/events/wsdl"
xmlns:tes-psmb="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding"
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
xmlns:tes-sm="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"
xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"
xmlns:tpl="http://www.onvif.org/ver10/plus/wsdl"
xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:tr2="http://www.onvif.org/ver20/media/wsdl"
xmlns:trc="http://www.onvif.org/ver10/recording/wsdl"
xmlns:trp="http://www.onvif.org/ver10/replay/wsdl"
xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl"
xmlns:tse="http://www.onvif.org/ver10/search/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<tse:GetRecordingSummaryResponse>
<tse:Summary>
<tt:DataFrom>1970-01-01T00:00:00Z</tt:DataFrom>
<tt:DataUntil>2024-12-13T08:08:49Z</tt:DataUntil>
<tt:NumberRecordings>8</tt:NumberRecordings>
</tse:Summary>
</tse:GetRecordingSummaryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
25 changes: 25 additions & 0 deletions test/search/get_recording_summary_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Onvif.Search.GetRecordingSummaryTest do
use ExUnit.Case, async: true

@moduletag capture_log: true

describe "GetRecordingSummary/0" do
test "get an event search token" do
xml_response = File.read!("test/search/fixtures/get_recording_summary__success.xml")

device = Onvif.Factory.device()

Mimic.expect(Tesla, :request, fn _client, _opts ->
{:ok, %{status: 200, body: xml_response}}
end)

{:ok, response} =
Onvif.Search.GetRecordingSummary.request(device)

assert response == %{
data_from: "1970-01-01T00:00:00Z",
data_until: "2024-12-13T08:08:49Z",
number_recordings: "8"}
end
end
end

0 comments on commit ffd72a2

Please sign in to comment.