amazon_spapi/client/
endpoint.rs1use std::fmt;
2
3#[derive(Clone)]
5pub struct ApiEndpoint {
6 pub version: &'static str,
8 pub path: &'static str,
10 pub path_params: Option<Vec<(&'static str, String)>>,
12 pub method: ApiMethod,
14 pub rate: f64,
16 pub burst: u32,
18}
19
20impl ApiEndpoint {
21 pub fn rate_limit_key(&self) -> String {
23 format!("{}:{}", self.version, self.path)
24 }
25
26 pub fn get_path(&self) -> String {
28 let mut path = self.path.to_string();
29 if let Some(path_params) = &self.path_params {
30 for (key, value) in path_params {
31 let placeholder = format!("{{{}}}", key);
32 path = path.replace(&placeholder, value);
33 }
34 }
35 path
36 }
37}
38
39#[derive(Debug, Clone, PartialEq, Eq)]
41pub enum ApiMethod {
42 Get,
43 Post,
44 Put,
45 Delete,
46 Patch,
47}
48
49impl fmt::Display for ApiMethod {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 match self {
52 ApiMethod::Get => write!(f, "GET"),
53 ApiMethod::Post => write!(f, "POST"),
54 ApiMethod::Put => write!(f, "PUT"),
55 ApiMethod::Delete => write!(f, "DELETE"),
56 ApiMethod::Patch => write!(f, "PATCH"),
57 }
58 }
59}