amazon_sp_api/models/
product_pricing.rs1use std::collections::HashMap;
2use reqwest::{Method, Response};
3use serde::{Deserialize, Serialize};
4use serde_json::json;
5use crate::error_handling::Errors;
6use crate::general::{Client, CountryMarketplace};
7pub enum CompetitiveSummaryIncludedData {
8 FeaturedBuyingOptions,
9 ReferencePrices,
10 LowestPricedOffers
11}
12impl CompetitiveSummaryIncludedData {
13 fn to_string(&self) -> String {
14 match self {
15 CompetitiveSummaryIncludedData::FeaturedBuyingOptions => "featuredBuyingOptions".to_string(),
16 CompetitiveSummaryIncludedData::ReferencePrices => "referencePrices".to_string(),
17 CompetitiveSummaryIncludedData::LowestPricedOffers => "lowestPricedOffers".to_string()
18 }
19 }
20}
21#[allow(non_snake_case)]
22#[derive(Debug, Deserialize, Serialize, Clone)]
23struct CompetitiveSummaryData {
24 method: String,
25 uri: String,
26 marketplaceId: String,
27 asin: String,
28 includedData: Vec<String>,
29}
30pub struct ProductPricing;
31impl ProductPricing {
32 pub async fn get_featured_offer_expected_price_batch(
46 client: &mut Client,
47 uri: Option<String>, method: String,
50 body: Option<String>,
51 headers: Option<HashMap<String, String>>,
52 market_place: crate::general::CountryMarketplace,
53 sku: Vec<String>,
54 ) -> Result<Response, Errors> {
55 const URL: &str = "/batches/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice";
56 const DEFAULT_URI: &str = "/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice";
57
58 let uri = uri.unwrap_or(DEFAULT_URI.to_string());
59 let mut params: HashMap<String, String> = HashMap::from([("uri".to_string(),uri.clone()), ("method".to_string(), method), ("marketplaceId".to_string(), market_place.details().0.to_string())]);
60 if let Some(o) = body {
61 params.insert("body".to_string(), o);
62 }
63 if let Some(h) = headers {
64 params.insert("headers".to_string(), h.iter().map(|s| serde_json::to_string(&s).unwrap()).collect());
65 }
66 let final_params: Vec<HashMap<String,String>> = sku.iter().map(|small_sku| {
67 let mut ff = params.clone();
68 ff.insert(String::from("sku"), small_sku.clone());
69 ff
70 }).collect();
71
72 client
73 .make_request_w_body(URL, Method::POST, None::<Vec<(String, String)>>, serde_json::to_string(&HashMap::from([("requests".to_string(),final_params)]))?)
74 .await
75 }
76
77 pub async fn get_competitive_summary(
91 client: &mut Client,
92 asin: Vec<String>,
93 market_place: CountryMarketplace,
94 included_data: Vec<CompetitiveSummaryIncludedData>,
95 method: String,
96 uri: Option<String>, ) -> Result<Response, Errors> {
98 const URL: &str = "/batches/products/pricing/2022-05-01/items/competitiveSummary";
99 const DEFAULT_URI: &str = "/products/pricing/2022-05-01/items/competitiveSummary";
100
101 let uri = uri.unwrap_or(DEFAULT_URI.to_string());
102 let data = &included_data.iter().map(|s| s.to_string()).collect::<Vec<String>>();
103
104 let final_result = asin.iter().map(|a| {
105 CompetitiveSummaryData {
106 method: method.clone(),
107 uri: uri.clone(),
108 marketplaceId: market_place.details().0.to_string(),
109 asin: a.clone(),
110 includedData: data.clone(),
111 }
112 }).collect::<Vec<CompetitiveSummaryData>>();
113 let to_send = json!({"requests": final_result});
114 client
115 .make_request_w_body(URL, Method::POST, None::<Vec<(String, String)>>, serde_json::to_string(&to_send)?)
116 .await
117
118 }
119
120
121}