#![doc(alias = "channel.charity_campaign.progress")]
use super::*;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
pub struct ChannelCharityCampaignProgressV1 {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
pub broadcaster_user_id: types::UserId,
}
impl ChannelCharityCampaignProgressV1 {
pub fn broadcaster_user_id(broadcaster_user_id: impl Into<types::UserId>) -> Self {
Self {
broadcaster_user_id: broadcaster_user_id.into(),
}
}
}
impl EventSubscription for ChannelCharityCampaignProgressV1 {
type Payload = ChannelCharityCampaignProgressV1Payload;
const EVENT_TYPE: EventType = EventType::ChannelCharityCampaignProgress;
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::ChannelReadCharity];
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 ChannelCharityCampaignProgressV1Payload {
pub id: types::CharityCampaignId,
pub broadcaster_id: types::UserId,
pub broadcaster_login: types::UserName,
pub broadcaster_name: types::DisplayName,
pub charity_name: String,
pub charity_description: String,
pub charity_logo: String,
pub charity_website: String,
pub current_amount: crate::extra::DonationAmount,
pub target_amount: crate::extra::DonationAmount,
}
#[cfg(test)]
#[test]
fn parse_payload() {
let payload = r##"
{
"subscription": {
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
"type": "channel.charity_campaign.progress",
"version": "1",
"status": "enabled",
"cost": 0,
"condition": {
"broadcaster_user_id": "123456"
},
"transport": {
"method": "webhook",
"callback": "https://example.com/webhooks/callback"
},
"created_at": "2022-07-25T10:11:12.12339824Z"
},
"event": {
"id": "123-abc-456-def",
"broadcaster_id": "123456",
"broadcaster_name": "SunnySideUp",
"broadcaster_login": "sunnysideup",
"charity_name": "Example name",
"charity_description": "Example description",
"charity_logo": "https://abc.cloudfront.net/ppgf/1000/100.png",
"charity_website": "https://www.example.com",
"current_amount": {
"value": 260000,
"decimal_places": 2,
"currency": "USD"
},
"target_amount": {
"value": 1500000,
"decimal_places": 2,
"currency": "USD"
}
}
}
"##;
let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
crate::tests::roundtrip(&val)
}