Skip to main content

spacetraders_client/endpoints/systems/
global.rs

1use crate::client::StClient;
2use crate::client::{
3    ClientError, RequestPriority, RetryPolicy, classify_status, retry_after_from_headers,
4};
5use crate::types;
6
7impl StClient {
8    pub async fn status(&self) -> Result<types::GetStatusResponse, ClientError> {
9        self.status_with_priority(RequestPriority::Normal).await
10    }
11
12    pub async fn status_with_priority(
13        &self,
14        priority: RequestPriority,
15    ) -> Result<types::GetStatusResponse, ClientError> {
16        let url = format!("{}/", self.base_url);
17        // Plain GET on the API root — idempotent, safe to retry transiently.
18        self.send_retrying("status", priority, RetryPolicy::Idempotent, || {
19            let url = url.clone();
20            async move {
21                let resp = self
22                    .http
23                    .get(&url)
24                    .send()
25                    .await
26                    .map_err(ClientError::Http)?;
27
28                if !resp.status().is_success() {
29                    let status = resp.status();
30                    let retry_after = retry_after_from_headers(resp.headers());
31                    let body = resp.text().await.unwrap_or_default();
32                    return Err(classify_status(status, retry_after, body));
33                }
34
35                resp.json().await.map_err(ClientError::Http)
36            }
37        })
38        .await
39    }
40
41    pub async fn get_status(&self) -> Result<types::GetStatusResponse, ClientError> {
42        self.get_status_with_priority(RequestPriority::Normal).await
43    }
44
45    pub async fn get_status_with_priority(
46        &self,
47        priority: RequestPriority,
48    ) -> Result<types::GetStatusResponse, ClientError> {
49        self.send("get_status", priority, || self.inner.get_status())
50            .await
51    }
52
53    pub async fn get_error_codes(&self) -> Result<types::GetErrorCodesResponse, ClientError> {
54        self.get_error_codes_with_priority(RequestPriority::Normal)
55            .await
56    }
57
58    pub async fn get_error_codes_with_priority(
59        &self,
60        priority: RequestPriority,
61    ) -> Result<types::GetErrorCodesResponse, ClientError> {
62        self.send("get_error_codes", priority, || self.inner.get_error_codes())
63            .await
64    }
65}