twitch_highway/extensions/
types.rs1use std::collections::HashMap;
2
3use chrono::{DateTime, FixedOffset};
4use serde::{Deserialize, Serialize};
5use url::Url;
6
7use crate::types::{BroadcasterId, Cost, ExtensionId, GameId};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(rename_all = "lowercase")]
11pub enum Segment {
12 Broadcaster,
13 Developer,
14 Global,
15}
16
17impl AsRef<str> for Segment {
18 fn as_ref(&self) -> &str {
19 match self {
20 Self::Broadcaster => "broadcaster",
21 Self::Developer => "developer",
22 Self::Global => "global",
23 }
24 }
25}
26
27impl From<Segment> for String {
28 fn from(value: Segment) -> Self {
29 value.as_ref().to_string()
30 }
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct ConfigurationSegment {
35 pub segment: Segment,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub broadcaster_id: Option<BroadcasterId>,
38 pub content: String,
39 pub version: String,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct LiveChannel {
44 pub broadcaster_id: BroadcasterId,
45 pub broadcaster_name: String,
46 pub game_name: String,
47 pub game_id: GameId,
48 pub title: String,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct SecretData {
53 pub format_version: u64,
54 pub secrets: Vec<Secret>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct Secret {
59 pub content: String,
60 pub active_at: DateTime<FixedOffset>,
61 pub expires_at: DateTime<FixedOffset>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct Extension {
66 pub author_name: String,
67 pub bits_enabled: bool,
68 pub can_install: bool,
69 pub configuration_location: ConfigurationLocation,
70 pub description: String,
71 pub eula_tos_url: String,
72 pub has_chat_support: bool,
73 pub icon_url: Url,
74 pub icon_urls: HashMap<String, String>,
75 pub id: ExtensionId,
76 pub name: String,
77 pub privacy_policy_url: String,
78 pub request_identity_link: bool,
79 pub screenshot_urls: Vec<Url>,
80 pub state: State,
81 pub subscriptions_support_level: SubscriptionsSupportLevel,
82 pub summary: String,
83 pub support_email: String,
84 pub version: String,
85 pub viewer_summary: String,
86 pub views: Views,
87 pub allowlisted_config_urls: Vec<String>,
88 pub allowlisted_panel_urls: Vec<String>,
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
92#[serde(rename_all = "lowercase")]
93pub enum ConfigurationLocation {
94 Hosted,
95 Custom,
96 None,
97}
98
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
100pub enum State {
101 Approved,
102 AssetsUploaded,
103 Deleted,
104 Deprecated,
105 InReview,
106 InTest,
107 PendingAction,
108 Rejected,
109 Released,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
113#[serde(rename_all = "lowercase")]
114pub enum SubscriptionsSupportLevel {
115 None,
116 Optional,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct Views {
121 pub mobile: Mobile,
122 pub panel: Panel,
123 pub video_overlay: VideoOverlay,
124 pub component: Component,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct Mobile {
129 pub viewer_url: Url,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct Panel {
134 pub viewer_url: Url,
135 pub height: u64,
136 pub can_link_external_content: bool,
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct VideoOverlay {
141 pub viewer_url: Url,
142 pub can_link_external_content: bool,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct Component {
147 pub viewer_url: Url,
148 pub aspect_width: u64,
149 pub aspect_height: u64,
150 pub aspect_ratio_x: u64,
151 pub aspect_ratio_y: u64,
152 pub autoscale: bool,
153 pub scale_pixels: u64,
154 pub target_height: u64,
155 pub size: u64,
156 pub zoom: bool,
157 pub zoom_pixels: u64,
158 pub can_link_external_content: bool,
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct BitsProductExtension {
163 pub sku: String,
164 pub cost: Cost,
165 pub display_name: String,
166 pub in_development: bool,
167 pub expiration: DateTime<FixedOffset>,
168 pub is_broadcast: bool,
169}
170
171impl BitsProductExtension {
172 pub fn into_json(&self) -> Option<String> {
173 Some(serde_json::to_string(self).unwrap())
174 }
175}
176
177#[derive(Serialize)]
178pub struct SetExtensionRequiredConfigurationBody<'a> {
179 pub extension_id: &'a ExtensionId,
180 pub extension_version: &'a str,
181 pub required_configuration: &'a str,
182}
183
184#[derive(Serialize)]
185pub struct SendExtensionPubSubMessageBody<'a> {
186 pub target: &'a [&'a str],
187 pub message: &'a str,
188 pub broadcaster_id: &'a BroadcasterId,
189 #[serde(skip_serializing_if = "Option::is_none")]
190 pub is_global_broadcast: Option<bool>,
191}
192
193#[derive(Serialize)]
194pub struct ExtensionChatMessageIntoRequestBody<'a> {
195 pub text: &'a str,
196 pub extension_id: &'a ExtensionId,
197 pub extension_version: &'a str,
198}