polyte_gamma/api/
series.rs

1use reqwest::Client;
2use url::Url;
3
4use crate::{
5    request::{QueryBuilder, Request},
6    types::SeriesData,
7};
8
9/// Series namespace for series-related operations
10#[derive(Clone)]
11pub struct Series {
12    pub(crate) client: Client,
13    pub(crate) base_url: Url,
14}
15
16impl Series {
17    /// List series with optional filtering
18    pub fn list(&self) -> ListSeries {
19        ListSeries {
20            request: Request::new(
21                self.client.clone(),
22                self.base_url.clone(),
23                "/series".to_string(),
24            ),
25        }
26    }
27
28    /// Get a series by ID
29    pub fn get(&self, id: impl Into<String>) -> Request<SeriesData> {
30        Request::new(
31            self.client.clone(),
32            self.base_url.clone(),
33            format!("/series/{}", urlencoding::encode(&id.into())),
34        )
35    }
36}
37
38/// Request builder for listing series
39pub struct ListSeries {
40    request: Request<Vec<SeriesData>>,
41}
42
43impl ListSeries {
44    /// Limit the number of results
45    pub fn limit(mut self, limit: u32) -> Self {
46        self.request = self.request.query("limit", limit);
47        self
48    }
49
50    /// Offset the results
51    pub fn offset(mut self, offset: u32) -> Self {
52        self.request = self.request.query("offset", offset);
53        self
54    }
55
56    /// Sort in ascending order
57    pub fn ascending(mut self, ascending: bool) -> Self {
58        self.request = self.request.query("ascending", ascending);
59        self
60    }
61
62    /// Filter by closed status
63    pub fn closed(mut self, closed: bool) -> Self {
64        self.request = self.request.query("closed", closed);
65        self
66    }
67
68    /// Execute the request
69    pub async fn send(self) -> crate::error::Result<Vec<SeriesData>> {
70        self.request.send().await
71    }
72}