fastly_api/apis/
director_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 [`delete_director`]
15#[derive(Clone, Debug, Default)]
16pub struct DeleteDirectorParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// Name for the Director.
22    pub director_name: String
23}
24
25/// struct for passing parameters to the method [`get_director`]
26#[derive(Clone, Debug, Default)]
27pub struct GetDirectorParams {
28    /// Alphanumeric string identifying the service.
29    pub service_id: String,
30    /// Integer identifying a service version.
31    pub version_id: i32,
32    /// Name for the Director.
33    pub director_name: String
34}
35
36/// struct for passing parameters to the method [`list_directors`]
37#[derive(Clone, Debug, Default)]
38pub struct ListDirectorsParams {
39    /// Alphanumeric string identifying the service.
40    pub service_id: String,
41    /// Integer identifying a service version.
42    pub version_id: i32
43}
44
45/// struct for passing parameters to the method [`update_director`]
46#[derive(Clone, Debug, Default)]
47pub struct UpdateDirectorParams {
48    /// Alphanumeric string identifying the service.
49    pub service_id: String,
50    /// Integer identifying a service version.
51    pub version_id: i32,
52    /// Name for the Director.
53    pub director_name: String
54}
55
56
57/// struct for typed errors of method [`delete_director`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum DeleteDirectorError {
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`get_director`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum GetDirectorError {
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`list_directors`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum ListDirectorsError {
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`update_director`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum UpdateDirectorError {
82    UnknownValue(serde_json::Value),
83}
84
85
86/// Delete the director for a particular service and version.
87pub async fn delete_director(configuration: &mut configuration::Configuration, params: DeleteDirectorParams) -> Result<crate::models::InlineResponse200, Error<DeleteDirectorError>> {
88    let local_var_configuration = configuration;
89
90    // unbox the parameters
91    let service_id = params.service_id;
92    let version_id = params.version_id;
93    let director_name = params.director_name;
94
95
96    let local_var_client = &local_var_configuration.client;
97
98    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, director_name=crate::apis::urlencode(director_name));
99    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
100
101    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
105        let local_var_key = local_var_apikey.key.clone();
106        let local_var_value = match local_var_apikey.prefix {
107            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
108            None => local_var_key,
109        };
110        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
111    };
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116    if "DELETE" != "GET" && "DELETE" != "HEAD" {
117      let headers = local_var_resp.headers();
118      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
119          Some(v) => v.to_str().unwrap().parse().unwrap(),
120          None => configuration::DEFAULT_RATELIMIT,
121      };
122      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
123          Some(v) => v.to_str().unwrap().parse().unwrap(),
124          None => 0,
125      };
126    }
127
128    let local_var_status = local_var_resp.status();
129    let local_var_content = local_var_resp.text().await?;
130
131    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
132        serde_json::from_str(&local_var_content).map_err(Error::from)
133    } else {
134        let local_var_entity: Option<DeleteDirectorError> = serde_json::from_str(&local_var_content).ok();
135        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
136        Err(Error::ResponseError(local_var_error))
137    }
138}
139
140/// Get the director for a particular service and version.
141pub async fn get_director(configuration: &mut configuration::Configuration, params: GetDirectorParams) -> Result<crate::models::DirectorResponse, Error<GetDirectorError>> {
142    let local_var_configuration = configuration;
143
144    // unbox the parameters
145    let service_id = params.service_id;
146    let version_id = params.version_id;
147    let director_name = params.director_name;
148
149
150    let local_var_client = &local_var_configuration.client;
151
152    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, director_name=crate::apis::urlencode(director_name));
153    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
154
155    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
156        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157    }
158    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
159        let local_var_key = local_var_apikey.key.clone();
160        let local_var_value = match local_var_apikey.prefix {
161            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
162            None => local_var_key,
163        };
164        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
165    };
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    if "GET" != "GET" && "GET" != "HEAD" {
171      let headers = local_var_resp.headers();
172      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
173          Some(v) => v.to_str().unwrap().parse().unwrap(),
174          None => configuration::DEFAULT_RATELIMIT,
175      };
176      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
177          Some(v) => v.to_str().unwrap().parse().unwrap(),
178          None => 0,
179      };
180    }
181
182    let local_var_status = local_var_resp.status();
183    let local_var_content = local_var_resp.text().await?;
184
185    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186        serde_json::from_str(&local_var_content).map_err(Error::from)
187    } else {
188        let local_var_entity: Option<GetDirectorError> = serde_json::from_str(&local_var_content).ok();
189        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
190        Err(Error::ResponseError(local_var_error))
191    }
192}
193
194/// List the directors for a particular service and version.
195pub async fn list_directors(configuration: &mut configuration::Configuration, params: ListDirectorsParams) -> Result<Vec<crate::models::DirectorResponse>, Error<ListDirectorsError>> {
196    let local_var_configuration = configuration;
197
198    // unbox the parameters
199    let service_id = params.service_id;
200    let version_id = params.version_id;
201
202
203    let local_var_client = &local_var_configuration.client;
204
205    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
206    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
207
208    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
209        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
210    }
211    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
212        let local_var_key = local_var_apikey.key.clone();
213        let local_var_value = match local_var_apikey.prefix {
214            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
215            None => local_var_key,
216        };
217        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
218    };
219
220    let local_var_req = local_var_req_builder.build()?;
221    let local_var_resp = local_var_client.execute(local_var_req).await?;
222
223    if "GET" != "GET" && "GET" != "HEAD" {
224      let headers = local_var_resp.headers();
225      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
226          Some(v) => v.to_str().unwrap().parse().unwrap(),
227          None => configuration::DEFAULT_RATELIMIT,
228      };
229      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
230          Some(v) => v.to_str().unwrap().parse().unwrap(),
231          None => 0,
232      };
233    }
234
235    let local_var_status = local_var_resp.status();
236    let local_var_content = local_var_resp.text().await?;
237
238    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239        serde_json::from_str(&local_var_content).map_err(Error::from)
240    } else {
241        let local_var_entity: Option<ListDirectorsError> = serde_json::from_str(&local_var_content).ok();
242        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
243        Err(Error::ResponseError(local_var_error))
244    }
245}
246
247/// Update the director for a particular service and version.
248pub async fn update_director(configuration: &mut configuration::Configuration, params: UpdateDirectorParams) -> Result<crate::models::DirectorResponse, Error<UpdateDirectorError>> {
249    let local_var_configuration = configuration;
250
251    // unbox the parameters
252    let service_id = params.service_id;
253    let version_id = params.version_id;
254    let director_name = params.director_name;
255
256
257    let local_var_client = &local_var_configuration.client;
258
259    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/director/{director_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, director_name=crate::apis::urlencode(director_name));
260    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
261
262    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
263        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
264    }
265    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
266        let local_var_key = local_var_apikey.key.clone();
267        let local_var_value = match local_var_apikey.prefix {
268            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
269            None => local_var_key,
270        };
271        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
272    };
273
274    let local_var_req = local_var_req_builder.build()?;
275    let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277    if "PUT" != "GET" && "PUT" != "HEAD" {
278      let headers = local_var_resp.headers();
279      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
280          Some(v) => v.to_str().unwrap().parse().unwrap(),
281          None => configuration::DEFAULT_RATELIMIT,
282      };
283      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
284          Some(v) => v.to_str().unwrap().parse().unwrap(),
285          None => 0,
286      };
287    }
288
289    let local_var_status = local_var_resp.status();
290    let local_var_content = local_var_resp.text().await?;
291
292    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293        serde_json::from_str(&local_var_content).map_err(Error::from)
294    } else {
295        let local_var_entity: Option<UpdateDirectorError> = serde_json::from_str(&local_var_content).ok();
296        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
297        Err(Error::ResponseError(local_var_error))
298    }
299}
300