fundamentum_sdk_api/client/
sdk_api.rs

1//! User facing structure to make calls to the Fundamentum API.
2
3use std::marker::PhantomData;
4
5use super::{
6    api_version::ApiVersion,
7    config::ClientConfig,
8    devices_api::{DevicesApi, DevicesApiConfig},
9    errors::SdkClientError,
10    provisioning_api::{ProvisioningApi, ProvisioningApiConfig},
11    sdk_client::SdkClient,
12    shelf_devices_api::{ShelfDevicesApi, ShelfDevicesApiConfig},
13};
14use crate::models::general::Status;
15
16/// User facing structure to make calls to the Fundamentum API. This may be used within
17/// a user application to register a device, provision it, and other actions available
18/// via the Fundamentum API.
19pub struct SdkApi<V> {
20    client: SdkClient,
21    _marker: PhantomData<fn() -> V>,
22}
23
24impl<V: ApiVersion> SdkApi<V> {
25    /// Create a new SDK API to access Fundamentum's API.
26    #[must_use]
27    pub fn new(config: ClientConfig) -> Self {
28        let api_version = V::version_str();
29        let client = SdkClient::new(config, api_version);
30        Self {
31            client,
32            _marker: PhantomData,
33        }
34    }
35
36    /// Get the API's status.
37    ///
38    /// # Errors
39    ///
40    /// There may be errors if the API is not up and running.
41    pub async fn status(&self) -> Result<Status, SdkClientError> {
42        self.client.status().await
43    }
44
45    /// Retrieve the Open API Json file.
46    ///
47    /// # Errors
48    ///
49    /// There may be errors if the API is not up and running.
50    pub async fn get_openapi_json(&self) -> Result<serde_json::Value, SdkClientError> {
51        self.client.get_openapi_json().await
52    }
53
54    /// Get the Devices API.
55    #[must_use]
56    pub fn devices_api<'a>(&'a self, api_config: &'a DevicesApiConfig) -> DevicesApi<'a, V> {
57        DevicesApi::new(&self.client, api_config)
58    }
59
60    /// Get the Provisioning API.
61    #[must_use]
62    pub fn provisioning_api<'a>(
63        &'a self,
64        api_config: &'a ProvisioningApiConfig,
65    ) -> ProvisioningApi<'a, V> {
66        ProvisioningApi::new(&self.client, api_config)
67    }
68
69    /// Get the Shelf Devices API.
70    #[must_use]
71    pub fn shelf_devices_api<'a>(
72        &'a self,
73        config: &'a ShelfDevicesApiConfig,
74    ) -> ShelfDevicesApi<'a, V> {
75        ShelfDevicesApi::new(&self.client, config)
76    }
77
78    /// Return the real [`SdkClient`] used internally. This allows the flexibility to use
79    /// the client to make other requests not supported by this SDK, however known to exist.
80    #[must_use]
81    pub const fn get_sdk_client(&self) -> &SdkClient {
82        &self.client
83    }
84}