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 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 Ok(resp.items)
44 }
45
46 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 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 Ok(items)
86 }
87}