fastly_api/apis/
dictionary_item_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 [`bulk_update_dictionary_item`]
15#[derive(Clone, Debug, Default)]
16pub struct BulkUpdateDictionaryItemParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Alphanumeric string identifying a Dictionary.
20    pub dictionary_id: String,
21    pub bulk_update_dictionary_list_request: Option<crate::models::BulkUpdateDictionaryListRequest>
22}
23
24/// struct for passing parameters to the method [`create_dictionary_item`]
25#[derive(Clone, Debug, Default)]
26pub struct CreateDictionaryItemParams {
27    /// Alphanumeric string identifying the service.
28    pub service_id: String,
29    /// Alphanumeric string identifying a Dictionary.
30    pub dictionary_id: String,
31    /// Item key, maximum 256 characters.
32    pub item_key: Option<String>,
33    /// Item value, maximum 8000 characters.
34    pub item_value: Option<String>
35}
36
37/// struct for passing parameters to the method [`delete_dictionary_item`]
38#[derive(Clone, Debug, Default)]
39pub struct DeleteDictionaryItemParams {
40    /// Alphanumeric string identifying the service.
41    pub service_id: String,
42    /// Alphanumeric string identifying a Dictionary.
43    pub dictionary_id: String,
44    /// Item key, maximum 256 characters.
45    pub dictionary_item_key: String
46}
47
48/// struct for passing parameters to the method [`get_dictionary_item`]
49#[derive(Clone, Debug, Default)]
50pub struct GetDictionaryItemParams {
51    /// Alphanumeric string identifying the service.
52    pub service_id: String,
53    /// Alphanumeric string identifying a Dictionary.
54    pub dictionary_id: String,
55    /// Item key, maximum 256 characters.
56    pub dictionary_item_key: String
57}
58
59/// struct for passing parameters to the method [`list_dictionary_items`]
60#[derive(Clone, Debug, Default)]
61pub struct ListDictionaryItemsParams {
62    /// Alphanumeric string identifying the service.
63    pub service_id: String,
64    /// Alphanumeric string identifying a Dictionary.
65    pub dictionary_id: String,
66    /// Current page.
67    pub page: Option<i32>,
68    /// Number of records per page.
69    pub per_page: Option<i32>,
70    /// Field on which to sort.
71    pub sort: Option<String>,
72    /// Direction in which to sort results.
73    pub direction: Option<String>
74}
75
76/// struct for passing parameters to the method [`update_dictionary_item`]
77#[derive(Clone, Debug, Default)]
78pub struct UpdateDictionaryItemParams {
79    /// Alphanumeric string identifying the service.
80    pub service_id: String,
81    /// Alphanumeric string identifying a Dictionary.
82    pub dictionary_id: String,
83    /// Item key, maximum 256 characters.
84    pub dictionary_item_key: String,
85    /// Item key, maximum 256 characters.
86    pub item_key: Option<String>,
87    /// Item value, maximum 8000 characters.
88    pub item_value: Option<String>
89}
90
91/// struct for passing parameters to the method [`upsert_dictionary_item`]
92#[derive(Clone, Debug, Default)]
93pub struct UpsertDictionaryItemParams {
94    /// Alphanumeric string identifying the service.
95    pub service_id: String,
96    /// Alphanumeric string identifying a Dictionary.
97    pub dictionary_id: String,
98    /// Item key, maximum 256 characters.
99    pub dictionary_item_key: String,
100    /// Item key, maximum 256 characters.
101    pub item_key: Option<String>,
102    /// Item value, maximum 8000 characters.
103    pub item_value: Option<String>
104}
105
106
107/// struct for typed errors of method [`bulk_update_dictionary_item`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum BulkUpdateDictionaryItemError {
111    UnknownValue(serde_json::Value),
112}
113
114/// struct for typed errors of method [`create_dictionary_item`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum CreateDictionaryItemError {
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`delete_dictionary_item`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum DeleteDictionaryItemError {
125    UnknownValue(serde_json::Value),
126}
127
128/// struct for typed errors of method [`get_dictionary_item`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetDictionaryItemError {
132    UnknownValue(serde_json::Value),
133}
134
135/// struct for typed errors of method [`list_dictionary_items`]
136#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum ListDictionaryItemsError {
139    UnknownValue(serde_json::Value),
140}
141
142/// struct for typed errors of method [`update_dictionary_item`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum UpdateDictionaryItemError {
146    UnknownValue(serde_json::Value),
147}
148
149/// struct for typed errors of method [`upsert_dictionary_item`]
150#[derive(Debug, Clone, Serialize, Deserialize)]
151#[serde(untagged)]
152pub enum UpsertDictionaryItemError {
153    UnknownValue(serde_json::Value),
154}
155
156
157/// Update multiple items in the same dictionary. For faster updates to your service, group your changes into large batches. The maximum batch size is 1000 items. [Contact support](https://support.fastly.com/) to discuss raising this limit.
158pub async fn bulk_update_dictionary_item(configuration: &mut configuration::Configuration, params: BulkUpdateDictionaryItemParams) -> Result<crate::models::InlineResponse200, Error<BulkUpdateDictionaryItemError>> {
159    let local_var_configuration = configuration;
160
161    // unbox the parameters
162    let service_id = params.service_id;
163    let dictionary_id = params.dictionary_id;
164    let bulk_update_dictionary_list_request = params.bulk_update_dictionary_list_request;
165
166
167    let local_var_client = &local_var_configuration.client;
168
169    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/items", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id));
170    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
171
172    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
174    }
175    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
176        let local_var_key = local_var_apikey.key.clone();
177        let local_var_value = match local_var_apikey.prefix {
178            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
179            None => local_var_key,
180        };
181        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
182    };
183    local_var_req_builder = local_var_req_builder.json(&bulk_update_dictionary_list_request);
184
185    let local_var_req = local_var_req_builder.build()?;
186    let local_var_resp = local_var_client.execute(local_var_req).await?;
187
188    if "PATCH" != "GET" && "PATCH" != "HEAD" {
189      let headers = local_var_resp.headers();
190      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
191          Some(v) => v.to_str().unwrap().parse().unwrap(),
192          None => configuration::DEFAULT_RATELIMIT,
193      };
194      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
195          Some(v) => v.to_str().unwrap().parse().unwrap(),
196          None => 0,
197      };
198    }
199
200    let local_var_status = local_var_resp.status();
201    let local_var_content = local_var_resp.text().await?;
202
203    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204        serde_json::from_str(&local_var_content).map_err(Error::from)
205    } else {
206        let local_var_entity: Option<BulkUpdateDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
207        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208        Err(Error::ResponseError(local_var_error))
209    }
210}
211
212/// Create DictionaryItem given service, dictionary ID, item key, and item value.
213pub async fn create_dictionary_item(configuration: &mut configuration::Configuration, params: CreateDictionaryItemParams) -> Result<crate::models::DictionaryItemResponse, Error<CreateDictionaryItemError>> {
214    let local_var_configuration = configuration;
215
216    // unbox the parameters
217    let service_id = params.service_id;
218    let dictionary_id = params.dictionary_id;
219    let item_key = params.item_key;
220    let item_value = params.item_value;
221
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/item", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id));
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
232        let local_var_key = local_var_apikey.key.clone();
233        let local_var_value = match local_var_apikey.prefix {
234            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
235            None => local_var_key,
236        };
237        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
238    };
239    let mut local_var_form_params = std::collections::HashMap::new();
240    if let Some(local_var_param_value) = item_key {
241        local_var_form_params.insert("item_key", local_var_param_value.to_string());
242    }
243    if let Some(local_var_param_value) = item_value {
244        local_var_form_params.insert("item_value", local_var_param_value.to_string());
245    }
246    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
247
248    let local_var_req = local_var_req_builder.build()?;
249    let local_var_resp = local_var_client.execute(local_var_req).await?;
250
251    if "POST" != "GET" && "POST" != "HEAD" {
252      let headers = local_var_resp.headers();
253      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
254          Some(v) => v.to_str().unwrap().parse().unwrap(),
255          None => configuration::DEFAULT_RATELIMIT,
256      };
257      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
258          Some(v) => v.to_str().unwrap().parse().unwrap(),
259          None => 0,
260      };
261    }
262
263    let local_var_status = local_var_resp.status();
264    let local_var_content = local_var_resp.text().await?;
265
266    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
267        serde_json::from_str(&local_var_content).map_err(Error::from)
268    } else {
269        let local_var_entity: Option<CreateDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
270        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
271        Err(Error::ResponseError(local_var_error))
272    }
273}
274
275/// Delete DictionaryItem given service, dictionary ID, and item key.
276pub async fn delete_dictionary_item(configuration: &mut configuration::Configuration, params: DeleteDictionaryItemParams) -> Result<crate::models::InlineResponse200, Error<DeleteDictionaryItemError>> {
277    let local_var_configuration = configuration;
278
279    // unbox the parameters
280    let service_id = params.service_id;
281    let dictionary_id = params.dictionary_id;
282    let dictionary_item_key = params.dictionary_item_key;
283
284
285    let local_var_client = &local_var_configuration.client;
286
287    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/item/{dictionary_item_key}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id), dictionary_item_key=crate::apis::urlencode(dictionary_item_key));
288    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
289
290    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
291        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292    }
293    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
294        let local_var_key = local_var_apikey.key.clone();
295        let local_var_value = match local_var_apikey.prefix {
296            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
297            None => local_var_key,
298        };
299        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
300    };
301
302    let local_var_req = local_var_req_builder.build()?;
303    let local_var_resp = local_var_client.execute(local_var_req).await?;
304
305    if "DELETE" != "GET" && "DELETE" != "HEAD" {
306      let headers = local_var_resp.headers();
307      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
308          Some(v) => v.to_str().unwrap().parse().unwrap(),
309          None => configuration::DEFAULT_RATELIMIT,
310      };
311      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
312          Some(v) => v.to_str().unwrap().parse().unwrap(),
313          None => 0,
314      };
315    }
316
317    let local_var_status = local_var_resp.status();
318    let local_var_content = local_var_resp.text().await?;
319
320    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321        serde_json::from_str(&local_var_content).map_err(Error::from)
322    } else {
323        let local_var_entity: Option<DeleteDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
324        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
325        Err(Error::ResponseError(local_var_error))
326    }
327}
328
329/// Retrieve a single DictionaryItem given service, dictionary ID and item key.
330pub async fn get_dictionary_item(configuration: &mut configuration::Configuration, params: GetDictionaryItemParams) -> Result<crate::models::DictionaryItemResponse, Error<GetDictionaryItemError>> {
331    let local_var_configuration = configuration;
332
333    // unbox the parameters
334    let service_id = params.service_id;
335    let dictionary_id = params.dictionary_id;
336    let dictionary_item_key = params.dictionary_item_key;
337
338
339    let local_var_client = &local_var_configuration.client;
340
341    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/item/{dictionary_item_key}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id), dictionary_item_key=crate::apis::urlencode(dictionary_item_key));
342    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
343
344    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
345        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
346    }
347    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
348        let local_var_key = local_var_apikey.key.clone();
349        let local_var_value = match local_var_apikey.prefix {
350            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
351            None => local_var_key,
352        };
353        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
354    };
355
356    let local_var_req = local_var_req_builder.build()?;
357    let local_var_resp = local_var_client.execute(local_var_req).await?;
358
359    if "GET" != "GET" && "GET" != "HEAD" {
360      let headers = local_var_resp.headers();
361      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
362          Some(v) => v.to_str().unwrap().parse().unwrap(),
363          None => configuration::DEFAULT_RATELIMIT,
364      };
365      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
366          Some(v) => v.to_str().unwrap().parse().unwrap(),
367          None => 0,
368      };
369    }
370
371    let local_var_status = local_var_resp.status();
372    let local_var_content = local_var_resp.text().await?;
373
374    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
375        serde_json::from_str(&local_var_content).map_err(Error::from)
376    } else {
377        let local_var_entity: Option<GetDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
378        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
379        Err(Error::ResponseError(local_var_error))
380    }
381}
382
383/// List of DictionaryItems given service and dictionary ID.
384pub async fn list_dictionary_items(configuration: &mut configuration::Configuration, params: ListDictionaryItemsParams) -> Result<Vec<crate::models::DictionaryItemResponse>, Error<ListDictionaryItemsError>> {
385    let local_var_configuration = configuration;
386
387    // unbox the parameters
388    let service_id = params.service_id;
389    let dictionary_id = params.dictionary_id;
390    let page = params.page;
391    let per_page = params.per_page;
392    let sort = params.sort;
393    let direction = params.direction;
394
395
396    let local_var_client = &local_var_configuration.client;
397
398    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/items", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id));
399    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
400
401    if let Some(ref local_var_str) = page {
402        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
403    }
404    if let Some(ref local_var_str) = per_page {
405        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
406    }
407    if let Some(ref local_var_str) = sort {
408        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
409    }
410    if let Some(ref local_var_str) = direction {
411        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
412    }
413    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
414        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
415    }
416    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
417        let local_var_key = local_var_apikey.key.clone();
418        let local_var_value = match local_var_apikey.prefix {
419            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
420            None => local_var_key,
421        };
422        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
423    };
424
425    let local_var_req = local_var_req_builder.build()?;
426    let local_var_resp = local_var_client.execute(local_var_req).await?;
427
428    if "GET" != "GET" && "GET" != "HEAD" {
429      let headers = local_var_resp.headers();
430      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
431          Some(v) => v.to_str().unwrap().parse().unwrap(),
432          None => configuration::DEFAULT_RATELIMIT,
433      };
434      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
435          Some(v) => v.to_str().unwrap().parse().unwrap(),
436          None => 0,
437      };
438    }
439
440    let local_var_status = local_var_resp.status();
441    let local_var_content = local_var_resp.text().await?;
442
443    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
444        serde_json::from_str(&local_var_content).map_err(Error::from)
445    } else {
446        let local_var_entity: Option<ListDictionaryItemsError> = serde_json::from_str(&local_var_content).ok();
447        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
448        Err(Error::ResponseError(local_var_error))
449    }
450}
451
452/// Update DictionaryItem given service, dictionary ID, item key, and item value.
453pub async fn update_dictionary_item(configuration: &mut configuration::Configuration, params: UpdateDictionaryItemParams) -> Result<crate::models::DictionaryItemResponse, Error<UpdateDictionaryItemError>> {
454    let local_var_configuration = configuration;
455
456    // unbox the parameters
457    let service_id = params.service_id;
458    let dictionary_id = params.dictionary_id;
459    let dictionary_item_key = params.dictionary_item_key;
460    let item_key = params.item_key;
461    let item_value = params.item_value;
462
463
464    let local_var_client = &local_var_configuration.client;
465
466    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/item/{dictionary_item_key}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id), dictionary_item_key=crate::apis::urlencode(dictionary_item_key));
467    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
468
469    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
470        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
471    }
472    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
473        let local_var_key = local_var_apikey.key.clone();
474        let local_var_value = match local_var_apikey.prefix {
475            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
476            None => local_var_key,
477        };
478        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
479    };
480    let mut local_var_form_params = std::collections::HashMap::new();
481    if let Some(local_var_param_value) = item_key {
482        local_var_form_params.insert("item_key", local_var_param_value.to_string());
483    }
484    if let Some(local_var_param_value) = item_value {
485        local_var_form_params.insert("item_value", local_var_param_value.to_string());
486    }
487    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
488
489    let local_var_req = local_var_req_builder.build()?;
490    let local_var_resp = local_var_client.execute(local_var_req).await?;
491
492    if "PATCH" != "GET" && "PATCH" != "HEAD" {
493      let headers = local_var_resp.headers();
494      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
495          Some(v) => v.to_str().unwrap().parse().unwrap(),
496          None => configuration::DEFAULT_RATELIMIT,
497      };
498      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
499          Some(v) => v.to_str().unwrap().parse().unwrap(),
500          None => 0,
501      };
502    }
503
504    let local_var_status = local_var_resp.status();
505    let local_var_content = local_var_resp.text().await?;
506
507    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
508        serde_json::from_str(&local_var_content).map_err(Error::from)
509    } else {
510        let local_var_entity: Option<UpdateDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
511        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
512        Err(Error::ResponseError(local_var_error))
513    }
514}
515
516/// Upsert DictionaryItem given service, dictionary ID, item key, and item value.
517pub async fn upsert_dictionary_item(configuration: &mut configuration::Configuration, params: UpsertDictionaryItemParams) -> Result<crate::models::DictionaryItemResponse, Error<UpsertDictionaryItemError>> {
518    let local_var_configuration = configuration;
519
520    // unbox the parameters
521    let service_id = params.service_id;
522    let dictionary_id = params.dictionary_id;
523    let dictionary_item_key = params.dictionary_item_key;
524    let item_key = params.item_key;
525    let item_value = params.item_value;
526
527
528    let local_var_client = &local_var_configuration.client;
529
530    let local_var_uri_str = format!("{}/service/{service_id}/dictionary/{dictionary_id}/item/{dictionary_item_key}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), dictionary_id=crate::apis::urlencode(dictionary_id), dictionary_item_key=crate::apis::urlencode(dictionary_item_key));
531    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
532
533    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
534        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
535    }
536    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
537        let local_var_key = local_var_apikey.key.clone();
538        let local_var_value = match local_var_apikey.prefix {
539            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
540            None => local_var_key,
541        };
542        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
543    };
544    let mut local_var_form_params = std::collections::HashMap::new();
545    if let Some(local_var_param_value) = item_key {
546        local_var_form_params.insert("item_key", local_var_param_value.to_string());
547    }
548    if let Some(local_var_param_value) = item_value {
549        local_var_form_params.insert("item_value", local_var_param_value.to_string());
550    }
551    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
552
553    let local_var_req = local_var_req_builder.build()?;
554    let local_var_resp = local_var_client.execute(local_var_req).await?;
555
556    if "PUT" != "GET" && "PUT" != "HEAD" {
557      let headers = local_var_resp.headers();
558      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
559          Some(v) => v.to_str().unwrap().parse().unwrap(),
560          None => configuration::DEFAULT_RATELIMIT,
561      };
562      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
563          Some(v) => v.to_str().unwrap().parse().unwrap(),
564          None => 0,
565      };
566    }
567
568    let local_var_status = local_var_resp.status();
569    let local_var_content = local_var_resp.text().await?;
570
571    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
572        serde_json::from_str(&local_var_content).map_err(Error::from)
573    } else {
574        let local_var_entity: Option<UpsertDictionaryItemError> = serde_json::from_str(&local_var_content).ok();
575        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
576        Err(Error::ResponseError(local_var_error))
577    }
578}
579