fastly_api/apis/
pop_api.rs1use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum ListPopsError {
19 UnknownValue(serde_json::Value),
20}
21
22
23pub async fn list_pops(configuration: &mut configuration::Configuration) -> Result<Vec<crate::models::Pop>, Error<ListPopsError>> {
25 let local_var_configuration = configuration;
26
27 let local_var_client = &local_var_configuration.client;
31
32 let local_var_uri_str = format!("{}/datacenters", local_var_configuration.base_path);
33 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
34
35 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
36 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
37 }
38 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
39 let local_var_key = local_var_apikey.key.clone();
40 let local_var_value = match local_var_apikey.prefix {
41 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
42 None => local_var_key,
43 };
44 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
45 };
46
47 let local_var_req = local_var_req_builder.build()?;
48 let local_var_resp = local_var_client.execute(local_var_req).await?;
49
50 if "GET" != "GET" && "GET" != "HEAD" {
51 let headers = local_var_resp.headers();
52 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
53 Some(v) => v.to_str().unwrap().parse().unwrap(),
54 None => configuration::DEFAULT_RATELIMIT,
55 };
56 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
57 Some(v) => v.to_str().unwrap().parse().unwrap(),
58 None => 0,
59 };
60 }
61
62 let local_var_status = local_var_resp.status();
63 let local_var_content = local_var_resp.text().await?;
64
65 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
66 serde_json::from_str(&local_var_content).map_err(Error::from)
67 } else {
68 let local_var_entity: Option<ListPopsError> = serde_json::from_str(&local_var_content).ok();
69 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
70 Err(Error::ResponseError(local_var_error))
71 }
72}
73