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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//! Conversations
//!
use super::link::LinkType;
use crate::api::MailchimpApi;
use crate::iter::{BuildIter, MailchimpCollection, ResourceFilter};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::rc::Rc;
///
/// The most recent message in the conversation.
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ConversationMessage {
/// A string that uniquely identifies this message
#[serde(default)]
pub id: String,
/// A string that identifies this message’s conversation
#[serde(default)]
pub conversation_id: String,
/// The unique identifier of the list for this conversation.
#[serde(default)]
pub list_id: String,
/// A label representing the sender of this message.
#[serde(default)]
pub from_label: String,
/// A label representing the email of the sender of this message.
#[serde(default)]
pub from_email: String,
/// The subject of this message.
#[serde(default)]
pub subject: String,
/// The plain-text content of the message.
#[serde(default)]
pub message: String,
/// Whether this message has been marked as read.
#[serde(default)]
pub read: bool,
/// The date and time the message was either sent or received in ISO 8601 format.
#[serde(default)]
pub timestamp: String,
/// A list of link types and descriptions for the API schema documents.
#[serde(default)]
pub _links: Vec<LinkType>,
}
impl Default for ConversationMessage {
fn default() -> Self {
ConversationMessage {
id: "".to_string(),
conversation_id: "".to_string(),
list_id: "".to_string(),
from_label: "".to_string(),
from_email: "".to_string(),
subject: "".to_string(),
message: "".to_string(),
read: true,
timestamp: "".to_string(),
_links: Vec::new(),
}
}
}
///
/// Param Message
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ParamMessage {
/// A label representing the email of the sender of this message
#[serde(default)]
pub from_email: String,
/// The subject of this message.
#[serde(default)]
pub subject: String,
/// The plain-text content of the message.
#[serde(default)]
pub message: String,
/// Whether this message has been marked as read.
#[serde(default)]
pub read: bool,
}
///
/// CollectionConversationMessages
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CollectionConversationMessages {
/// Recent list activity.
#[serde(default)]
pub conversation_messages: Vec<ConversationMessage>,
/// The total number of items matching the query regardless of pagination.
#[serde(default)]
pub total_items: u64,
/// A string that identifies this conversation.
#[serde(default)]
pub conversation_id: String,
/// A list of link types and descriptions for the API schema documents.
#[serde(default)]
pub _links: Vec<LinkType>,
}
impl MailchimpCollection<ConversationMessage> for CollectionConversationMessages {
/// Total Items
fn get_total_items(&self) -> u64 {
self.total_items
}
/// Data
fn get_values(&self) -> Vec<ConversationMessage> {
self.conversation_messages.clone()
}
}
impl Default for CollectionConversationMessages {
fn default() -> Self {
CollectionConversationMessages {
conversation_id: "".to_string(),
conversation_messages: Vec::new(),
total_items: 0,
_links: Vec::new(),
}
}
}
///
/// Messages Filter
///
#[derive(Debug, Clone)]
pub struct MessagesFilter {
/// A comma-separated list of fields to return. Reference
/// parameters of sub-objects with dot notation.
pub fields: Option<String>,
/// A comma-separated list of fields to exclude. Reference
/// parameters of sub-objects with dot notation.
pub exclude_fields: Option<String>,
/// The number of records to return. Default value is 10.
pub count: Option<u64>,
/// The number of records from a collection to skip. Iterating over
/// large collections with this parameter can be slow. Default value is 0..
pub offset: Option<u64>,
/// Restrict the response to messages created before the set time. We recommend ISO 8601
/// time format: 2015-10-21T15:41:36+00:00.
pub before_timestamp: Option<String>,
/// Restrict the response to messages created after the set time. We recommend ISO 8601
/// time format: 2015-10-21T15:41:36+00:00.
pub since_timestamp: Option<String>,
}
impl Default for MessagesFilter {
fn default() -> Self {
MessagesFilter {
fields: None,
exclude_fields: None,
count: Some(50),
offset: Some(0),
before_timestamp: None,
since_timestamp: None,
}
}
}
impl ResourceFilter for MessagesFilter {
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.before_timestamp.is_some() {
payload.insert(
"before_timestamp".to_string(),
format!("{:}", self.before_timestamp.as_ref().unwrap().clone()),
);
}
if self.since_timestamp.is_some() {
payload.insert(
"since_timestamp".to_string(),
format!("{:}", self.since_timestamp.as_ref().unwrap().clone()),
);
}
payload
}
}
///
/// Conversation Builder
///
#[derive(Debug)]
pub struct MessagesBuider {}
impl BuildIter for MessagesBuider {
type Item = ConversationMessage;
type FilterItem = MessagesFilter;
type Collection = CollectionConversationMessages;
///
/// Return a new data updated
///
fn update_item(&self, data: &Self::Item, _: Rc<MailchimpApi>) -> Self::Item {
let in_data = data.clone();
in_data
}
///
/// Update the offset for pagination
///
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
}
}