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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::utils::serde::parse_hashmap_with_null_values;
use crate::utils::serde::parse_intbool;
use super::annotations::Annotations;
use super::common::ID;
use super::tags::Tags;
pub type Entries = Vec<Entry>;
#[derive(Deserialize, Serialize, Debug)]
pub struct Entry {
pub annotations: Option<Annotations>,
pub content: Option<String>,
pub created_at: DateTime<Utc>,
pub domain_name: Option<String>,
#[serde(deserialize_with = "parse_hashmap_with_null_values")]
pub headers: Option<HashMap<String, String>>,
pub http_status: Option<String>,
pub id: ID,
#[serde(deserialize_with = "parse_intbool")]
pub is_archived: bool,
#[serde(deserialize_with = "parse_intbool")]
pub is_public: bool,
#[serde(deserialize_with = "parse_intbool")]
pub is_starred: bool,
pub language: Option<String>,
pub mimetype: Option<String>,
pub origin_url: Option<String>,
pub preview_picture: Option<String>,
pub published_at: Option<DateTime<Utc>>,
pub published_by: Option<Vec<Option<String>>>,
pub reading_time: u32,
pub starred_at: Option<DateTime<Utc>>,
pub tags: Tags,
pub title: Option<String>,
pub uid: Option<String>,
pub updated_at: DateTime<Utc>,
pub url: Option<String>,
pub user_email: String,
pub user_id: ID,
pub user_name: String,
}
#[derive(Deserialize, Debug)]
pub(crate) struct DeletedEntry {
pub annotations: Option<Annotations>,
pub content: Option<String>,
pub created_at: DateTime<Utc>,
pub domain_name: Option<String>,
pub headers: Option<HashMap<String, String>>,
pub http_status: Option<String>,
#[serde(deserialize_with = "parse_intbool")]
pub is_archived: bool,
#[serde(deserialize_with = "parse_intbool")]
pub is_public: bool,
#[serde(deserialize_with = "parse_intbool")]
pub is_starred: bool,
pub language: Option<String>,
pub mimetype: Option<String>,
pub origin_url: Option<String>,
pub preview_picture: Option<String>,
pub published_at: Option<DateTime<Utc>>,
pub published_by: Option<Vec<Option<String>>>,
pub reading_time: u32,
pub starred_at: Option<DateTime<Utc>>,
pub tags: Tags,
pub title: Option<String>,
pub uid: Option<String>,
pub updated_at: DateTime<Utc>,
pub url: Option<String>,
pub user_email: String,
pub user_id: ID,
pub user_name: String,
}
impl From<Entry> for ID {
fn from(entry: Entry) -> Self {
entry.id
}
}
impl From<&Entry> for ID {
fn from(entry: &Entry) -> Self {
entry.id
}
}
#[derive(Deserialize, Debug)]
pub(crate) struct PaginatedEntries {
pub limit: u32,
pub page: u32,
pub pages: u32,
pub total: u32,
#[serde(rename = "_embedded")]
pub embedded: EmbeddedEntries,
}
#[derive(Deserialize, Debug)]
pub(crate) struct EmbeddedEntries {
pub items: Entries,
}
#[derive(Debug)]
pub struct EntriesPage {
pub per_page: u32,
pub current_page: u32,
pub total_pages: u32,
pub total_entries: u32,
pub entries: Entries,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_entry_header_with_string_value() {
let text = r###"{
"is_archived": 1,
"is_starred": 0,
"user_name": "sibben",
"user_email": "detlef@posteo.org",
"user_id": 15568,
"tags": [],
"is_public": false,
"id": 10849650,
"uid": null,
"title": "Klettenwurzel\u00f6l",
"url": "https:\/\/oelerini.com\/klettenwurzeloel",
"hashed_url": "baff1dd17cb2cc15578cb9b6955971dfb8ada45a",
"origin_url": null,
"given_url": "https:\/\/oelerini.com\/klettenwurzeloel",
"hashed_given_url": "baff1dd17cb2cc15578cb9b6955971dfb8ada45a",
"archived_at": "2020-02-12T10:20:58+0100",
"content": "Dummy content",
"created_at": "2019-01-14T18:16:36+0100",
"updated_at": "2020-02-12T10:20:58+0100",
"published_at": null,
"published_by": null,
"starred_at": null,
"annotations": [],
"mimetype": "text\/html",
"language": "de",
"reading_time": 12,
"domain_name": "oelerini.com",
"preview_picture": "https:\/\/oelerini.com\/img\/klettenwurzeloel.jpg",
"http_status": null,
"headers": {
"content-type": "text\/html"
},
"_links": {
"self": {
"href": "\/api\/entries\/10849650"
}
}
}
"###;
let entry: Entry = serde_json::from_str(&text).unwrap();
assert_eq!(
entry.headers,
Some(HashMap::from([("content-type".into(), "text/html".into())]))
);
}
#[test]
fn test_entry_header_with_null_value() {
let text = r###"{
"is_archived": 1,
"is_starred": 0,
"user_name": "sibben",
"user_email": "detlef@posteo.org",
"user_id": 15568,
"tags": [],
"is_public": false,
"id": 10849669,
"uid": null,
"title": "Erfahrungen beim Jurtenaufbau Es geht auch zu zweit!",
"url": "https:\/\/www.jurte.com\/de\/berichte\/ammertal.html",
"hashed_url": "f3c65c41ecef84d95e7a7afc12dbebdd04a8a471",
"origin_url": null,
"given_url": "https:\/\/www.jurte.com\/de\/berichte\/ammertal.html",
"hashed_given_url": "f3c65c41ecef84d95e7a7afc12dbebdd04a8a471",
"archived_at": "2020-02-12T10:20:59+0100",
"content": "wallabag can't retrieve contents for this article. Please <a href=\"http:\/\/doc.wallabag.org\/en\/user\/errors_during_fetching.html#how-can-i-help-to-fix-that\">troubleshoot this issue<\/a>.",
"created_at": "2018-08-23T22:28:58+0200",
"updated_at": "2020-02-12T10:20:59+0100",
"published_at": null,
"published_by": null,
"starred_at": null,
"annotations": [],
"mimetype": null,
"language": null,
"reading_time": 0,
"domain_name": "www.jurte.com",
"preview_picture": "https:\/\/www.jurte.com\/images\/ammertal\/aushub_192.jpg",
"http_status": null,
"headers": {
"content-type": null
},
"_links": {
"self": {
"href": "\/api\/entries\/10849669"
}
}
}
"###;
let entry: Entry = serde_json::from_str(&text).unwrap();
assert_eq!(entry.headers, Some(HashMap::from([])));
}
}