Skip to main content

polyoxide_gamma/api/
series.rs

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