#![doc(alias = "channel.channel_points_custom_reward_redemption.add")]
use super::*;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelPointsCustomRewardRedemptionAddV1 {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub broadcaster_user_id: types::UserId,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
pub reward_id: Option<types::RewardId>,
}
impl ChannelPointsCustomRewardRedemptionAddV1 {
pub fn broadcaster_user_id(broadcaster_user_id: impl Into<types::UserId>) -> Self {
Self {
broadcaster_user_id: broadcaster_user_id.into(),
reward_id: None,
}
}
pub fn reward_id(mut self, reward_id: impl Into<types::RewardId>) -> Self {
self.reward_id = Some(reward_id.into());
self
}
}
impl EventSubscription for ChannelPointsCustomRewardRedemptionAddV1 {
type Payload = ChannelPointsCustomRewardRedemptionAddV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelPointsCustomRewardRedemptionAdd;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![any(
twitch_oauth2::Scope::ChannelReadRedemptions,
twitch_oauth2::Scope::ChannelManageRedemptions
)];
const VERSION: &'static str = "1";
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ChannelPointsCustomRewardRedemptionAddV1Payload {
pub broadcaster_user_id: types::UserId,
pub broadcaster_user_login: types::UserName,
pub broadcaster_user_name: types::DisplayName,
pub id: types::RedemptionId,
pub redeemed_at: types::Timestamp,
pub reward: Reward,
pub status: RedemptionStatus,
pub user_input: String,
pub user_id: types::UserId,
pub user_login: types::UserName,
pub user_name: types::DisplayName,
}
#[cfg(test)]
#[test]
fn parse_payload() {
let payload = r##"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.channel_points_custom_reward_redemption.add",
"version": "1",
"status": "enabled",
"cost": 0,
"condition": {
"broadcaster_user_id": "1337"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2019-11-16T10:11:12.123Z"
},
"event": {
"id": "1234",
"broadcaster_user_id": "1337",
"broadcaster_user_login": "cool_user",
"broadcaster_user_name": "Cool_User",
"user_id": "9001",
"user_login": "cooler_user",
"user_name": "Cooler_User",
"user_input": "pogchamp",
"status": "unfulfilled",
"reward": {
"id": "9001",
"title": "title",
"cost": 100,
"prompt": "reward prompt"
},
"redeemed_at": "2020-07-15T17:16:03.17106713Z"
}
}
"##;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}