fastly_api/apis/
star_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_service_star`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateServiceStarParams {
17    pub star: Option<crate::models::Star>
18}
19
20/// struct for passing parameters to the method [`delete_service_star`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteServiceStarParams {
23    /// Alphanumeric string identifying a star.
24    pub star_id: String
25}
26
27/// struct for passing parameters to the method [`get_service_star`]
28#[derive(Clone, Debug, Default)]
29pub struct GetServiceStarParams {
30    /// Alphanumeric string identifying a star.
31    pub star_id: String
32}
33
34
35/// struct for typed errors of method [`create_service_star`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum CreateServiceStarError {
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`delete_service_star`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum DeleteServiceStarError {
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`get_service_star`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum GetServiceStarError {
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`list_service_stars`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum ListServiceStarsError {
60    UnknownValue(serde_json::Value),
61}
62
63
64/// Create star.
65pub async fn create_service_star(configuration: &mut configuration::Configuration, params: CreateServiceStarParams) -> Result<crate::models::StarResponse, Error<CreateServiceStarError>> {
66    let local_var_configuration = configuration;
67
68    // unbox the parameters
69    let star = params.star;
70
71
72    let local_var_client = &local_var_configuration.client;
73
74    let local_var_uri_str = format!("{}/stars", local_var_configuration.base_path);
75    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
76
77    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79    }
80    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
81        let local_var_key = local_var_apikey.key.clone();
82        let local_var_value = match local_var_apikey.prefix {
83            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
84            None => local_var_key,
85        };
86        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
87    };
88    local_var_req_builder = local_var_req_builder.json(&star);
89
90    let local_var_req = local_var_req_builder.build()?;
91    let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93    if "POST" != "GET" && "POST" != "HEAD" {
94      let headers = local_var_resp.headers();
95      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
96          Some(v) => v.to_str().unwrap().parse().unwrap(),
97          None => configuration::DEFAULT_RATELIMIT,
98      };
99      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
100          Some(v) => v.to_str().unwrap().parse().unwrap(),
101          None => 0,
102      };
103    }
104
105    let local_var_status = local_var_resp.status();
106    let local_var_content = local_var_resp.text().await?;
107
108    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
109        serde_json::from_str(&local_var_content).map_err(Error::from)
110    } else {
111        let local_var_entity: Option<CreateServiceStarError> = serde_json::from_str(&local_var_content).ok();
112        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
113        Err(Error::ResponseError(local_var_error))
114    }
115}
116
117/// Delete star.
118pub async fn delete_service_star(configuration: &mut configuration::Configuration, params: DeleteServiceStarParams) -> Result<(), Error<DeleteServiceStarError>> {
119    let local_var_configuration = configuration;
120
121    // unbox the parameters
122    let star_id = params.star_id;
123
124
125    let local_var_client = &local_var_configuration.client;
126
127    let local_var_uri_str = format!("{}/stars/{star_id}", local_var_configuration.base_path, star_id=crate::apis::urlencode(star_id));
128    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
129
130    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
131        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
132    }
133    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
134        let local_var_key = local_var_apikey.key.clone();
135        let local_var_value = match local_var_apikey.prefix {
136            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
137            None => local_var_key,
138        };
139        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
140    };
141
142    let local_var_req = local_var_req_builder.build()?;
143    let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145    if "DELETE" != "GET" && "DELETE" != "HEAD" {
146      let headers = local_var_resp.headers();
147      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
148          Some(v) => v.to_str().unwrap().parse().unwrap(),
149          None => configuration::DEFAULT_RATELIMIT,
150      };
151      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
152          Some(v) => v.to_str().unwrap().parse().unwrap(),
153          None => 0,
154      };
155    }
156
157    let local_var_status = local_var_resp.status();
158    let local_var_content = local_var_resp.text().await?;
159
160    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161        Ok(())
162    } else {
163        let local_var_entity: Option<DeleteServiceStarError> = serde_json::from_str(&local_var_content).ok();
164        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
165        Err(Error::ResponseError(local_var_error))
166    }
167}
168
169/// Show star.
170pub async fn get_service_star(configuration: &mut configuration::Configuration, params: GetServiceStarParams) -> Result<crate::models::StarResponse, Error<GetServiceStarError>> {
171    let local_var_configuration = configuration;
172
173    // unbox the parameters
174    let star_id = params.star_id;
175
176
177    let local_var_client = &local_var_configuration.client;
178
179    let local_var_uri_str = format!("{}/stars/{star_id}", local_var_configuration.base_path, star_id=crate::apis::urlencode(star_id));
180    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
181
182    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
183        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
184    }
185    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
186        let local_var_key = local_var_apikey.key.clone();
187        let local_var_value = match local_var_apikey.prefix {
188            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
189            None => local_var_key,
190        };
191        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    if "GET" != "GET" && "GET" != "HEAD" {
198      let headers = local_var_resp.headers();
199      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
200          Some(v) => v.to_str().unwrap().parse().unwrap(),
201          None => configuration::DEFAULT_RATELIMIT,
202      };
203      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
204          Some(v) => v.to_str().unwrap().parse().unwrap(),
205          None => 0,
206      };
207    }
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text().await?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<GetServiceStarError> = serde_json::from_str(&local_var_content).ok();
216        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
217        Err(Error::ResponseError(local_var_error))
218    }
219}
220
221/// List stars.
222pub async fn list_service_stars(configuration: &mut configuration::Configuration) -> Result<crate::models::Pagination, Error<ListServiceStarsError>> {
223    let local_var_configuration = configuration;
224
225    // unbox the parameters
226
227
228    let local_var_client = &local_var_configuration.client;
229
230    let local_var_uri_str = format!("{}/stars", local_var_configuration.base_path);
231    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
232
233    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
234        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
235    }
236    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
237        let local_var_key = local_var_apikey.key.clone();
238        let local_var_value = match local_var_apikey.prefix {
239            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
240            None => local_var_key,
241        };
242        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
243    };
244
245    let local_var_req = local_var_req_builder.build()?;
246    let local_var_resp = local_var_client.execute(local_var_req).await?;
247
248    if "GET" != "GET" && "GET" != "HEAD" {
249      let headers = local_var_resp.headers();
250      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
251          Some(v) => v.to_str().unwrap().parse().unwrap(),
252          None => configuration::DEFAULT_RATELIMIT,
253      };
254      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
255          Some(v) => v.to_str().unwrap().parse().unwrap(),
256          None => 0,
257      };
258    }
259
260    let local_var_status = local_var_resp.status();
261    let local_var_content = local_var_resp.text().await?;
262
263    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264        serde_json::from_str(&local_var_content).map_err(Error::from)
265    } else {
266        let local_var_entity: Option<ListServiceStarsError> = serde_json::from_str(&local_var_content).ok();
267        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
268        Err(Error::ResponseError(local_var_error))
269    }
270}
271