polyte_gamma/api/
comments.rs

1use reqwest::Client;
2use url::Url;
3
4use crate::{
5    request::{QueryBuilder, Request},
6    types::Comment,
7};
8
9/// Comments namespace for comment-related operations
10#[derive(Clone)]
11pub struct Comments {
12    pub(crate) client: Client,
13    pub(crate) base_url: Url,
14}
15
16impl Comments {
17    /// List comments with optional filtering
18    pub fn list(&self) -> ListComments {
19        ListComments {
20            request: Request::new(
21                self.client.clone(),
22                self.base_url.clone(),
23                "/comments".to_string(),
24            ),
25        }
26    }
27}
28
29/// Request builder for listing comments
30pub struct ListComments {
31    request: Request<Vec<Comment>>,
32}
33
34impl ListComments {
35    /// Set maximum number of results (minimum: 0)
36    pub fn limit(mut self, limit: u32) -> Self {
37        self.request = self.request.query("limit", limit);
38        self
39    }
40
41    /// Set pagination offset (minimum: 0)
42    pub fn offset(mut self, offset: u32) -> Self {
43        self.request = self.request.query("offset", offset);
44        self
45    }
46
47    /// Set order fields (comma-separated list)
48    pub fn order(mut self, order: impl Into<String>) -> Self {
49        self.request = self.request.query("order", order.into());
50        self
51    }
52
53    /// Set sort direction
54    pub fn ascending(mut self, ascending: bool) -> Self {
55        self.request = self.request.query("ascending", ascending);
56        self
57    }
58
59    /// Filter by parent entity type (Event, Series, market)
60    pub fn parent_entity_type(mut self, entity_type: impl Into<String>) -> Self {
61        self.request = self.request.query("parent_entity_type", entity_type.into());
62        self
63    }
64
65    /// Filter by parent entity ID
66    pub fn parent_entity_id(mut self, id: i64) -> Self {
67        self.request = self.request.query("parent_entity_id", id);
68        self
69    }
70
71    /// Include position data in response
72    pub fn get_positions(mut self, include: bool) -> Self {
73        self.request = self.request.query("get_positions", include);
74        self
75    }
76
77    /// Restrict results to position holders only
78    pub fn holders_only(mut self, holders_only: bool) -> Self {
79        self.request = self.request.query("holders_only", holders_only);
80        self
81    }
82
83    /// Filter by market ID (deprecated - use parent_entity_id with parent_entity_type=market)
84    pub fn market_id(mut self, id: impl Into<String>) -> Self {
85        self.request = self.request.query("market_id", id.into());
86        self
87    }
88
89    /// Filter by event ID (deprecated - use parent_entity_id with parent_entity_type=Event)
90    pub fn event_id(mut self, id: impl Into<String>) -> Self {
91        self.request = self.request.query("event_id", id.into());
92        self
93    }
94
95    /// Filter by series ID (deprecated - use parent_entity_id with parent_entity_type=Series)
96    pub fn series_id(mut self, id: impl Into<String>) -> Self {
97        self.request = self.request.query("series_id", id.into());
98        self
99    }
100
101    /// Filter by parent comment ID
102    pub fn parent_id(mut self, id: impl Into<String>) -> Self {
103        self.request = self.request.query("parent_id", id.into());
104        self
105    }
106
107    /// Execute the request
108    pub async fn send(self) -> crate::error::Result<Vec<Comment>> {
109        self.request.send().await
110    }
111}