ccdata_api/
schemas.rs

1pub mod min_api;
2pub mod data_api;
3
4
5use serde::Deserialize;
6
7
8// Min-API Wrappers
9
10
11#[derive(Deserialize, Debug)]
12pub struct CCCallsMade {
13    pub second: i32,
14    pub minute: i32,
15    pub hour: i32,
16    pub day: i32,
17    pub month: i32,
18    pub total_calls: i32,
19}
20
21#[derive(Deserialize, Debug)]
22pub struct CCMaxCalls {
23    pub second: i32,
24    pub minute: i32,
25    pub hour: i32,
26    pub day: i32,
27    pub month: i32,
28}
29
30#[derive(Deserialize, Debug)]
31pub struct CCRateLimit {
32    pub calls_made: Option<CCCallsMade>,
33    pub max_calls: Option<CCMaxCalls>,
34}
35
36#[derive(Deserialize, Debug)]
37pub struct CCMinWrapper<T> {
38    #[serde(rename = "Aggregated")]
39    pub aggregated: Option<bool>,
40    #[serde(rename = "TimeFrom")]
41    pub time_from: Option<i64>,
42    #[serde(rename = "TimeTo")]
43    pub time_to: Option<i64>,
44    #[serde(rename = "Data")]
45    pub data: Option<T>,
46}
47
48#[derive(Deserialize, Debug)]
49pub struct CCMinResponse<T> {
50    #[serde(rename = "Response")]
51    pub response: String,
52    #[serde(rename = "Message")]
53    pub message: String,
54    #[serde(rename = "HasWarning")]
55    pub has_warning: bool,
56    #[serde(rename = "Type")]
57    pub type_: i32,
58    #[serde(rename = "Data")]
59    pub data: Option<T>,
60    #[serde(rename = "RateLimit")]
61    pub rate_limit: Option<CCRateLimit>,
62}
63
64
65// Data-API Wrappers
66
67
68#[derive(Deserialize, Debug)]
69pub struct CCErrorOtherInfo {
70    /// The parameter that is responsible for the error.
71    pub param: Option<String>,
72    /// The values responsible for the error.
73    pub values: Option<Vec<String>>,
74    /// Status of the instrument.
75    pub instrument_status: Option<String>,
76    /// First available timestamp.
77    pub first: Option<i64>,
78    /// Last available timestamp.
79    pub last: Option<i64>,
80}
81
82#[derive(Deserialize, Debug)]
83/// This object provides detailed information about an error encountered while processing the request. It includes an error code, a message explaining the error,
84/// and additional context about the parameters or values that caused the issue. This helps clients identify and resolve issues with their requests.
85pub struct CCError {
86    #[serde(rename = "type")]
87    /// A public facing error type. If you want to treat a specific error use the type.
88    pub type_: i32,
89    /// A message describing the error.
90    pub message: String,
91    pub other_info: Option<CCErrorOtherInfo>,
92}
93
94#[derive(Deserialize, Debug)]
95pub struct CCDataResponse<T> {
96    #[serde(rename = "Data")]
97    pub data: Option<T>,
98    #[serde(rename = "Err")]
99    /// This object provides detailed information about an error encountered while processing the request. It includes an error code,
100    /// a message explaining the error, and additional context about the parameters or values that caused the issue.
101    /// This helps clients identify and resolve issues with their requests.
102    pub error: Option<CCError>,
103}
104
105
106#[cfg(test)]
107mod tests {
108
109    #[test]
110    fn unit_test_nullable_field() -> () {
111        use serde_json;
112        use crate::schemas;
113        let d: String = String::from("{\"Data\":{}, \"Err\":{\"type\": 23, \"message\": \"hello\", \"other_info\":null}}");
114        let response: schemas::CCDataResponse<String> = serde_json::from_str(&d.to_string().replace("{}", "null")).unwrap();
115        assert_eq!(response.data, None);
116    }
117}