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
//! Routing API: read-only routing information for a network.
//!
//! Ported from `eero-api src/eero/api/routing.py` (v8.4.1). Python's `RoutingAPI` has exactly
//! one method (`get_routing`) and no mutating counterpart.
use std::sync::Arc;
use serde_json::Value;
use crate::envelope::Envelope;
use crate::error::Error;
use crate::links::rewrite_version;
use crate::routes::{self, ApiVersion};
use crate::transport::{RequestBody, Transport};
/// `eero-api`'s `RoutingAPI` (`src/eero/api/routing.py`): a single read-only method returning a
/// network's routing information.
///
/// Build one with [`RoutingApi::new`], wrapping a [`Transport`] already shared with the rest of
/// the `EeroApi` aggregator — `RoutingApi` never constructs or owns a `Transport` itself.
#[derive(Debug)]
pub struct RoutingApi {
transport: Arc<Transport>,
}
impl RoutingApi {
/// Wraps `transport` as a `RoutingApi`.
#[must_use]
pub fn new(transport: Arc<Transport>) -> Self {
Self { transport }
}
/// Gets routing information for a network — returns the raw Eero API response.
///
/// Ported from `eero-api src/eero/api/routing.py:35-74` (`RoutingAPI.get_routing`). Sends
/// `GET` [`crate::routes::routing::GET_ROUTING_V8`], preferring `parent`'s own published
/// `routing` link, and always on API version 2.2: the resolved URL is re-pinned with
/// [`crate::links::rewrite_version`] whichever form `network_id` takes and whatever version
/// the published link names. The API publishes the link on 2.3 for a current `User-Agent`;
/// the known shape is the same on both versions, so the pin is for safety.
///
/// # Errors
///
/// Returns [`Error::Validation`] if `network_id`/`parent` cannot be resolved to a URL.
/// Otherwise, [`Error::Authentication`] if no valid session is configured, or whatever
/// status-mapped [`Error`] the request produces.
pub async fn get_routing(
&self,
network_id: &str,
parent: Option<&Value>,
) -> Result<Envelope, Error> {
let url = routes::routing::GET_ROUTING_V8.resolve(
self.transport.api_host(),
network_id,
parent,
)?;
let url = rewrite_version(&url, ApiVersion::V2_2);
self.transport
.request(
routes::routing::GET_ROUTING_V8.method.clone(),
url,
&[],
RequestBody::None,
)
.await
}
}