use super::*;
use helix::RequestGet;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetEmoteSetsRequest {
#[builder(setter(into))]
pub emote_set_id: Vec<types::EmoteSetId>,
}
#[derive(PartialEq, 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 {
id: std::borrow::Cow::Borrowed(&self.id),
animation_setting: <_>::default(),
theme_mode: <_>::default(),
scale: <_>::default(),
template: types::EMOTE_V2_URL_TEMPLATE.into(),
}
}
}
impl Request for GetEmoteSetsRequest {
type Response = Vec<Emote>;
const PATH: &'static str = "chat/emotes/set";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
impl RequestGet for GetEmoteSetsRequest {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetEmoteSetsRequest::builder()
.emote_set_id(vec!["301590448".into()])
.build();
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());
}