freedom_api/extensions/
satellite.rs1use freedom_models::{
2 account::Account, band::Band, satellite::Satellite,
3 satellite_configuration::SatelliteConfiguration,
4};
5
6use crate::{Api, error::Error};
7
8pub trait SatelliteExt {
9 fn get_id(&self) -> Result<i32, Error>;
10
11 fn get_account<C>(
12 &self,
13 client: &C,
14 ) -> impl Future<Output = Result<Account, Error>> + Send + Sync
15 where
16 C: Api;
17
18 fn get_satellite_configuration<C>(
19 &self,
20 client: &C,
21 ) -> impl Future<Output = Result<SatelliteConfiguration, Error>> + Send + Sync
22 where
23 C: Api;
24}
25
26impl SatelliteExt for Satellite {
27 fn get_id(&self) -> Result<i32, Error> {
28 super::get_id("self", &self.links)
29 }
30
31 async fn get_account<C>(&self, client: &C) -> Result<Account, Error>
32 where
33 C: Api,
34 {
35 super::get_item("account", &self.links, client).await
36 }
37
38 async fn get_satellite_configuration<C>(
39 &self,
40 client: &C,
41 ) -> Result<SatelliteConfiguration, Error>
42 where
43 C: Api,
44 {
45 super::get_item("configuration", &self.links, client).await
46 }
47}
48
49pub trait SatelliteConfigurationExt {
50 fn get_id(&self) -> Result<i32, Error>;
51
52 fn get_account<C>(
53 &self,
54 client: &C,
55 ) -> impl Future<Output = Result<Account, Error>> + Send + Sync
56 where
57 C: Api;
58
59 fn get_bands<C>(
60 &self,
61 client: &C,
62 ) -> impl Future<Output = Result<Vec<Band>, Error>> + Send + Sync
63 where
64 C: Api;
65}
66
67impl SatelliteConfigurationExt for SatelliteConfiguration {
68 fn get_id(&self) -> Result<i32, Error> {
69 super::get_id("self", &self.links)
70 }
71
72 async fn get_account<C>(&self, client: &C) -> Result<Account, Error>
73 where
74 C: Api,
75 {
76 super::get_content("account", &self.links, client).await
77 }
78
79 async fn get_bands<C>(&self, client: &C) -> Result<Vec<Band>, Error>
80 where
81 C: Api,
82 {
83 super::get_embedded("bandDetails", &self.links, client).await
84 }
85}