use super::*;
use helix::RequestPatch;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct ModifyChannelInformationRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug, Default)]
#[non_exhaustive]
pub struct ModifyChannelInformationBody {
#[builder(default, setter(into))]
pub game_id: Option<types::CategoryId>,
#[builder(default, setter(into))]
pub broadcaster_language: Option<String>,
#[builder(default, setter(into))]
pub title: Option<String>,
}
impl helix::private::SealedSerialize for ModifyChannelInformationBody {}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[non_exhaustive]
pub enum ModifyChannelInformation {
Success,
}
impl Request for ModifyChannelInformationRequest {
type Response = ModifyChannelInformation;
const PATH: &'static str = "channels";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::UserEditBroadcast];
}
impl RequestPatch for ModifyChannelInformationRequest {
type Body = ModifyChannelInformationBody;
fn parse_inner_response(
request: Option<Self>,
uri: &http::Uri,
response: &str,
status: http::StatusCode,
) -> Result<helix::Response<Self, Self::Response>, helix::HelixRequestPatchError>
where
Self: Sized,
{
Ok(helix::Response {
data: match status {
http::StatusCode::NO_CONTENT | http::StatusCode::OK => {
ModifyChannelInformation::Success
}
_ => {
return Err(helix::HelixRequestPatchError::InvalidResponse {
reason: "unexpected status code",
response: response.to_string(),
status,
uri: uri.clone(),
})
}
},
pagination: None,
request,
total: None,
other: None,
})
}
}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = ModifyChannelInformationRequest::builder()
.broadcaster_id(String::from("0"))
.build();
let body = ModifyChannelInformationBody::builder()
.title("Hello World!".to_string())
.build();
dbg!(req.create_request(body, "token", "clientid").unwrap());
let data = br#""#.to_vec();
let http_response = http::Response::builder().status(200).body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/channels?broadcaster_id=0"
);
dbg!(ModifyChannelInformationRequest::parse_response(Some(req), &uri, http_response).unwrap());
}