1#[macro_export]
2macro_rules! define_request {
3 (
4 Name => $name: ident;
5 Product => $product: expr;
6 Endpoint => $endpoint: expr;
7 Method => $method: expr;
8 Signed => $signed: expr;
9 Request => { $($req_def:tt)* };
10 Response => { $($resp_def:tt)* };
11 ) => {
12 crate::define_request! {
13 Name => $name;
14 Product => $product;
15 Endpoint => $endpoint;
16 Method => $method;
17 Keyed => false;
18 Signed => $signed;
19 Request => { $($req_def)* };
20 Response => { $($resp_def)* };
21 }
22 };
23 (
24 Name => $name: ident;
25 Product => $product: expr;
26 Endpoint => $endpoint: expr;
27 Method => $method: expr;
28 Keyed => $keyed: expr;
29 Signed => $signed: expr;
30 Request => { $($req_def:tt)* };
31 Response => { $($resp_def:tt)* };
32 ) => {
33 paste::paste! {
34 #[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
35 #[serde(rename_all = "camelCase")]
36 pub struct [<$name Request>] {
37 $($req_def)*
38 }
39
40 #[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
41 #[serde(rename_all = "camelCase")]
42 pub struct [<$name Response>] {
43 $($resp_def)*
44 }
45
46 impl crate::rest::Request for [<$name Request>] {
47 const PRODUCT: crate::rest::Product = $product;
48 const ENDPOINT: &'static str = $endpoint;
49 const METHOD: reqwest::Method = $method;
50 const KEYED: bool = $keyed;
51 const SIGNED: bool = $signed;
52 type Response = [<$name Response>];
53 }
54 }
55 };
56
57 (
58 Name => $name: ident;
59 Product => $product: expr;
60 Endpoint => $endpoint: expr;
61 Method => $method: expr;
62 Signed => $signed: expr;
63 Request => { $($req_def:tt)* };
64 Response => $resp_ty: ty;
65 ) => {
66 crate::define_request! {
67 Name => $name;
68 Product => $product;
69 Endpoint => $endpoint;
70 Method => $method;
71 Keyed => false;
72 Signed => $signed;
73 Request => { $($req_def)* };
74 Response => $resp_ty;
75 }
76 };
77 (
78 Name => $name: ident;
79 Product => $product: expr;
80 Endpoint => $endpoint: expr;
81 Method => $method: expr;
82 Keyed => $keyed: expr;
83 Signed => $signed: expr;
84 Request => { $($req_def:tt)* };
85 Response => $resp_ty: ty;
86 ) => {
87 paste::paste! {
88 #[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
89 #[serde(rename_all = "camelCase")]
90 pub struct [<$name Request>] {
91 $($req_def)*
92 }
93
94 impl crate::rest::Request for [<$name Request>] {
95 const PRODUCT: crate::rest::Product = $product;
96 const ENDPOINT: &'static str = $endpoint;
97 const METHOD: reqwest::Method = $method;
98 const KEYED: bool = $keyed;
99 const SIGNED: bool = $signed;
100 type Response = $resp_ty;
101 }
102 }
103 };
104}