amazon-spapi 2.0.3

A Rust client library for Amazon Selling Partner API (SP-API)
Documentation
/*
 * The Selling Partner API for Automotive.
 *
 * The Selling Partner API for Automotive provides programmatic access to information needed by selling partners to provide compatibility information about their listed products.
 *
 * The version of the OpenAPI document: 2024-11-01
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`get_vehicles`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVehiclesError {
    Status400(models::vehicles_2024_11_01::ErrorList),
    Status403(models::vehicles_2024_11_01::ErrorList),
    Status404(models::vehicles_2024_11_01::ErrorList),
    Status413(models::vehicles_2024_11_01::ErrorList),
    Status415(models::vehicles_2024_11_01::ErrorList),
    Status429(models::vehicles_2024_11_01::ErrorList),
    Status500(models::vehicles_2024_11_01::ErrorList),
    Status503(models::vehicles_2024_11_01::ErrorList),
    UnknownValue(serde_json::Value),
}


/// Get the latest collection of vehicles
pub 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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_marketplace_id = marketplace_id;
    let p_vehicle_type = vehicle_type;
    let p_page_token = page_token;
    let p_updated_after = updated_after;

    let uri_str = format!("{}/catalog/2024-11-01/automotive/vehicles", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_page_token {
        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
    }
    req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
    req_builder = req_builder.query(&[("vehicleType", &p_vehicle_type.to_string())]);
    if let Some(ref param_value) = p_updated_after {
        req_builder = req_builder.query(&[("updatedAfter", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            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`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetVehiclesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}