tba_openapi_rust/apis/
tba_api.rs

1/*
2 * The Blue Alliance API v3
3 *
4 * # Overview    Information and statistics about FIRST Robotics Competition teams and events.   # Authentication   All endpoints require an Auth Key to be passed in the header `X-TBA-Auth-Key`. If you do not have an auth key yet, you can obtain one from your [Account Page](/account).
5 *
6 * The version of the OpenAPI document: 3.8.2
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`get_status`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetStatusError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26
27/// Returns API status, and TBA status information.
28pub async fn get_status(configuration: &configuration::Configuration, if_none_match: Option<&str>) -> Result<crate::models::ApiStatus, Error<GetStatusError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!("{}/status", local_var_configuration.base_path);
34    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
37        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    if let Some(local_var_param_value) = if_none_match {
40        local_var_req_builder = local_var_req_builder.header("If-None-Match", local_var_param_value.to_string());
41    }
42    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
43        let local_var_key = local_var_apikey.key.clone();
44        let local_var_value = match local_var_apikey.prefix {
45            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
46            None => local_var_key,
47        };
48        local_var_req_builder = local_var_req_builder.header("X-TBA-Auth-Key", local_var_value);
49    };
50
51    let local_var_req = local_var_req_builder.build()?;
52    let local_var_resp = local_var_client.execute(local_var_req).await?;
53
54    let local_var_status = local_var_resp.status();
55    let local_var_content = local_var_resp.text().await?;
56
57    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
58        serde_json::from_str(&local_var_content).map_err(Error::from)
59    } else {
60        let local_var_entity: Option<GetStatusError> = serde_json::from_str(&local_var_content).ok();
61        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
62        Err(Error::ResponseError(local_var_error))
63    }
64}
65