Skip to content

Commit d9bd422

Browse files
committed
Add support for ExtensionBitsTransactionCreateV1 event
format Update submodule Add missing dependency to eventsub feature Update src/eventsub/extension/bits_transaction/create.rs Co-authored-by: nerix <[email protected]> Update src/eventsub/extension/bits_transaction/create.rs Co-authored-by: nerix <[email protected]> Update src/eventsub/extension/bits_transaction/create.rs Co-authored-by: nerix <[email protected]> Alphabetically sort entries Update Docs Fix missing local path reference for twitch_types Set submodule to correct commit (again)
1 parent c379795 commit d9bd422

File tree

10 files changed

+163
-8
lines changed

10 files changed

+163
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ exclude = ["twitch_types", "twitch_oauth2"]
2929
[workspace.dependencies]
3030
twitch_api = { version = "0.7.2", path = "." }
3131
twitch_oauth2 = { version = "0.16.0", path = "twitch_oauth2/" }
32-
twitch_types = { version = "0.4.9", features = [
32+
twitch_types = { version = "0.4.10", features = [
3333
"serde",
34-
], path = "./twitch_types" }
34+
], path = "twitch_types/" }
3535
ureq = { version = "2.10.1", default-features = false, features = [
3636
"tls",
3737
]}
@@ -120,6 +120,7 @@ eventsub = [
120120
"twitch_types/timestamp",
121121
"twitch_types/sub",
122122
"twitch_types/color",
123+
"twitch_types/extension"
123124
]
124125

125126
hmac = ["dep:crypto_hmac", "dep:sha2"]

src/eventsub/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ macro_rules! fill_events {
9090
channel::ChannelWarningAcknowledgeV1;
9191
channel::ChannelWarningSendV1;
9292
conduit::ConduitShardDisabledV1;
93+
extension::ExtensionBitsTransactionCreateV1;
9394
stream::StreamOfflineV1;
9495
stream::StreamOnlineV1;
9596
user::UserAuthorizationGrantV1;
@@ -310,6 +311,8 @@ make_event_type!("Event Types": pub enum EventType {
310311
ChannelVipRemove => "channel.vip.remove",
311312
"sends a notification when eventsub disables a shard due to the status of the underlying transport changing.":
312313
ConduitShardDisabled => "conduit.shard.disabled",
314+
"an extension triggers a bits transaction":
315+
ExtensionBitsTransactionCreate => "extension.bits_transaction.create",
313316
"the specified broadcaster starts a stream.":
314317
StreamOnline => "stream.online",
315318
"the specified broadcaster stops a stream.":
@@ -497,6 +500,8 @@ pub enum Event {
497500
ChannelModeratorRemoveV1(Payload<channel::ChannelModeratorRemoveV1>),
498501
/// Conduit Shard Disabled V1 Event
499502
ConduitShardDisabledV1(Payload<conduit::ConduitShardDisabledV1>),
503+
/// Extension Bits Transaction Create V1 Event
504+
ExtensionBitsTransactionCreateV1(Payload<extension::ExtensionBitsTransactionCreateV1>),
500505
/// StreamOnline V1 Event
501506
StreamOnlineV1(Payload<stream::StreamOnlineV1>),
502507
/// StreamOffline V1 Event
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#![doc(alias = "extension.bits_transaction.create")]
2+
//! a user purchases a product in the extension.
3+
4+
use super::*;
5+
use crate::eventsub::{EventSubscription, EventType};
6+
7+
/// [`extension.bits_transaction.create`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#extensionbits_transactioncreate): a new transaction is created for a Twitch Extension.
8+
9+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10+
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
11+
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
12+
#[non_exhaustive]
13+
pub struct ExtensionBitsTransactionCreateV1 {
14+
/// The ID of the extension client that you want to get bits transaction notifications for
15+
pub extension_client_id: types::ExtensionId,
16+
}
17+
18+
impl ExtensionBitsTransactionCreateV1 {
19+
/// Get notifications when transactions are created for this extension client
20+
pub fn new(extension_client_id: impl Into<types::ExtensionId>) -> Self {
21+
Self {
22+
extension_client_id: extension_client_id.into(),
23+
}
24+
}
25+
}
26+
27+
impl EventSubscription for ExtensionBitsTransactionCreateV1 {
28+
type Payload = ExtensionBitsTransactionCreateV1Payload;
29+
30+
const EVENT_TYPE: EventType = EventType::ExtensionBitsTransactionCreate;
31+
#[cfg(feature = "twitch_oauth2")]
32+
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![];
33+
const VERSION: &'static str = "1";
34+
}
35+
36+
/// [`extension.bits_transaction.create`](ExtensionBitsTransactionCreateV1) response payload.
37+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
38+
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
39+
#[non_exhaustive]
40+
pub struct ExtensionBitsTransactionCreateV1Payload {
41+
/// The ID of the bits transaction that was created
42+
pub id: types::BitsTransactionId,
43+
/// The ID of the extension client that created the bits transaction
44+
pub extension_client_id: types::ExtensionClientId,
45+
46+
/// The transaction’s broadcaster ID.
47+
pub broadcaster_user_id: types::UserId,
48+
/// The broadcaster’s login name.
49+
pub broadcaster_user_login: types::UserName,
50+
/// The broadcaster’s display name.
51+
pub broadcaster_user_name: types::DisplayName,
52+
53+
/// The transaction’s user ID.
54+
pub user_id: types::UserId,
55+
/// The user’s login name.
56+
pub user_login: types::UserName,
57+
/// The user’s display name.
58+
pub user_name: types::DisplayName,
59+
60+
/// The product that was purchased in the transaction
61+
pub product: ExtensionBitsProduct,
62+
}
63+
64+
#[cfg(test)]
65+
#[test]
66+
fn parse_payload() {
67+
use crate::eventsub::Event;
68+
69+
let payload = r##"
70+
{
71+
"subscription": {
72+
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4",
73+
"type": "extension.bits_transaction.create",
74+
"version": "1",
75+
"status": "enabled",
76+
"cost": 0,
77+
"condition": {
78+
"extension_client_id": "deadbeef"
79+
},
80+
"transport": {
81+
"method": "webhook",
82+
"callback": "https://example.com/webhooks/callback"
83+
},
84+
"created_at": "2019-11-16T10:11:12.634234626Z"
85+
},
86+
"event": {
87+
"id": "bits-tx-id",
88+
"extension_client_id": "deadbeef",
89+
"broadcaster_user_id": "1337",
90+
"broadcaster_user_login": "cool_user",
91+
"broadcaster_user_name": "Cool_User",
92+
"user_name": "Coolest_User",
93+
"user_login": "coolest_user",
94+
"user_id": "1236",
95+
"product": {
96+
"name": "great_product",
97+
"sku": "skuskusku",
98+
"bits": 1234,
99+
"in_development": false
100+
}
101+
}
102+
}"##;
103+
let val = Event::parse(payload).unwrap();
104+
crate::tests::roundtrip(&val);
105+
106+
let Event::ExtensionBitsTransactionCreateV1(_val) = val else {
107+
panic!("invalid event type");
108+
};
109+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![doc(alias = "extension.bits_transaction")]
2+
//! A bits transaction for an extension is changed.
3+
use super::ExtensionBitsProduct;
4+
use crate::types;
5+
use serde_derive::{Deserialize, Serialize};
6+
pub mod create;
7+
8+
#[doc(inline)]
9+
pub use create::{ExtensionBitsTransactionCreateV1, ExtensionBitsTransactionCreateV1Payload};

src/eventsub/extension/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![doc(alias = "extensions")]
2+
//! Subscription types regarding extensions
3+
4+
pub mod bits_transaction;
5+
use serde_derive::{Deserialize, Serialize};
6+
7+
#[doc(inline)]
8+
pub use bits_transaction::{
9+
ExtensionBitsTransactionCreateV1, ExtensionBitsTransactionCreateV1Payload,
10+
};
11+
12+
/// [`extension.bits_transaction.create`](ExtensionBitsTransactionCreateV1) product payload.
13+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
14+
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
15+
#[non_exhaustive]
16+
pub struct ExtensionBitsProduct {
17+
/// The Display name of the purchased product
18+
pub name: String,
19+
20+
/// The sku of the purchased product
21+
pub sku: String,
22+
23+
/// The amount of bits paid for the product
24+
pub bits: i64,
25+
26+
/// If the product is in development (bits will always be 0 if this is true)
27+
pub in_development: bool,
28+
}

src/eventsub/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@
185185
//!
186186
//! </details>
187187
//!
188-
//! <details><summary style="cursor: pointer"><code style="color: var(--link-color)">extension.*</code> 🔴 0/1</summary>
188+
//! <details><summary style="cursor: pointer"><code style="color: var(--link-color)">extension.*</code> 🟢 1/1</summary>
189189
//!
190190
//! | Name | Subscription<br>Payload |
191191
//! |---|:---|
192-
//! | [`extension.bits_transaction.create`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#extensionbits_transactioncreate) (v1) | -<br>- |
192+
//! | [`extension.bits_transaction.create`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#extensionbits_transactioncreate) (v1) | [ExtensionBitsTransactionCreateV1](extension::ExtensionBitsTransactionCreateV1)<br>[ExtensionBitsTransactionCreateV1Payload](extension::ExtensionBitsTransactionCreateV1Payload) |
193193
//!
194194
//! </details>
195195
//!
@@ -227,6 +227,7 @@ pub mod automod;
227227
pub mod channel;
228228
pub mod conduit;
229229
pub mod event;
230+
pub mod extension;
230231
pub mod stream;
231232
pub mod user;
232233

src/helix/endpoints/users/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
//!
2424
//! <!-- generate with "cargo xtask overview" (with a nightly toolchain) -->
2525
//! <!-- BEGIN-OVERVIEW -->
26-
//! <details open><summary style="cursor: pointer">Users 🟢 8/8</summary>
26+
//! <details open><summary style="cursor: pointer">Users 🟡 8/9</summary>
2727
//!
2828
//! | Endpoint | Helper | Module |
2929
//! |---|---|---|
3030
//! | [Get Users](https://dev.twitch.tv/docs/api/reference#get-users) | [`HelixClient::get_user_from_id`](crate::helix::HelixClient::get_user_from_id), [`HelixClient::get_user_from_login`](crate::helix::HelixClient::get_user_from_login), [`HelixClient::get_users_from_ids`](crate::helix::HelixClient::get_users_from_ids), [`HelixClient::get_users_from_logins`](crate::helix::HelixClient::get_users_from_logins) | [`get_users`] |
3131
//! | [Update User](https://dev.twitch.tv/docs/api/reference#update-user) | [`HelixClient::update_user_description`](crate::helix::HelixClient::update_user_description) | [`update_user`] |
32+
//! | [Get Authorization By User](https://dev.twitch.tv/docs/api/reference#get-authorization-by-user) | - | - |
3233
//! | [Get User Block List](https://dev.twitch.tv/docs/api/reference#get-user-block-list) | - | [`get_user_block_list`] |
3334
//! | [Block User](https://dev.twitch.tv/docs/api/reference#block-user) | [`HelixClient::block_user`](crate::helix::HelixClient::block_user) | [`block_user`] |
3435
//! | [Unblock User](https://dev.twitch.tv/docs/api/reference#unblock-user) | [`HelixClient::unblock_user`](crate::helix::HelixClient::unblock_user) | [`unblock_user`] |

src/helix/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,13 @@
353353
//!
354354
//! </details>
355355
//!
356-
//! <details><summary style="cursor: pointer">Users 🟢 8/8</summary>
356+
//! <details><summary style="cursor: pointer">Users 🟡 8/9</summary>
357357
//!
358358
//! | Endpoint | Helper | Module |
359359
//! |---|---|---|
360360
//! | [Get Users](https://dev.twitch.tv/docs/api/reference#get-users) | [`HelixClient::get_user_from_id`], [`HelixClient::get_user_from_login`], [`HelixClient::get_users_from_ids`], [`HelixClient::get_users_from_logins`] | [`users::get_users`] |
361361
//! | [Update User](https://dev.twitch.tv/docs/api/reference#update-user) | [`HelixClient::update_user_description`] | [`users::update_user`] |
362+
//! | [Get Authorization By User](https://dev.twitch.tv/docs/api/reference#get-authorization-by-user) | - | - |
362363
//! | [Get User Block List](https://dev.twitch.tv/docs/api/reference#get-user-block-list) | - | [`users::get_user_block_list`] |
363364
//! | [Block User](https://dev.twitch.tv/docs/api/reference#block-user) | [`HelixClient::block_user`] | [`users::block_user`] |
364365
//! | [Unblock User](https://dev.twitch.tv/docs/api/reference#unblock-user) | [`HelixClient::unblock_user`] | [`users::unblock_user`] |

0 commit comments

Comments
 (0)