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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use super::link::LinkType;
use crate::api::MailchimpApi;
use crate::iter::{BuildIter, MailchimpCollection, ResourceFilter};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListGrowthHistoryType {
#[serde(default)]
pub list_id: String,
#[serde(default)]
pub month: String,
#[serde(default)]
pub existing: u64,
#[serde(default)]
pub imports: u64,
#[serde(default)]
pub optins: u64,
#[serde(default)]
pub _links: Vec<LinkType>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CollectionListGrowthHistory {
#[serde(default)]
pub list_id: String,
#[serde(default)]
pub history: Vec<ListGrowthHistoryType>,
#[serde(default)]
pub total_items: u64,
#[serde(default)]
pub _links: Vec<LinkType>,
}
impl MailchimpCollection<ListGrowthHistoryType> for CollectionListGrowthHistory {
fn get_total_items(&self) -> u64 {
self.total_items
}
fn get_values(&self) -> Vec<ListGrowthHistoryType> {
self.history.clone()
}
}
impl Default for CollectionListGrowthHistory {
fn default() -> Self {
CollectionListGrowthHistory {
list_id: String::new(),
history: Vec::new(),
total_items: 0,
_links: Vec::new(),
}
}
}
#[derive(Debug, Clone)]
pub struct ListGrowthHistoryFilter {
pub fields: Option<String>,
pub exclude_fields: Option<String>,
pub count: Option<u64>,
pub offset: Option<u64>,
pub sort_field: Option<String>,
pub sort_dir: Option<String>,
}
impl Default for ListGrowthHistoryFilter {
fn default() -> Self {
ListGrowthHistoryFilter {
fields: None,
exclude_fields: None,
count: Some(50),
offset: Some(0),
sort_field: None,
sort_dir: None,
}
}
}
impl ResourceFilter for ListGrowthHistoryFilter {
fn build_payload(&self) -> HashMap<String, String> {
let mut payload = HashMap::new();
if self.fields.is_some() {
payload.insert("fields".to_string(), self.fields.as_ref().unwrap().clone());
}
if self.exclude_fields.is_some() {
payload.insert(
"exclude_fields".to_string(),
self.exclude_fields.as_ref().unwrap().clone(),
);
}
if self.count.is_some() {
payload.insert(
"count".to_string(),
format!("{:}", self.count.as_ref().unwrap().clone()),
);
}
if self.offset.is_some() {
payload.insert(
"offset".to_string(),
format!("{:}", self.offset.as_ref().unwrap().clone()),
);
}
if self.sort_field.is_some() {
payload.insert(
"sort_field".to_string(),
format!("{:}", self.sort_field.as_ref().unwrap().clone()),
);
}
if self.sort_dir.is_some() {
payload.insert(
"sort_dir".to_string(),
format!("{:}", self.sort_dir.as_ref().unwrap().clone()),
);
}
payload
}
}
#[derive(Debug)]
pub struct ListGrowthHistoryBuilder {}
impl BuildIter for ListGrowthHistoryBuilder {
type Item = ListGrowthHistoryType;
type FilterItem = ListGrowthHistoryFilter;
type Collection = CollectionListGrowthHistory;
fn update_item(&self, data: &Self::Item, _: &MailchimpApi) -> Self::Item {
let in_data = data.clone();
in_data
}
fn update_filter_offset(&self, filter: &Self::FilterItem) -> Self::FilterItem {
let mut f = filter.clone();
f.offset = Some(f.count.unwrap() + f.offset.unwrap());
f
}
}