use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetFollowedStreamsRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub user_id: Cow<'a, types::UserIdRef>,
#[cfg_attr(feature = "typed-builder", builder(default))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub after: Option<Cow<'a, helix::CursorRef>>,
#[cfg_attr(feature = "typed-builder", builder(default))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub before: Option<Cow<'a, helix::CursorRef>>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
pub first: Option<usize>,
}
impl<'a> GetFollowedStreamsRequest<'a> {
pub fn user_id(user_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
Self {
user_id: user_id.into_cow(),
after: Default::default(),
before: Default::default(),
first: Default::default(),
}
}
pub const fn first(mut self, first: usize) -> Self {
self.first = Some(first);
self
}
}
pub type GetFollowedStreamsResponse = Stream;
impl Request for GetFollowedStreamsRequest<'_> {
type Response = Vec<GetFollowedStreamsResponse>;
const PATH: &'static str = "streams/followed";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::UserReadFollows];
}
impl RequestGet for GetFollowedStreamsRequest<'_> {}
impl helix::Paginated for GetFollowedStreamsRequest<'_> {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) {
self.after = cursor.map(|c| c.into_cow())
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetFollowedStreamsRequest::user_id("141981764");
let data = br#"
{
"data": [
{
"id": "42170724654",
"user_id": "132954738",
"user_login": "aws",
"user_name": "AWS",
"game_id": "417752",
"game_name": "Talk Shows & Podcasts",
"type": "live",
"title": "AWS Howdy Partner! Y'all welcome ExtraHop to the show!",
"viewer_count": 20,
"started_at": "2021-03-31T20:57:26Z",
"language": "en",
"thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_aws-{width}x{height}.jpg",
"tag_ids": [],
"tags": ["English"],
"is_mature": false
},
{
"id": "42170724654",
"user_id": "132954738",
"user_login": "aws",
"user_name": "AWS",
"game_id": "417752",
"game_name": "Talk Shows & Podcasts",
"type": "live",
"title": "AWS Howdy Partner! Y'all welcome ExtraHop to the show!",
"viewer_count": 20,
"started_at": "2021-03-31T20:57:26Z",
"language": "en",
"thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_aws-{width}x{height}.jpg",
"tag_ids": [],
"tags": ["English"],
"is_mature": false
}
],
"pagination": {
"cursor": "eyJiIjp7IkN1cnNvciI6ImV5SnpJam8zT0RNMk5TNDBORFF4TlRjMU1UY3hOU3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqb3hOVGs0TkM0MU56RXhNekExTVRZNU1ESXNJbVFpT21aaGJITmxMQ0owSWpwMGNuVmxmUT09In19=="
}
}
"#
.to_vec();
let http_response = http::Response::builder().body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/streams/followed?user_id=141981764"
);
dbg!(GetFollowedStreamsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}