1
2
3
4
5
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! `DdnsApi`: `ddns` endpoints (`eero-api src/eero/api/ddns.py`, new in v8.0.0).
//!
//! Both operations are parameterless `PUT`s: the API declares no request body for either
//! endpoint, so neither method sends one — [`RequestBody::None`], mirroring Python's
//! `RequestEncoding.NONE`.
use std::sync::Arc;
use serde_json::Value;
use crate::envelope::Envelope;
use crate::error::Error;
use crate::links;
use crate::routes;
use crate::transport::{RequestBody, Transport};
/// `eero-api`'s `DdnsAPI` (`src/eero/api/ddns.py`, new in v8.0.0).
///
/// Build one with [`DdnsApi::new`], wrapping a [`Transport`] already shared with the rest of
/// the [`crate::api::EeroApi`] aggregator — `DdnsApi` never constructs or owns a `Transport`
/// itself.
#[derive(Debug)]
pub struct DdnsApi {
transport: Arc<Transport>,
}
impl DdnsApi {
/// Wraps `transport` as a `DdnsApi`.
#[must_use]
pub fn new(transport: Arc<Transport>) -> Self {
Self { transport }
}
/// Enables dynamic DNS for a network — returns the raw Eero API response.
///
/// Ported from `eero-api src/eero/api/ddns.py:40-79` (`DdnsAPI.enable`). Issues a `PUT` with
/// no request body to [`crate::routes::ddns::DDNS_ENABLE`], preferring `parent`'s published
/// `ddns_enable` link over the `networks/{id}/ddns/enable` template when supplied. Logs
/// [`crate::links::warn_uncharacterised_write`] (`"enable DDNS for network"`) immediately
/// before issuing the request.
///
/// # Errors
///
/// Returns [`Error::Authentication`] if no valid session is configured, or whatever
/// status-mapped [`Error`] the request produces otherwise.
pub async fn enable(
&self,
network_id: &str,
parent: Option<&Value>,
) -> Result<Envelope, Error> {
let url =
routes::ddns::DDNS_ENABLE.resolve(self.transport.api_host(), network_id, parent)?;
links::warn_uncharacterised_write("enable DDNS for network");
self.transport
.request(
routes::ddns::DDNS_ENABLE.method.clone(),
url,
&[],
RequestBody::None,
)
.await
}
/// Disables dynamic DNS for a network — returns the raw Eero API response.
///
/// Ported from `eero-api src/eero/api/ddns.py:82-120` (`DdnsAPI.disable`). Issues a `PUT`
/// with no request body to [`crate::routes::ddns::DDNS_DISABLE`], preferring `parent`'s
/// published `ddns_disable` link over the `networks/{id}/ddns/disable` template when
/// supplied. Logs [`crate::links::warn_uncharacterised_write`] (`"disable DDNS for
/// network"`) immediately before issuing the request.
///
/// # Errors
///
/// Returns [`Error::Authentication`] if no valid session is configured, or whatever
/// status-mapped [`Error`] the request produces otherwise.
pub async fn disable(
&self,
network_id: &str,
parent: Option<&Value>,
) -> Result<Envelope, Error> {
let url =
routes::ddns::DDNS_DISABLE.resolve(self.transport.api_host(), network_id, parent)?;
links::warn_uncharacterised_write("disable DDNS for network");
self.transport
.request(
routes::ddns::DDNS_DISABLE.method.clone(),
url,
&[],
RequestBody::None,
)
.await
}
}