twitch_api/eventsub/user/
update.rs1#![doc(alias = "user.update")]
2use super::*;
4#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
7#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
8#[non_exhaustive]
9pub struct UserUpdateV1 {
10 #[cfg_attr(feature = "typed-builder", builder(setter(into)))]
12 pub user_id: types::UserId,
13}
14
15impl UserUpdateV1 {
16 pub fn new(user_id: impl Into<types::UserId>) -> Self {
18 Self {
19 user_id: user_id.into(),
20 }
21 }
22}
23
24impl EventSubscription for UserUpdateV1 {
25 type Payload = UserUpdateV1Payload;
26
27 const EVENT_TYPE: EventType = EventType::UserUpdate;
28 #[cfg(feature = "twitch_oauth2")]
29 const OPT_SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserReadEmail];
30 #[cfg(feature = "twitch_oauth2")]
31 const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
32 const VERSION: &'static str = "1";
33}
34
35#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
37#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
38#[non_exhaustive]
39pub struct UserUpdateV1Payload {
40 pub description: String,
42 pub email: Option<String>,
44 pub user_id: types::UserId,
46 pub user_login: types::UserName,
48 pub user_name: types::DisplayName,
50}
51
52#[cfg(test)]
53#[test]
54fn parse_payload() {
55 let payload = r#"
56 {
57 "subscription": {
58 "id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
59 "type": "user.update",
60 "version": "1",
61 "status": "enabled",
62 "cost": 0,
63 "condition": {
64 "user_id": "1337"
65 },
66 "transport": {
67 "method": "webhook",
68 "callback": "https://example.com/webhooks/callback"
69 },
70 "created_at": "2019-11-16T10:11:12.123Z"
71 },
72 "event": {
73 "user_id": "1337",
74 "user_login": "cool_user",
75 "user_name": "Cool_User",
76 "email": "user@email.com",
77 "description": "cool description"
78 }
79 }
80 "#;
81
82 let val = dbg!(crate::eventsub::Event::parse(payload).unwrap());
83 crate::tests::roundtrip(&val)
84}