oxide_api/
metrics.rs

1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Metrics {
6    pub client: Client,
7}
8
9impl Metrics {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Metrics { client }
13    }
14
15    /**
16     * List timeseries schema.
17     *
18     * This function performs a `GET` to the `/timeseries/schema` endpoint.
19     *
20     * **Parameters:**
21     *
22     * * `limit: u32` -- Maximum number of items returned by a single call.
23     * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
24     */
25    pub async fn timeseries_schema_get(
26        &self,
27        limit: u32,
28        page_token: &str,
29    ) -> Result<Vec<crate::types::TimeseriesSchema>> {
30        let mut query_args: Vec<(String, String)> = Default::default();
31        if !limit.to_string().is_empty() {
32            query_args.push(("limit".to_string(), limit.to_string()));
33        }
34        if !page_token.is_empty() {
35            query_args.push(("page_token".to_string(), page_token.to_string()));
36        }
37        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
38        let url = format!("/timeseries/schema?{}", query_);
39
40        let resp: crate::types::TimeseriesSchemaResultsPage = self.client.get(&url, None).await?;
41
42        // Return our response data.
43        Ok(resp.items)
44    }
45
46    /**
47     * List timeseries schema.
48     *
49     * This function performs a `GET` to the `/timeseries/schema` endpoint.
50     *
51     * As opposed to `timeseries_schema_get`, this function returns all the pages of the request at once.
52     */
53    pub async fn timeseries_schema_get_all(&self) -> Result<Vec<crate::types::TimeseriesSchema>> {
54        let url = "/timeseries/schema".to_string();
55        let mut resp: crate::types::TimeseriesSchemaResultsPage =
56            self.client.get(&url, None).await?;
57
58        let mut items = resp.items;
59        let mut page = resp.next_page;
60
61        // Paginate if we should.
62        while !page.is_empty() {
63            if !url.contains('?') {
64                resp = self
65                    .client
66                    .get(&format!("{}?page={}", url, page), None)
67                    .await?;
68            } else {
69                resp = self
70                    .client
71                    .get(&format!("{}&page={}", url, page), None)
72                    .await?;
73            }
74
75            items.append(&mut resp.items);
76
77            if !resp.next_page.is_empty() && resp.next_page != page {
78                page = resp.next_page.to_string();
79            } else {
80                page = "".to_string();
81            }
82        }
83
84        // Return our response data.
85        Ok(items)
86    }
87}