prawn/apis/
providers_api.rs1use super::{configuration, Error};
12use crate::apis::ContentType;
13use crate::{apis::ResponseContent, models};
14use async_trait::async_trait;
15use reqwest;
16use serde::{de::Error as _, Deserialize, Serialize};
17use std::sync::Arc;
18
19#[async_trait]
20pub trait ProvidersApi: Send + Sync {
21 async fn get_provider<'id>(
25 &self,
26 id: &'id str,
27 ) -> Result<models::ProvidersSingleResourceDataDocument, Error<GetProviderError>>;
28
29 async fn get_providers<'filter_left_square_bracket_id_right_square_bracket>(
33 &self,
34 filter_left_square_bracket_id_right_square_bracket: Option<Vec<String>>,
35 ) -> Result<models::ProvidersMultiResourceDataDocument, Error<GetProvidersError>>;
36}
37
38#[derive(Clone)]
39pub struct ProvidersApiClient {
40 configuration: Arc<configuration::Configuration>,
41}
42
43impl ProvidersApiClient {
44 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
45 Self { configuration }
46 }
47}
48
49#[async_trait]
50impl ProvidersApi for ProvidersApiClient {
51 async fn get_provider<'id>(
53 &self,
54 id: &'id str,
55 ) -> Result<models::ProvidersSingleResourceDataDocument, Error<GetProviderError>> {
56 let local_var_configuration = &self.configuration;
57
58 let local_var_client = &local_var_configuration.client;
59
60 let local_var_uri_str = format!(
61 "{}/providers/{id}",
62 local_var_configuration.base_path,
63 id = crate::apis::urlencode(id)
64 );
65 let mut local_var_req_builder =
66 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
67
68 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
69 local_var_req_builder = local_var_req_builder
70 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
71 }
72 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
73 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
74 };
75 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
76 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
77 };
78
79 let local_var_req = local_var_req_builder.build()?;
80 let local_var_resp = local_var_client.execute(local_var_req).await?;
81
82 let local_var_status = local_var_resp.status();
83 let local_var_content_type = local_var_resp
84 .headers()
85 .get("content-type")
86 .and_then(|v| v.to_str().ok())
87 .unwrap_or("application/octet-stream");
88 let local_var_content_type = super::ContentType::from(local_var_content_type);
89 let local_var_content = local_var_resp.text().await?;
90
91 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92 match local_var_content_type {
93 ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&local_var_content)).map_err(Error::from),
94 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProvidersSingleResourceDataDocument`"))),
95 ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProvidersSingleResourceDataDocument`")))),
96 }
97 } else {
98 let local_var_entity: Option<GetProviderError> =
99 serde_json::from_str(&local_var_content).ok();
100 let local_var_error = ResponseContent {
101 status: local_var_status,
102 content: local_var_content,
103 entity: local_var_entity,
104 };
105 Err(Error::ResponseError(local_var_error))
106 }
107 }
108
109 async fn get_providers<'filter_left_square_bracket_id_right_square_bracket>(
111 &self,
112 filter_left_square_bracket_id_right_square_bracket: Option<Vec<String>>,
113 ) -> Result<models::ProvidersMultiResourceDataDocument, Error<GetProvidersError>> {
114 let local_var_configuration = &self.configuration;
115
116 let local_var_client = &local_var_configuration.client;
117
118 let local_var_uri_str = format!("{}/providers", local_var_configuration.base_path);
119 let mut local_var_req_builder =
120 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
121
122 if let Some(ref param_value) = filter_left_square_bracket_id_right_square_bracket {
123 local_var_req_builder = match "multi" {
124 "multi" => local_var_req_builder.query(
125 ¶m_value
126 .into_iter()
127 .map(|p| ("filter[id]".to_owned(), p.to_string()))
128 .collect::<Vec<(std::string::String, std::string::String)>>(),
129 ),
130 _ => local_var_req_builder.query(&[(
131 "filter[id]",
132 ¶m_value
133 .into_iter()
134 .map(|p| p.to_string())
135 .collect::<Vec<String>>()
136 .join(",")
137 .to_string(),
138 )]),
139 };
140 }
141 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142 local_var_req_builder = local_var_req_builder
143 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
144 }
145 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
146 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
147 };
148 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
149 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150 };
151
152 let local_var_req = local_var_req_builder.build()?;
153 let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155 let local_var_status = local_var_resp.status();
156 let local_var_content_type = local_var_resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let local_var_content_type = super::ContentType::from(local_var_content_type);
162 let local_var_content = local_var_resp.text().await?;
163
164 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165 match local_var_content_type {
166 ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&local_var_content)).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProvidersMultiResourceDataDocument`"))),
168 ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProvidersMultiResourceDataDocument`")))),
169 }
170 } else {
171 let local_var_entity: Option<GetProvidersError> =
172 serde_json::from_str(&local_var_content).ok();
173 let local_var_error = ResponseContent {
174 status: local_var_status,
175 content: local_var_content,
176 entity: local_var_entity,
177 };
178 Err(Error::ResponseError(local_var_error))
179 }
180 }
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185#[serde(untagged)]
186pub enum GetProviderError {
187 Status400(models::Default400ResponseBody),
188 Status404(models::Default404ResponseBody),
189 Status405(models::Default405ResponseBody),
190 Status406(models::Default406ResponseBody),
191 Status415(models::Default415ResponseBody),
192 Status429(models::Default429ResponseBody),
193 Status500(models::Default500ResponseBody),
194 Status503(models::Default503ResponseBody),
195 UnknownValue(serde_json::Value),
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum GetProvidersError {
202 Status400(models::Default400ResponseBody),
203 Status404(models::Default404ResponseBody),
204 Status405(models::Default405ResponseBody),
205 Status406(models::Default406ResponseBody),
206 Status415(models::Default415ResponseBody),
207 Status429(models::Default429ResponseBody),
208 Status500(models::Default500ResponseBody),
209 Status503(models::Default503ResponseBody),
210 UnknownValue(serde_json::Value),
211}