nodesty_api_library/models/
shared.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase")]
5pub struct ApiResponse<T> {
6    #[serde(default = "default_success")]
7    pub success: bool,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub error: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub data: Option<T>,
12}
13
14fn default_success() -> bool {
15    true
16}
17
18#[derive(Debug, Clone)]
19pub struct RestClientOptions {
20    pub access_token: String,
21    pub base_url: String,
22    pub retry: Option<u32>,
23    pub timeout_ms: Option<u64>,
24    pub rate_limit_offset_ms: Option<u64>,
25}
26
27impl RestClientOptions {
28    pub fn new(access_token: String) -> Self {
29        Self {
30            access_token,
31            base_url: "https://nodesty.com/api".to_string(),
32            retry: Some(3),
33            timeout_ms: Some(30_000),
34            rate_limit_offset_ms: Some(50),
35        }
36    }
37
38    pub fn with_base_url(mut self, base_url: String) -> Self {
39        self.base_url = base_url;
40        self
41    }
42
43    pub fn with_retry(mut self, retry: u32) -> Self {
44        self.retry = Some(retry);
45        self
46    }
47
48    pub fn with_timeout_ms(mut self, timeout_ms: u64) -> Self {
49        self.timeout_ms = Some(timeout_ms);
50        self
51    }
52
53    pub fn with_rate_limit_offset_ms(mut self, rate_limit_offset_ms: u64) -> Self {
54        self.rate_limit_offset_ms = Some(rate_limit_offset_ms);
55        self
56    }
57}