amazon_spapi/apis/
mod.rs

1use std::error;
2use std::fmt;
3
4#[derive(Debug, Clone)]
5pub struct ResponseContent<T> {
6    pub status: reqwest::StatusCode,
7    pub content: String,
8    pub entity: Option<T>,
9}
10
11#[derive(Debug)]
12pub enum Error<T> {
13    Reqwest(reqwest::Error),
14    Serde(serde_json::Error),
15    Io(std::io::Error),
16    ResponseError(ResponseContent<T>),
17}
18
19impl <T> fmt::Display for Error<T> {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        let (module, e) = match self {
22            Error::Reqwest(e) => ("reqwest", e.to_string()),
23            Error::Serde(e) => ("serde", e.to_string()),
24            Error::Io(e) => ("IO", e.to_string()),
25            Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
26        };
27        write!(f, "error in {}: {}", module, e)
28    }
29}
30
31impl <T: fmt::Debug> error::Error for Error<T> {
32    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
33        Some(match self {
34            Error::Reqwest(e) => e,
35            Error::Serde(e) => e,
36            Error::Io(e) => e,
37            Error::ResponseError(_) => return None,
38        })
39    }
40}
41
42impl <T> From<reqwest::Error> for Error<T> {
43    fn from(e: reqwest::Error) -> Self {
44        Error::Reqwest(e)
45    }
46}
47
48impl <T> From<serde_json::Error> for Error<T> {
49    fn from(e: serde_json::Error) -> Self {
50        Error::Serde(e)
51    }
52}
53
54impl <T> From<std::io::Error> for Error<T> {
55    fn from(e: std::io::Error) -> Self {
56        Error::Io(e)
57    }
58}
59
60pub fn urlencode<T: AsRef<str>>(s: T) -> String {
61    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
62}
63
64pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
65    if let serde_json::Value::Object(object) = value {
66        let mut params = vec![];
67
68        for (key, value) in object {
69            match value {
70                serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
71                    &format!("{}[{}]", prefix, key),
72                    value,
73                )),
74                serde_json::Value::Array(array) => {
75                    for (i, value) in array.iter().enumerate() {
76                        params.append(&mut parse_deep_object(
77                            &format!("{}[{}][{}]", prefix, key, i),
78                            value,
79                        ));
80                    }
81                },
82                serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
83                _ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
84            }
85        }
86
87        return params;
88    }
89
90    unimplemented!("Only objects are supported with style=deepObject")
91}
92
93/// Internal use only
94/// A content type supported by this client.
95#[allow(dead_code)]
96enum ContentType {
97    Json,
98    Text,
99    Unsupported(String)
100}
101
102impl From<&str> for ContentType {
103    fn from(content_type: &str) -> Self {
104        if content_type.starts_with("application") && content_type.contains("json") {
105            return Self::Json;
106        } else if content_type.starts_with("text/plain") {
107            return Self::Text;
108        } else {
109            return Self::Unsupported(content_type.to_string());
110        }
111    }
112}
113
114pub mod configuration;
115
116pub mod shipping;
117pub mod shipping_v2;
118
119pub mod vendor_df_sandbox_api;
120pub mod vendor_df_sandboxtransactionstatus_api;
121
122
123pub mod update_inventory_api;
124
125
126pub mod service_api;
127
128
129pub mod fba_inbound_api;
130pub mod fba_inventory_api;
131pub mod fba_outbound_api;
132
133
134pub mod supply_sources_api;
135
136
137pub mod catalog_items_2020_12_01;
138pub mod catalog_items_2022_04_01;
139pub mod catalog_items_v0;
140
141
142pub mod app_integrations_api;
143
144
145pub mod tokens_api;
146
147
148pub mod queries_api;
149
150
151pub mod listings_items_2020_09_01;
152pub mod listings_items_2021_08_01;
153
154pub mod listings_restrictions_2021_08_01;
155
156pub mod vendor_orders_api;
157
158
159pub mod shipment_invoice_api;
160
161
162pub mod finances_v0;
163pub mod finances_2024_06_19;
164
165
166pub mod sellers_api;
167
168
169pub mod fees_api;
170
171
172pub mod messaging_api;
173
174
175pub mod fulfillment_inbound_2024_03_20;
176pub mod fulfillment_inbound_v0;
177
178
179pub mod replenishment_2022_11_07;
180
181
182pub mod reports_api;
183
184
185pub mod sales_api;
186
187
188pub mod uploads_api;
189
190
191pub mod automotive_api;
192pub mod vehicles_api;
193
194
195
196
197pub mod orders_v0_api;
198pub mod shipment_api;
199
200
201pub mod vendor_transaction_api;
202pub mod vendor_direct_fulfillment_shipping_2021_12_28;
203pub mod vendor_direct_fulfillment_shipping_v1;
204
205pub mod invoices_api;
206
207
208pub mod merchant_fulfillment_api;
209
210
211pub mod feeds_api;
212
213
214pub mod easy_ship_api;
215
216
217pub mod vendor_invoice_api;
218pub mod vendor_shipping_api;
219
220
221pub mod aplus_content_api;
222
223
224pub mod notifications_api;
225
226
227pub mod awd_api;
228
229
230pub mod vendor_payments_api;
231
232
233pub mod applications_api;
234
235
236pub mod accounts_api;
237pub mod transactions_api;
238pub mod transfer_preview_api;
239pub mod transfer_schedule_api;
240
241
242pub mod product_type_definitions_2020_09_01;
243
244
245pub mod product_pricing_2022_05_01;
246pub mod product_pricing_v0;
247
248
249pub mod solicitations_api;
250
251
252pub mod customer_feedback_api;
253
254