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 GetUserEmotesRequest<'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(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub broadcaster_id: Option<Cow<'a, types::UserIdRef>>,
}
impl<'a> GetUserEmotesRequest<'a> {
pub fn user_id(user_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
Self {
user_id: user_id.into_cow(),
after: None,
broadcaster_id: None,
}
}
}
impl helix::Paginated for GetUserEmotesRequest<'_> {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) {
self.after = cursor.map(|c| c.into_cow())
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct UserEmote {
pub id: types::EmoteId,
pub name: String,
pub emote_type: String,
pub emote_set_id: types::EmoteSetId,
pub owner_id: types::UserId,
pub format: Vec<types::EmoteAnimationSetting>,
pub scale: Vec<types::EmoteScale>,
pub theme_mode: Vec<types::EmoteThemeMode>,
}
impl UserEmote {
pub fn url(&self) -> types::EmoteUrlBuilder<'_> { EmoteUrlBuilder::new(&self.id) }
}
impl Request for GetUserEmotesRequest<'_> {
type Response = Vec<UserEmote>;
const PATH: &'static str = "chat/emotes/user";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::UserReadEmotes];
}
impl RequestGet for GetUserEmotesRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetUserEmotesRequest::user_id("123456");
let data = br#"
{
"data": [
{
"emote_set_id": "",
"emote_type": "hypetrain",
"format": [
"static"
],
"id": "304420818",
"name": "HypeLol",
"owner_id": "477339272",
"scale": [
"1.0",
"2.0",
"3.0"
],
"theme_mode": [
"light",
"dark"
]
}
],
"template": "https://static-cdn.jtvnw.net/emoticons/v2/{{id}}/{{format}}/{{theme_mode}}/{{scale}}",
"pagination": {
"cursor": "eyJiIjpudWxsLJxhIjoiIn0gf5"
}
}
"#
.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/chat/emotes/user?user_id=123456"
);
dbg!(GetUserEmotesRequest::parse_response(Some(req), &uri, http_response).unwrap());
}