use super::*;
use helix::RequestGet;
#[derive(PartialEq, Eq, Deserialize, Serialize, Clone, Debug, Default)]
#[cfg_attr(feature = "typed-builder", derive(typed_builder::TypedBuilder))]
#[must_use]
#[non_exhaustive]
pub struct GetUserExtensionsRequest {}
impl GetUserExtensionsRequest {
pub fn new() -> Self { Self::default() }
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Extension {
pub id: types::ExtensionId,
pub version: String,
pub name: String,
pub can_activate: bool,
#[serde(rename = "type")]
pub type_: Vec<ExtensionType>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(rename_all = "snake_case")]
pub enum ExtensionType {
Component,
Mobile,
Overlay,
Panel,
#[serde(untagged)]
Unknown(String),
}
impl Request for GetUserExtensionsRequest {
type Response = Vec<Extension>;
#[cfg(feature = "twitch_oauth2")]
const OPT_SCOPE: &'static [twitch_oauth2::Scope] =
&[twitch_oauth2::Scope::UserReadBlockedUsers];
const PATH: &'static str = "users/extensions/list";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![any(
twitch_oauth2::Scope::UserReadBroadcast,
twitch_oauth2::Scope::UserEditBroadcast
)];
}
impl RequestGet for GetUserExtensionsRequest {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetUserExtensionsRequest::new();
let data = br#"
{
"data": [
{
"id": "wi08ebtatdc7oj83wtl9uxwz807l8b",
"version": "1.1.8",
"name": "Streamlabs Leaderboard",
"can_activate": true,
"type": [
"panel"
]
},
{
"id": "d4uvtfdr04uq6raoenvj7m86gdk16v",
"version": "2.0.2",
"name": "Prime Subscription and Loot Reminder",
"can_activate": true,
"type": [
"overlay"
]
},
{
"id": "rh6jq1q334hqc2rr1qlzqbvwlfl3x0",
"version": "1.1.0",
"name": "TopClip",
"can_activate": true,
"type": [
"mobile",
"panel"
]
},
{
"id": "zfh2irvx2jb4s60f02jq0ajm8vwgka",
"version": "1.0.19",
"name": "Streamlabs",
"can_activate": true,
"type": [
"mobile",
"overlay"
]
},
{
"id": "lqnf3zxk0rv0g7gq92mtmnirjz2cjj",
"version": "0.0.1",
"name": "Dev Experience Test",
"can_activate": true,
"type": [
"component",
"mobile",
"panel",
"overlay"
]
}
]
}
"#
.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/users/extensions/list?"
);
let res = GetUserExtensionsRequest::parse_response(Some(req), &uri, http_response)
.unwrap()
.data;
assert_eq!(res.len(), 5);
assert_eq!(res[4].id.as_str(), "lqnf3zxk0rv0g7gq92mtmnirjz2cjj");
assert_eq!(res[4].version, "0.0.1");
assert!(res[4].can_activate);
assert_eq!(res[4].type_.len(), 4);
assert_eq!(res[4].type_[0], ExtensionType::Component);
assert_eq!(res[4].type_[1], ExtensionType::Mobile);
assert_eq!(res[4].type_[2], ExtensionType::Panel);
assert_eq!(res[4].type_[3], ExtensionType::Overlay);
}