feat: add visitor data to paginator, trends: mapping tests

This commit is contained in:
ThetaDev 2022-10-15 14:49:11 +02:00
parent 9ced819abe
commit 2b70badd4e
6 changed files with 5803 additions and 19 deletions

View file

@ -28,6 +28,9 @@ pub struct Paginator<T> {
///
/// If it is None, it means that no more items can be fetched.
pub ctoken: Option<String>,
/// YouTube visitor data. Required for fetching the startpage
#[serde(skip_serializing_if = "Option::is_none")]
pub visitor_data: Option<String>,
}
impl<T> Default for Paginator<T> {
@ -36,12 +39,22 @@ impl<T> Default for Paginator<T> {
count: Some(0),
items: Vec::new(),
ctoken: None,
visitor_data: None,
}
}
}
impl<T> Paginator<T> {
pub(crate) fn new(count: Option<u64>, items: Vec<T>, ctoken: Option<String>) -> Self {
Self::new_with_vdata(count, items, ctoken, None)
}
pub(crate) fn new_with_vdata(
count: Option<u64>,
items: Vec<T>,
ctoken: Option<String>,
visitor_data: Option<String>,
) -> Self {
Self {
count: match ctoken {
Some(_) => count,
@ -49,6 +62,7 @@ impl<T> Paginator<T> {
},
items,
ctoken,
visitor_data,
}
}