Skip to content

Commit a28e2f6

Browse files
authored
Allow providing only profile token in get video encoder configuration (#104)
1 parent 1c54a11 commit a28e2f6

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

lib/media/ver20/get_video_encoder_configurations.ex

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,12 @@ defmodule Onvif.Media.Ver20.GetVideoEncoderConfigurations do
1414
def request(device, args \\ []),
1515
do: Onvif.Media.Ver20.Media.request(device, args, __MODULE__)
1616

17-
def request_body() do
18-
element(:"s:Body", [
19-
element(:"tr2:GetVideoEncoderConfigurations")
20-
])
21-
end
22-
23-
def request_body(configuration_token) do
24-
element(:"s:Body", [
25-
element(:"tr2:GetVideoEncoderConfigurations", [
26-
element(:"tr2:ConfigurationToken", configuration_token)
27-
])
28-
])
29-
end
17+
def request_body(configuration_token \\ nil, profile_token \\ nil) do
18+
config =
19+
with_configuration_token([], configuration_token) |> with_profile_token(profile_token)
3020

31-
def request_body(configuration_token, profile_token) do
3221
element(:"s:Body", [
33-
element(:"tr2:GetVideoEncoderConfigurations", [
34-
element(:"tr2:ConfigurationToken", configuration_token),
35-
element(:"tr2:ProfileToken", profile_token)
36-
])
22+
element(:"tr2:GetVideoEncoderConfigurations", config)
3723
])
3824
end
3925

@@ -62,4 +48,16 @@ defmodule Onvif.Media.Ver20.GetVideoEncoderConfigurations do
6248

6349
{:ok, response}
6450
end
51+
52+
defp with_configuration_token(config, nil), do: config
53+
54+
defp with_configuration_token(config, configuration_token) do
55+
[element(:"tr2:ConfigurationToken", configuration_token) | config]
56+
end
57+
58+
defp with_profile_token(config, nil), do: config
59+
60+
defp with_profile_token(config, profile_token) do
61+
[element(:"tr2:ProfileToken", profile_token) | config]
62+
end
6563
end

test/devices/get_network_protocols_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ defmodule Onvif.Devices.GetNetworkProtocolsTest do
2525
end
2626

2727
test "should return error when response is invalid" do
28-
xml_response = File.read!("test/devices/fixtures/invalid_get_network_protocols_response.xml")
28+
xml_response =
29+
File.read!("test/devices/fixtures/invalid_get_network_protocols_response.xml")
30+
2931
device = Onvif.Factory.device()
3032

3133
Mimic.expect(Tesla, :request, fn _client, _opts ->

test/search/get_recording_summary_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ defmodule Onvif.Search.GetRecordingSummaryTest do
1313
{:ok, %{status: 200, body: xml_response}}
1414
end)
1515

16-
{:ok, response} =
17-
Onvif.Search.GetRecordingSummary.request(device)
16+
{:ok, response} = Onvif.Search.GetRecordingSummary.request(device)
1817

1918
assert response == %{
20-
data_from: "1970-01-01T00:00:00Z",
21-
data_until: "2024-12-13T08:08:49Z",
22-
number_recordings: "8"}
19+
data_from: "1970-01-01T00:00:00Z",
20+
data_until: "2024-12-13T08:08:49Z",
21+
number_recordings: "8"
22+
}
2323
end
2424
end
2525
end

0 commit comments

Comments
 (0)