1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Reports API
//!
//! This module provides functionality to get tenant reports.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::reports::*;
impl RainClient {
/// Get a tenant's report
///
/// # Arguments
///
/// * `year` - Year of the report
/// * `month` - Month of the report
/// * `day` - Day of the report
/// * `params` - Optional query parameters (format)
///
/// # Returns
///
/// Returns the report as raw bytes (content type depends on format: csv, json, or ssrp).
///
/// # Errors
///
/// This method can return the following errors:
/// - `400` - Invalid request
/// - `401` - Invalid authorization
/// - `404` - Report not found
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::reports::{GetReportParams, ReportFormat};
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let params = GetReportParams {
/// format: Some(ReportFormat::Csv),
/// };
/// let report = client.get_report("2024", "01", "15", ¶ms).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn get_report(
&self,
year: &str,
month: &str,
day: &str,
params: &GetReportParams,
) -> Result<Vec<u8>> {
let base_url = self.base_url();
let mut url = base_url.clone();
url.path_segments_mut()
.map_err(|_| crate::error::RainError::Other(anyhow::anyhow!("Cannot be a base URL")))?
.pop_if_empty()
.push("issuing")
.push("reports")
.push(year)
.push(month)
.push(day);
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
format!("/reports/{year}/{month}/{day}")
} else {
format!("/reports/{year}/{month}/{day}?{query_string}")
};
self.get_bytes(&full_path).await
}
// ============================================================================
// Blocking Methods
// ============================================================================
/// Get a tenant's report (blocking)
#[cfg(feature = "sync")]
pub fn get_report_blocking(
&self,
year: &str,
month: &str,
day: &str,
params: &GetReportParams,
) -> Result<Vec<u8>> {
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
format!("/reports/{year}/{month}/{day}")
} else {
format!("/reports/{year}/{month}/{day}?{query_string}")
};
self.get_bytes_blocking(&full_path)
}
}