1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::{LIVE_ENDPOINT, SANDBOX_ENDPOINT};
use serde::{de::DeserializeOwned, Serialize};
use std::borrow::Cow;
pub trait Endpoint {
type Query: Serialize;
type Body: Serialize;
type Response: DeserializeOwned;
fn relative_path(&self) -> Cow<str>;
fn method(&self) -> reqwest::Method;
fn query(&self) -> Option<Self::Query> {
None
}
fn body(&self) -> Option<Self::Body> {
None
}
fn full_path(&self, is_sandbox: bool) -> String {
let relative_path = self.relative_path();
assert!(relative_path.starts_with('/'), "relative path must start with '/'");
if is_sandbox {
format!("{}{}", SANDBOX_ENDPOINT, relative_path)
} else {
format!("{}{}", LIVE_ENDPOINT, relative_path)
}
}
}