hcloud/apis/
load_balancer_types_api.rs

1/*
2 * Hetzner Cloud API
3 *
4 * Copied from the official API documentation for the Public Hetzner Cloud.
5 *
6 * The version of the OpenAPI document: 0.26.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for passing parameters to the method [`get_load_balancer_type`]
17#[derive(Clone, Debug, Default)]
18pub struct GetLoadBalancerTypeParams {
19    /// ID of the Load Balancer Type.
20    pub id: i64,
21}
22
23/// struct for passing parameters to the method [`list_load_balancer_types`]
24#[derive(Clone, Debug, Default)]
25pub struct ListLoadBalancerTypesParams {
26    /// Filter resources by their name. The response will only contain the resources matching exactly the specified name.
27    pub name: Option<String>,
28    /// Page number to return. For more information, see \"[Pagination](#pagination)\".
29    pub page: Option<i64>,
30    /// Maximum number of entries returned per page. For more information, see \"[Pagination](#pagination)\".
31    pub per_page: Option<i64>,
32}
33
34/// struct for typed errors of method [`get_load_balancer_type`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetLoadBalancerTypeError {
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`list_load_balancer_types`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum ListLoadBalancerTypesError {
45    UnknownValue(serde_json::Value),
46}
47
48/// Gets a specific Load Balancer type object.
49pub async fn get_load_balancer_type(
50    configuration: &configuration::Configuration,
51    params: GetLoadBalancerTypeParams,
52) -> Result<models::GetLoadBalancerTypeResponse, Error<GetLoadBalancerTypeError>> {
53    let local_var_configuration = configuration;
54
55    // unbox the parameters
56    let id = params.id;
57
58    let local_var_client = &local_var_configuration.client;
59
60    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
61    let local_var_uri_str = format!("{}/load_balancer_types/{id}", local_base_path, id = id);
62    let mut local_var_req_builder =
63        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
64
65    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
66        local_var_req_builder =
67            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
68    }
69    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
70        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
71    };
72
73    let local_var_req = local_var_req_builder.build()?;
74    let local_var_resp = local_var_client.execute(local_var_req).await?;
75
76    let local_var_status = local_var_resp.status();
77    let local_var_content = local_var_resp.text().await?;
78
79    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
80        serde_json::from_str(&local_var_content).map_err(Error::from)
81    } else {
82        let local_var_entity: Option<GetLoadBalancerTypeError> =
83            serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent {
85            status: local_var_status,
86            content: local_var_content,
87            entity: local_var_entity,
88        };
89        Err(Error::ResponseError(local_var_error))
90    }
91}
92
93/// Gets all Load Balancer type objects.
94pub async fn list_load_balancer_types(
95    configuration: &configuration::Configuration,
96    params: ListLoadBalancerTypesParams,
97) -> Result<models::ListLoadBalancerTypesResponse, Error<ListLoadBalancerTypesError>> {
98    let local_var_configuration = configuration;
99
100    // unbox the parameters
101    let name = params.name;
102    let page = params.page;
103    let per_page = params.per_page;
104
105    let local_var_client = &local_var_configuration.client;
106
107    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
108    let local_var_uri_str = format!("{}/load_balancer_types", local_base_path);
109    let mut local_var_req_builder =
110        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
111
112    if let Some(ref local_var_str) = name {
113        local_var_req_builder =
114            local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
115    }
116    if let Some(ref local_var_str) = page {
117        local_var_req_builder =
118            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
119    }
120    if let Some(ref local_var_str) = per_page {
121        local_var_req_builder =
122            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
123    }
124    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
125        local_var_req_builder =
126            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
129        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130    };
131
132    let local_var_req = local_var_req_builder.build()?;
133    let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135    let local_var_status = local_var_resp.status();
136    let local_var_content = local_var_resp.text().await?;
137
138    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139        serde_json::from_str(&local_var_content).map_err(Error::from)
140    } else {
141        let local_var_entity: Option<ListLoadBalancerTypesError> =
142            serde_json::from_str(&local_var_content).ok();
143        let local_var_error = ResponseContent {
144            status: local_var_status,
145            content: local_var_content,
146            entity: local_var_entity,
147        };
148        Err(Error::ResponseError(local_var_error))
149    }
150}