tongbal_api/live/
builder.rs1use serde::Serialize;
2
3use crate::{
4 BaseClient, Error, UserClient,
5 types::CategoryId,
6 types::{
7 CategoryType,
8 constants::{LIVES, SETTING},
9 },
10};
11
12#[derive(Debug, Serialize)]
13#[serde(rename_all = "camelCase")]
14pub struct SetStreamSetting<'a> {
15 #[serde(skip)]
16 client: &'a UserClient,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 default_live_title: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 category: Option<CategoryType>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 category_id: Option<CategoryId>,
23 #[serde(skip_serializing_if = "Vec::is_empty")]
24 tags: Vec<String>,
25}
26
27impl<'a> SetStreamSetting<'a> {
28 pub(crate) fn new(client: &'a UserClient) -> Self {
29 Self {
30 client,
31 default_live_title: None,
32 category: None,
33 category_id: None,
34 tags: Vec::new(),
35 }
36 }
37
38 pub fn default_live_title(mut self, title: impl Into<String>) -> Self {
39 self.default_live_title = Some(title.into());
40 self
41 }
42
43 pub fn category(mut self, category: CategoryType) -> Self {
44 self.category = Some(category);
45 self
46 }
47
48 pub fn category_id(mut self, category_id: CategoryId) -> Self {
49 self.category_id = Some(category_id);
50 self
51 }
52
53 pub fn add_tag(mut self, tag: impl Into<String>) -> Self {
54 self.tags.push(tag.into());
55 self
56 }
57
58 pub fn add_tags(mut self, tags: impl IntoIterator<Item = impl Into<String>>) -> Self {
59 self.tags.extend(tags.into_iter().map(|t| t.into()));
60 self
61 }
62
63 pub async fn send(self) -> Result<(), Error> {
64 let mut url = self.client.base_url();
65 url.path_segments_mut().unwrap().extend([LIVES, SETTING]);
66 crate::client::no_content(self.client.http_client().patch(url).json(&self)).await?;
67 Ok(())
68 }
69}