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