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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use super::enums::SortOrder;
const DEFAULT_SORT_ORDER: SortOrder = SortOrder::Asc;
#[derive(Clone, Debug)]
pub struct ListCardsParameters {
pub cursor: String,
pub customer_id: String,
pub include_disabled: bool,
pub reference_id: String,
pub sort_order: SortOrder,
}
impl ListCardsParameters {
pub fn to_query_string(&self) -> String {
self.to_string()
}
}
impl Default for ListCardsParameters {
fn default() -> Self {
Self {
cursor: Default::default(),
customer_id: Default::default(),
include_disabled: Default::default(),
reference_id: Default::default(),
sort_order: DEFAULT_SORT_ORDER,
}
}
}
impl From<ListCardsParameters> for String {
fn from(list_cards_parameters: ListCardsParameters) -> Self {
list_cards_parameters.to_string()
}
}
impl ToString for ListCardsParameters {
fn to_string(&self) -> String {
let mut params = Vec::new();
if !self.cursor.is_empty() {
params.push(format!("cursor={}", self.cursor));
}
if !self.customer_id.is_empty() {
params.push(format!("customer_id={}", self.customer_id));
}
if self.include_disabled {
params.push(String::from("include_disabled=true"));
}
if !self.reference_id.is_empty() {
params.push(format!("reference_id={}", self.reference_id));
}
if self.sort_order != DEFAULT_SORT_ORDER {
params.push(format!(
"sort_order={}",
serde_json::to_string(&self.sort_order).unwrap()
));
}
if params.is_empty() {
String::new()
} else {
format!("?{}", params.join("&"))
}
}
}