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 GetEmoteSetsRequest<'a> {
#[cfg_attr(
feature = "typed-builder",
builder(default_code = "types::Collection::default()", setter(into))
)]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
#[cfg_attr(not(feature = "deser_borrow"), serde(bound(deserialize = "'de: 'a")))]
pub emote_set_id: types::Collection<'a, types::EmoteSetId>,
}
impl<'a> GetEmoteSetsRequest<'a> {
pub fn emote_set_ids(
emote_set_ids: impl Into<types::Collection<'a, types::EmoteSetId>>,
) -> Self {
Self {
emote_set_id: emote_set_ids.into(),
}
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Emote {
pub id: types::EmoteId,
pub name: String,
pub images: types::Image,
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 Emote {
pub fn url(&self) -> types::EmoteUrlBuilder<'_> { EmoteUrlBuilder::new(&self.id) }
}
impl Request for GetEmoteSetsRequest<'_> {
type Response = Vec<Emote>;
const PATH: &'static str = "chat/emotes/set";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
}
impl RequestGet for GetEmoteSetsRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let ids: &[&types::EmoteSetIdRef] = &["301590448".into()];
let req = GetEmoteSetsRequest::emote_set_ids(ids);
let data = br#"
{
"data": [
{
"id": "304456832",
"name": "twitchdevPitchfork",
"images": {
"url_1x": "https://static-cdn.jtvnw.net/emoticons/v2/304456832/static/light/1.0",
"url_2x": "https://static-cdn.jtvnw.net/emoticons/v2/304456832/static/light/2.0",
"url_4x": "https://static-cdn.jtvnw.net/emoticons/v2/304456832/static/light/3.0"
},
"emote_type": "subscriptions",
"emote_set_id": "301590448",
"owner_id": "141981764",
"format": [
"static"
],
"scale": [
"1.0",
"2.0",
"3.0"
],
"theme_mode": [
"light",
"dark"
]
}
],
"template": "https://static-cdn.jtvnw.net/emoticons/v2/{{id}}/{{format}}/{{theme_mode}}/{{scale}}"
}
"#
.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/set?emote_set_id=301590448"
);
dbg!(GetEmoteSetsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}