Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetRecordingSummary #96

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/device.ex
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,4 @@ defmodule Onvif.Device do
%Onvif.Device.Service{} = service -> service.xaddr |> URI.parse() |> Map.get(:path)
end
end


end
3 changes: 2 additions & 1 deletion lib/recording/create_recording.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ defmodule Onvif.Recording.CreateRecording do

def gen_maximum_retention_time(nil), do: []
def gen_maximum_retention_time(""), do: []
def gen_maximum_retention_time(maximum_retention_time), do: element(:"tt:MaximumRetentionTime", maximum_retention_time)

def gen_maximum_retention_time(maximum_retention_time),
do: element(:"tt:MaximumRetentionTime", maximum_retention_time)

def response(xml_response_body) do
recording_token =
Expand Down
1 change: 1 addition & 0 deletions lib/recording/create_recording_job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule Onvif.Recording.CreateRecordingJob do
|> add_namespace("trc", "http://www.onvif.org/ver10/recording/wsdl")
|> add_namespace("tt", "http://www.onvif.org/ver10/schema")
)

{:ok, parsed_result}
end
end
39 changes: 39 additions & 0 deletions lib/search/find_events.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule Onvif.Search.FindEvents do
import SweetXml
import XmlBuilder
require Logger

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

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

def request_body([included_recordings, start_point, end_point, search_filter, keep_alive_time]) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are treating the parameters differently in a few contexts, so I will pass through and make adjustments to the contracts before releasing

element(:"s:Body", [
element(:"tse:FindEvents", [
element(:"tse:StartPoint", start_point),
element(:"tse:EndPoint", end_point),
element(:"tse:scope", [
Enum.map(included_recordings, fn ir -> element(:"tt:IncludedRecordings", [ir]) end)
]),
element(:"tt:SearchFilter", [search_filter]),
element(:"tse:IncludeStartState", false),
element(:"tse:KeepAliveTime", keep_alive_time)
])
])
end

def response(xml_response_body) do
parsed_result =
xml_response_body
|> parse(namespace_conformant: true, quiet: true)
|> xpath(
~x"//tse:SearchToken/text()"s
|> add_namespace("s", "http://www.w3.org/2003/05/soap-envelope")
|> add_namespace("tse", "http://www.onvif.org/ver10/search/wsdl")
)

{:ok, parsed_result}
end
end
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
7 changes: 6 additions & 1 deletion test/recording/create_recording_job_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ defmodule Onvif.Recording.CreateRecordingJobTest do
{:ok, %{status: 200, body: xml_response}}
end)

{:ok, response} = Onvif.Recording.CreateRecordingJob.request(device, ["SD_DISK_20241120_211729_9C896594", "9", "Active"])
{:ok, response} =
Onvif.Recording.CreateRecordingJob.request(device, [
"SD_DISK_20241120_211729_9C896594",
"9",
"Active"
])

assert response == "SD_DISK_20241120_211729_9C896594"
end
Expand Down
12 changes: 7 additions & 5 deletions test/recording/create_recording_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ defmodule Onvif.Recording.CreateRecordingTest do
{:ok, %{status: 200, body: xml_response}}
end)

{:ok, response_uri} = Onvif.Recording.CreateRecording.request(
device,
config: %Onvif.Recording.Recording.Configuration{
{:ok, response_uri} =
Onvif.Recording.CreateRecording.request(
device,
config: %Onvif.Recording.Recording.Configuration{
content: "test",
maximum_retention_time: "PT1H",
source: %Onvif.Recording.Recording.Configuration.Source{
name: "test",
name: "test"
}
})
}
)

assert response_uri == "SD_DISK_20200422_123501_A2388AB3"
end
Expand Down
28 changes: 28 additions & 0 deletions test/search/find_events_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Onvif.Search.FindEventsTest do
use ExUnit.Case, async: true

@moduletag capture_log: true

describe "FindEvents/2" do
test "get an event search token" do
xml_response = File.read!("test/search/fixtures/find_events__success.xml")

device = Onvif.Factory.device()

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

{:ok, response} =
Onvif.Search.FindEvents.request(device, [
["Record_004"],
"2024-12-06T19:00:00.0Z",
"2024-12-06T19:02:00.0Z",
"tns1:RecordingHistory/Track/State",
"PT1M"
])

assert response == "SearchToken[1]"
end
end
end
53 changes: 53 additions & 0 deletions test/search/fixtures/find_events__success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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:FindEventsResponse>
<tse:SearchToken>SearchToken[1]</tse:SearchToken>
</tse:FindEventsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
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
Loading