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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
use crate::error::{PixivError, Result};
use crate::models::app::{
Comment, CommentsResponse, ContentType, Duration, Filter, FollowRestrict, IllustBookmarkResponse,
IllustDetail, IllustFollowResponse, RankingMode, RankingResponse, RecommendedResponse,
SearchIllustResponse, SearchTarget, Sort, TrendingTagsResponse, UgoiraMetadataResponse,
UserFollowingResponse, UserFollowerResponse, UserMypixivResponse,
};
use crate::network::HttpClient;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::debug;
/// App API client for interacting with Pixiv App API
#[derive(Debug, Clone)]
pub struct AppClient {
/// HTTP client
http_client: HttpClient,
/// API base URL
base_url: String,
}
impl AppClient {
/// Create new App API client instance
pub fn new(http_client: HttpClient) -> Self {
Self {
http_client,
base_url: "https://app-api.pixiv.net".to_string(),
}
}
/// Set API base URL
pub fn set_base_url(&mut self, url: String) {
self.base_url = url;
}
/// Get API base URL
pub fn base_url(&self) -> &str {
&self.base_url
}
/// Get illustration details
///
/// # Arguments
/// * `illust_id` - Illustration ID
///
/// # Returns
/// Returns illustration detail information
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let detail = client.illust_detail(12345678).await?;
/// ```
pub async fn illust_detail(&self, illust_id: u64) -> Result<IllustDetail> {
debug!(illust_id = %illust_id, "Fetching illustration detail");
let url = format!("{}/v1/illust/detail", self.base_url);
let params = [("illust_id", illust_id.to_string())];
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let detail: IllustDetail = serde_json::from_str(&text)?;
Ok(detail)
}
/// Get illustration ranking
///
/// # Arguments
/// * `mode` - Ranking mode
/// * `filter` - Filter
/// * `date` - Date (format: YYYY-MM-DD)
/// * `offset` - Offset
///
/// # Returns
/// Returns ranking response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let ranking = client.illust_ranking(
/// RankingMode::Day,
/// Filter::ForIOS,
/// Some("2023-01-01"),
/// Some(0)
/// ).await?;
/// ```
pub async fn illust_ranking(
&self,
mode: RankingMode,
filter: Filter,
date: Option<&str>,
offset: Option<u32>,
) -> Result<RankingResponse> {
debug!(
mode = %mode.to_string(),
filter = %filter.to_string(),
date = ?date,
offset = ?offset,
"Fetching illustration ranking"
);
let url = format!("{}/v1/illust/ranking", self.base_url);
let mut params = Vec::new();
params.push(("mode", mode.to_string()));
params.push(("filter", filter.to_string()));
if let Some(date) = date {
params.push(("date", date.to_string()));
}
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let ranking: RankingResponse = serde_json::from_str(&text)?;
Ok(ranking)
}
/// Get recommended illustrations
///
/// # Arguments
/// * `content_type` - Content type
/// * `include_ranking_label` - Whether to include ranking label
/// * `filter` - Filter
/// * `max_bookmark_id_for_recommend` - Maximum bookmark ID for recommendation
/// * `min_bookmark_id_for_recent_illust` - Minimum bookmark ID for recent illustrations
/// * `offset` - Offset
/// * `include_ranking_illusts` - Whether to include ranking illustrations
/// * `bookmark_illust_ids` - List of bookmarked illustration IDs
/// * `viewed` - List of viewed illustration IDs
///
/// # Returns
/// Returns recommendation response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let recommended = client.illust_recommended(
/// ContentType::Illust,
/// true,
/// Filter::ForIOS,
/// None,
/// None,
/// None,
/// None,
/// None,
/// None
/// ).await?;
/// ```
pub async fn illust_recommended(
&self,
content_type: ContentType,
include_ranking_label: bool,
filter: Filter,
max_bookmark_id_for_recommend: Option<u64>,
min_bookmark_id_for_recent_illust: Option<u64>,
offset: Option<u32>,
include_ranking_illusts: Option<bool>,
bookmark_illust_ids: Option<Vec<u64>>,
viewed: Option<Vec<String>>,
) -> Result<RecommendedResponse> {
debug!(
content_type = %content_type.to_string(),
include_ranking_label = %include_ranking_label,
filter = %filter.to_string(),
max_bookmark_id_for_recommend = ?max_bookmark_id_for_recommend,
min_bookmark_id_for_recent_illust = ?min_bookmark_id_for_recent_illust,
offset = ?offset,
include_ranking_illusts = ?include_ranking_illusts,
bookmark_illust_ids = ?bookmark_illust_ids,
viewed = ?viewed,
"Fetching recommended illustrations"
);
let url = format!("{}/v1/illust/recommended", self.base_url);
let mut params = Vec::new();
params.push(("content_type".to_string(), content_type.to_string()));
params.push(("include_ranking_label".to_string(), include_ranking_label.to_string()));
params.push(("filter".to_string(), filter.to_string()));
if let Some(max_bookmark_id_for_recommend) = max_bookmark_id_for_recommend {
params.push(("max_bookmark_id_for_recommend".to_string(), max_bookmark_id_for_recommend.to_string()));
}
if let Some(min_bookmark_id_for_recent_illust) = min_bookmark_id_for_recent_illust {
params.push(("min_bookmark_id_for_recent_illust".to_string(), min_bookmark_id_for_recent_illust.to_string()));
}
if let Some(offset) = offset {
params.push(("offset".to_string(), offset.to_string()));
}
if let Some(include_ranking_illusts) = include_ranking_illusts {
params.push(("include_ranking_illusts".to_string(), include_ranking_illusts.to_string()));
}
if let Some(bookmark_illust_ids) = bookmark_illust_ids {
let ids = bookmark_illust_ids
.iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(",");
params.push(("bookmark_illust_ids".to_string(), ids));
}
if let Some(viewed) = viewed {
for (i, viewed_id) in viewed.iter().enumerate() {
let key = format!("viewed[{}]", i);
params.push((key, viewed_id.to_string()));
}
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let recommended: RecommendedResponse = serde_json::from_str(&text)?;
Ok(recommended)
}
/// Search illustrations
///
/// # Arguments
/// * `word` - Search keyword
/// * `search_target` - Search target
/// * `sort` - Sort method
/// * `duration` - Search duration
/// * `start_date` - Start date (format: YYYY-MM-DD)
/// * `end_date` - End date (format: YYYY-MM-DD)
/// * `filter` - Filter
/// * `search_ai_type` - AI type (0: Filter AI-generated works, 1: Show AI-generated works)
/// * `offset` - Offset
///
/// # Returns
/// Returns search response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let search_result = client.search_illust(
/// "original",
/// SearchTarget::PartialMatchForTags,
/// Sort::DateDesc,
/// None,
/// None,
/// None,
/// Filter::ForIOS,
/// None,
/// None
/// ).await?;
/// ```
pub async fn search_illust(
&self,
word: &str,
search_target: SearchTarget,
sort: Sort,
duration: Option<Duration>,
start_date: Option<&str>,
end_date: Option<&str>,
filter: Filter,
search_ai_type: Option<u32>,
offset: Option<u32>,
) -> Result<SearchIllustResponse> {
debug!(
word = %word,
search_target = %search_target.to_string(),
sort = %sort.to_string(),
duration = ?duration,
start_date = ?start_date,
end_date = ?end_date,
filter = %filter.to_string(),
search_ai_type = ?search_ai_type,
offset = ?offset,
"Searching illustrations"
);
let url = format!("{}/v1/search/illust", self.base_url);
let mut params = Vec::new();
params.push(("word", word.to_string()));
params.push(("search_target", search_target.to_string()));
params.push(("sort", sort.to_string()));
params.push(("filter", filter.to_string()));
if let Some(duration) = duration {
params.push(("duration", duration.to_string()));
}
if let Some(start_date) = start_date {
params.push(("start_date", start_date.to_string()));
}
if let Some(end_date) = end_date {
params.push(("end_date", end_date.to_string()));
}
if let Some(search_ai_type) = search_ai_type {
params.push(("search_ai_type", search_ai_type.to_string()));
}
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let search_result: SearchIllustResponse = serde_json::from_str(&text)?;
Ok(search_result)
}
/// Get illustrations from followed users
///
/// # Arguments
/// * `restrict` - Follow restriction (public/private)
/// * `offset` - Offset
///
/// # Returns
/// Returns response with illustrations from followed users
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let follow_illusts = client.illust_follow(
/// FollowRestrict::Public,
/// Some(0)
/// ).await?;
/// ```
pub async fn illust_follow(
&self,
restrict: FollowRestrict,
offset: Option<u32>,
) -> Result<IllustFollowResponse> {
debug!(
restrict = %restrict.to_string(),
offset = ?offset,
"Fetching follow illustrations"
);
let url = format!("{}/v2/illust/follow", self.base_url);
let mut params = Vec::new();
params.push(("restrict", restrict.to_string()));
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let follow_response: IllustFollowResponse = serde_json::from_str(&text)?;
Ok(follow_response)
}
/// Get illustration comments
///
/// # Arguments
/// * `illust_id` - Illustration ID
/// * `offset` - Offset
/// * `include_total_comments` - Whether to include total comment count
///
/// # Returns
/// Returns comment response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let comments = client.illust_comments(
/// 12345678,
/// Some(0),
/// Some(true)
/// ).await?;
/// ```
pub async fn illust_comments(
&self,
illust_id: u64,
offset: Option<u32>,
include_total_comments: Option<bool>,
) -> Result<CommentsResponse> {
debug!(
illust_id = %illust_id,
offset = ?offset,
include_total_comments = ?include_total_comments,
"Fetching illustration comments"
);
let url = format!("{}/v1/illust/comments", self.base_url);
let mut params = Vec::new();
params.push(("illust_id", illust_id.to_string()));
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
if let Some(include_total_comments) = include_total_comments {
params.push(("include_total_comments", include_total_comments.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let comments: CommentsResponse = serde_json::from_str(&text)?;
Ok(comments)
}
/// Get user following list
///
/// # Arguments
/// * `user_id` - User ID
/// * `restrict` - Follow restriction (public/private)
/// * `offset` - Offset
///
/// # Returns
/// Returns user following response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let following = client.user_following(
/// 12345678,
/// FollowRestrict::Public,
/// Some(0)
/// ).await?;
/// ```
pub async fn user_following(
&self,
user_id: u64,
restrict: FollowRestrict,
offset: Option<u32>,
) -> Result<UserFollowingResponse> {
debug!(
user_id = %user_id,
restrict = %restrict.to_string(),
offset = ?offset,
"Fetching user following"
);
let url = format!("{}/v1/user/following", self.base_url);
let mut params = Vec::new();
params.push(("user_id", user_id.to_string()));
params.push(("restrict", restrict.to_string()));
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let following: UserFollowingResponse = serde_json::from_str(&text)?;
Ok(following)
}
/// Get user followers list
///
/// # Arguments
/// * `user_id` - User ID
/// * `filter` - Filter
/// * `offset` - Offset
///
/// # Returns
/// Returns user followers response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let followers = client.user_follower(
/// 12345678,
/// Filter::ForIOS,
/// Some(0)
/// ).await?;
/// ```
pub async fn user_follower(
&self,
user_id: u64,
filter: Filter,
offset: Option<u32>,
) -> Result<UserFollowerResponse> {
debug!(
user_id = %user_id,
filter = %filter.to_string(),
offset = ?offset,
"Fetching user followers"
);
let url = format!("{}/v1/user/follower", self.base_url);
let mut params = Vec::new();
params.push(("user_id", user_id.to_string()));
params.push(("filter", filter.to_string()));
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let followers: UserFollowerResponse = serde_json::from_str(&text)?;
Ok(followers)
}
/// Get user mypixiv list
///
/// # Arguments
/// * `user_id` - User ID
/// * `offset` - Offset
///
/// # Returns
/// Returns user mypixiv response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let mypixiv = client.user_mypixiv(
/// 12345678,
/// Some(0)
/// ).await?;
/// ```
pub async fn user_mypixiv(
&self,
user_id: u64,
offset: Option<u32>,
) -> Result<UserMypixivResponse> {
debug!(
user_id = %user_id,
offset = ?offset,
"Fetching user mypixiv"
);
let url = format!("{}/v1/user/mypixiv", self.base_url);
let mut params = Vec::new();
params.push(("user_id", user_id.to_string()));
if let Some(offset) = offset {
params.push(("offset", offset.to_string()));
}
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let mypixiv: UserMypixivResponse = serde_json::from_str(&text)?;
Ok(mypixiv)
}
/// Add illustration bookmark
///
/// # Arguments
/// * `illust_id` - Illustration ID
/// * `restrict` - Bookmark restriction (public/private)
/// * `tags` - Tag list
///
/// # Returns
/// Returns bookmark response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let result = client.illust_bookmark_add(
/// 12345678,
/// FollowRestrict::Public,
/// Some(vec!["tag1".to_string(), "tag2".to_string()])
/// ).await?;
/// ```
pub async fn illust_bookmark_add(
&self,
illust_id: u64,
restrict: FollowRestrict,
tags: Option<Vec<String>>,
) -> Result<IllustBookmarkResponse> {
debug!(
illust_id = %illust_id,
restrict = %restrict.to_string(),
tags = ?tags,
"Adding illustration bookmark"
);
let url = format!("{}/v2/illust/bookmark/add", self.base_url);
let mut data = HashMap::new();
data.insert("illust_id", illust_id.to_string());
data.insert("restrict", restrict.to_string());
if let Some(tags) = tags {
data.insert("tags", tags.join(" "));
}
let response = self
.http_client
.send_request(reqwest::Method::POST, &url, Some(&data))
.await?;
let text = response.text().await?;
let bookmark_response: IllustBookmarkResponse = serde_json::from_str(&text)?;
Ok(bookmark_response)
}
/// Delete illustration bookmark
///
/// # Arguments
/// * `illust_id` - Illustration ID
///
/// # Returns
/// Returns bookmark response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let result = client.illust_bookmark_delete(12345678).await?;
/// ```
pub async fn illust_bookmark_delete(
&self,
illust_id: u64,
) -> Result<IllustBookmarkResponse> {
debug!(
illust_id = %illust_id,
"Deleting illustration bookmark"
);
let url = format!("{}/v1/illust/bookmark/delete", self.base_url);
let mut data = HashMap::new();
data.insert("illust_id", illust_id.to_string());
let response = self
.http_client
.send_request(reqwest::Method::POST, &url, Some(&data))
.await?;
let text = response.text().await?;
let bookmark_response: IllustBookmarkResponse = serde_json::from_str(&text)?;
Ok(bookmark_response)
}
/// Get trending tags
///
/// # Arguments
/// * `filter` - Filter
///
/// # Returns
/// Returns trending tags response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let trending = client.trending_tags_illust(Filter::ForIOS).await?;
/// ```
pub async fn trending_tags_illust(
&self,
filter: Filter,
) -> Result<TrendingTagsResponse> {
debug!(
filter = %filter.to_string(),
"Fetching trending tags"
);
let url = format!("{}/v1/trending-tags/illust", self.base_url);
let params = [("filter", filter.to_string())];
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let trending: TrendingTagsResponse = serde_json::from_str(&text)?;
Ok(trending)
}
/// Get Ugoira metadata
///
/// # Arguments
/// * `illust_id` - Illustration ID
///
/// # Returns
/// Returns Ugoira metadata response
///
/// # Example
/// ```rust
/// let client = AppClient::new(http_client);
/// let metadata = client.ugoira_metadata(12345678).await?;
/// ```
pub async fn ugoira_metadata(
&self,
illust_id: u64,
) -> Result<UgoiraMetadataResponse> {
debug!(
illust_id = %illust_id,
"Fetching ugoira metadata"
);
let url = format!("{}/v1/ugoira/metadata", self.base_url);
let params = [("illust_id", illust_id.to_string())];
let response = self
.http_client
.send_request(reqwest::Method::GET, &url, Some(¶ms))
.await?;
let text = response.text().await?;
let metadata: UgoiraMetadataResponse = serde_json::from_str(&text)?;
Ok(metadata)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_search_target_to_string() {
assert_eq!(SearchTarget::PartialMatchForTags.to_string(), "partial_match_for_tags");
assert_eq!(SearchTarget::ExactMatchForTags.to_string(), "exact_match_for_tags");
assert_eq!(SearchTarget::TitleAndCaption.to_string(), "title_and_caption");
assert_eq!(SearchTarget::Keyword.to_string(), "keyword");
}
#[test]
fn test_sort_to_string() {
assert_eq!(Sort::DateDesc.to_string(), "date_desc");
assert_eq!(Sort::DateAsc.to_string(), "date_asc");
assert_eq!(Sort::PopularDesc.to_string(), "popular_desc");
}
#[test]
fn test_ranking_mode_to_string() {
assert_eq!(RankingMode::Day.to_string(), "day");
assert_eq!(RankingMode::Week.to_string(), "week");
assert_eq!(RankingMode::Month.to_string(), "month");
assert_eq!(RankingMode::DayMale.to_string(), "day_male");
assert_eq!(RankingMode::DayFemale.to_string(), "day_female");
assert_eq!(RankingMode::WeekOriginal.to_string(), "week_original");
assert_eq!(RankingMode::WeekRookie.to_string(), "week_rookie");
assert_eq!(RankingMode::DayManga.to_string(), "day_manga");
assert_eq!(RankingMode::DayR18.to_string(), "day_r18");
assert_eq!(RankingMode::DayMaleR18.to_string(), "day_male_r18");
assert_eq!(RankingMode::DayFemaleR18.to_string(), "day_female_r18");
assert_eq!(RankingMode::WeekR18.to_string(), "week_r18");
assert_eq!(RankingMode::WeekR18g.to_string(), "week_r18g");
}
#[test]
fn test_content_type_to_string() {
assert_eq!(ContentType::Illust.to_string(), "illust");
assert_eq!(ContentType::Manga.to_string(), "manga");
}
#[test]
fn test_filter_to_string() {
assert_eq!(Filter::ForIOS.to_string(), "for_ios");
assert_eq!(Filter::None.to_string(), "");
}
#[test]
fn test_duration_to_string() {
assert_eq!(Duration::WithinLastDay.to_string(), "within_last_day");
assert_eq!(Duration::WithinLastWeek.to_string(), "within_last_week");
assert_eq!(Duration::WithinLastMonth.to_string(), "within_last_month");
}
}