use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetChannelEditorsRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub broadcaster_id: Cow<'a, types::UserIdRef>,
}
impl<'a> GetChannelEditorsRequest<'a> {
pub fn broadcaster_id(broadcaster_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
Self {
broadcaster_id: broadcaster_id.into_cow(),
}
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Editor {
pub user_id: types::UserId,
pub user_name: types::DisplayName,
pub created_at: types::Timestamp,
}
impl Request for GetChannelEditorsRequest<'_> {
type Response = Vec<Editor>;
const PATH: &'static str = "channels/editors";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator =
twitch_oauth2::validator![twitch_oauth2::Scope::ChannelReadEditors];
}
impl RequestGet for GetChannelEditorsRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetChannelEditorsRequest::broadcaster_id("44445592");
let data = br#"
{
"data": [
{
"user_id": "182891647",
"user_name": "mauerbac",
"created_at": "2019-02-15T21:19:50.380833Z"
},
{
"user_id": "135093069",
"user_name": "BlueLava",
"created_at": "2018-03-07T16:28:29.872937Z"
}
]
}
"#
.to_vec();
let http_response = http::Response::builder().body(data).unwrap();
let uri = req.get_uri().unwrap();
assert_eq!(
uri.to_string(),
"https://api.twitch.tv/helix/channels/editors?broadcaster_id=44445592"
);
dbg!(GetChannelEditorsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}