use super::*;
use helix::RequestGet;
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetCreatorGoalsRequest {
#[builder(setter(into))]
pub broadcaster_id: types::UserId,
#[builder(default)]
pub cursor: Option<helix::Cursor>,
#[builder(default, setter(into))]
pub first: Option<usize>,
#[builder(default, setter(into))]
pub id: Option<String>,
}
#[derive(PartialEq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct CreatorGoal {
pub id: types::CreatorGoalId,
pub broadcaster_id: types::UserId,
pub broadcaster_name: types::DisplayName,
pub broadcaster_login: types::UserName,
#[serde(rename = "type")]
pub type_: types::CreatorGoalType,
pub description: String,
pub current_amount: i64,
pub target_amount: i64,
pub created_at: types::Timestamp,
}
impl Request for GetCreatorGoalsRequest {
type Response = Vec<CreatorGoal>;
const PATH: &'static str = "goals";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[twitch_oauth2::Scope::ChannelReadGoals];
}
impl RequestGet for GetCreatorGoalsRequest {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetCreatorGoalsRequest::builder()
.broadcaster_id("141981764".to_string())
.build();
let data = br#"
{
"data": [
{
"id": "1woowvbkiNv8BRxEWSqmQz6Zk92",
"broadcaster_id": "141981764",
"broadcaster_name": "TwitchDev",
"broadcaster_login": "twitchdev",
"type": "follower",
"description": "Follow goal for Helix testing",
"current_amount": 27062,
"target_amount": 30000,
"created_at": "2021-08-16T17:22:23Z"
}
]
}
"#
.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/goals?broadcaster_id=141981764"
);
dbg!(GetCreatorGoalsRequest::parse_response(Some(req), &uri, http_response).unwrap());
}