amazon_spapi/apis/
vehicles_2024_11_01.rs

1/*
2 * The Selling Partner API for Automotive.
3 *
4 * The Selling Partner API for Automotive provides programmatic access to information needed by selling partners to provide compatibility information about their listed products.
5 *
6 * The version of the OpenAPI document: 2024-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 [`get_vehicles`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetVehiclesError {
22    Status400(models::vehicles_2024_11_01::ErrorList),
23    Status403(models::vehicles_2024_11_01::ErrorList),
24    Status404(models::vehicles_2024_11_01::ErrorList),
25    Status413(models::vehicles_2024_11_01::ErrorList),
26    Status415(models::vehicles_2024_11_01::ErrorList),
27    Status429(models::vehicles_2024_11_01::ErrorList),
28    Status500(models::vehicles_2024_11_01::ErrorList),
29    Status503(models::vehicles_2024_11_01::ErrorList),
30    UnknownValue(serde_json::Value),
31}
32
33
34/// Get the latest collection of vehicles
35pub async fn get_vehicles(configuration: &configuration::Configuration, marketplace_id: &str, vehicle_type: &str, page_token: Option<&str>, updated_after: Option<&str>) -> Result<models::vehicles_2024_11_01::VehiclesResponse, Error<GetVehiclesError>> {
36    // add a prefix to parameters to efficiently prevent name collisions
37    let p_marketplace_id = marketplace_id;
38    let p_vehicle_type = vehicle_type;
39    let p_page_token = page_token;
40    let p_updated_after = updated_after;
41
42    let uri_str = format!("{}/catalog/2024-11-01/automotive/vehicles", configuration.base_path);
43    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45    if let Some(ref param_value) = p_page_token {
46        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
47    }
48    req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
49    req_builder = req_builder.query(&[("vehicleType", &p_vehicle_type.to_string())]);
50    if let Some(ref param_value) = p_updated_after {
51        req_builder = req_builder.query(&[("updatedAfter", &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::vehicles_2024_11_01::VehiclesResponse`"))),
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::vehicles_2024_11_01::VehiclesResponse`")))),
74        }
75    } else {
76        let content = resp.text().await?;
77        let entity: Option<GetVehiclesError> = serde_json::from_str(&content).ok();
78        Err(Error::ResponseError(ResponseContent { status, content, entity }))
79    }
80}
81