amazon_spapi/apis/
uploads_2020_11_01.rs

1/*
2 * Selling Partner API for Uploads
3 *
4 * The Uploads API lets you upload files that you can programmatically access using other Selling Partner APIs, such as the A+ Content API and the Messaging API.
5 *
6 * The version of the OpenAPI document: 2020-11-01
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`create_upload_destination_for_resource`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateUploadDestinationForResourceError {
22    Status400(models::uploads_2020_11_01::CreateUploadDestinationResponse),
23    Status403(models::uploads_2020_11_01::CreateUploadDestinationResponse),
24    Status404(models::uploads_2020_11_01::CreateUploadDestinationResponse),
25    Status413(models::uploads_2020_11_01::CreateUploadDestinationResponse),
26    Status415(models::uploads_2020_11_01::CreateUploadDestinationResponse),
27    Status429(models::uploads_2020_11_01::CreateUploadDestinationResponse),
28    Status500(models::uploads_2020_11_01::CreateUploadDestinationResponse),
29    Status503(models::uploads_2020_11_01::CreateUploadDestinationResponse),
30    UnknownValue(serde_json::Value),
31}
32
33
34/// Creates an upload destination, returning the information required to upload a file to the destination and to programmatically access the file.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
35pub async fn create_upload_destination_for_resource(configuration: &configuration::Configuration, marketplace_ids: Vec<String>, content_md5: &str, resource: &str, content_type: Option<&str>) -> Result<models::uploads_2020_11_01::CreateUploadDestinationResponse, Error<CreateUploadDestinationForResourceError>> {
36    // add a prefix to parameters to efficiently prevent name collisions
37    let p_marketplace_ids = marketplace_ids;
38    let p_content_md5 = content_md5;
39    let p_resource = resource;
40    let p_content_type = content_type;
41
42    let uri_str = format!("{}/uploads/2020-11-01/uploadDestinations/{resource}", configuration.base_path, resource=crate::apis::urlencode(p_resource));
43    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
44
45    req_builder = match "csv" {
46        "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
47        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
48    };
49    req_builder = req_builder.query(&[("contentMD5", &p_content_md5.to_string())]);
50    if let Some(ref param_value) = p_content_type {
51        req_builder = req_builder.query(&[("contentType", &param_value.to_string())]);
52    }
53    if let Some(ref user_agent) = configuration.user_agent {
54        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55    }
56
57    let req = req_builder.build()?;
58    let resp = configuration.client.execute(req).await?;
59
60    let status = resp.status();
61    let content_type = resp
62        .headers()
63        .get("content-type")
64        .and_then(|v| v.to_str().ok())
65        .unwrap_or("application/octet-stream");
66    let content_type = super::ContentType::from(content_type);
67
68    if !status.is_client_error() && !status.is_server_error() {
69        let content = resp.text().await?;
70        match content_type {
71            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
72            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::uploads_2020_11_01::CreateUploadDestinationResponse`"))),
73            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::uploads_2020_11_01::CreateUploadDestinationResponse`")))),
74        }
75    } else {
76        let content = resp.text().await?;
77        let entity: Option<CreateUploadDestinationForResourceError> = serde_json::from_str(&content).ok();
78        Err(Error::ResponseError(ResponseContent { status, content, entity }))
79    }
80}
81