gateio_rs/http/
request.rs1use crate::http::{Credentials, Method};
2
3#[derive(PartialEq, Eq, Debug)]
5pub struct Request {
6 pub(crate) method: Method,
7 pub(crate) path: String,
8 pub(crate) params: Vec<(String, String)>,
9 pub(crate) payload: String,
10 pub(crate) x_gate_exp_time: Option<u128>,
11 pub(crate) credentials: Option<Credentials>,
12 pub(crate) sign: bool,
13}
14
15impl Request {
16 pub fn method(&self) -> &Method {
18 &self.method
19 }
20 pub fn path(&self) -> &str {
22 &self.path
23 }
24 pub fn params(&self) -> &[(String, String)] {
26 &self.params
27 }
28 pub fn payload(&self) -> &str {
30 &self.payload
31 }
32 pub fn x_gate_exp_time(&self) -> &Option<u128> {
34 &self.x_gate_exp_time
35 }
36 pub fn credentials(&self) -> &Option<Credentials> {
38 &self.credentials
39 }
40 pub fn sign(&self) -> &bool {
42 &self.sign
43 }
44}
45
46pub struct RequestBuilder {
51 method: Method,
52 path: String,
53 params: Vec<(String, String)>,
54 payload: String,
55 credentials: Option<Credentials>,
56 x_gate_exp_time: Option<u128>,
57 sign: bool,
58}
59
60impl RequestBuilder {
61 pub fn new(method: Method, path: &str) -> Self {
63 Self {
64 method,
65 path: path.to_owned(),
66 params: vec![],
67 payload: "".to_owned(),
68 x_gate_exp_time: None,
69 credentials: None,
70 sign: false,
71 }
72 }
73
74 pub fn params<'a>(mut self, params: impl IntoIterator<Item = (&'a str, &'a str)>) -> Self {
78 self.params.extend(
79 params
80 .into_iter()
81 .map(|param| (param.0.to_owned(), param.1.to_owned())),
82 );
83 self
84 }
85 pub fn payload(mut self, payload: &str) -> Self {
87 self.payload = payload.to_owned();
88 self
89 }
90
91 pub fn credentials(mut self, credentials: Credentials) -> Self {
93 self.credentials = Some(credentials);
94 self
95 }
96
97 pub fn x_gate_exp_time(mut self, x_gate_exp_time: u128) -> Self {
99 self.x_gate_exp_time = Some(x_gate_exp_time);
100 self
101 }
102
103 pub fn sign(mut self) -> Self {
105 self.sign = true;
106 self
107 }
108}
109
110impl From<RequestBuilder> for Request {
111 fn from(builder: RequestBuilder) -> Request {
112 Request {
113 method: builder.method,
114 path: builder.path,
115 params: builder.params,
116 payload: builder.payload,
117 x_gate_exp_time: builder.x_gate_exp_time,
118 credentials: builder.credentials,
119 sign: builder.sign,
120 }
121 }
122}