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 GetCustomRewardRequest<'a> {
#[cfg_attr(feature = "typed-builder", builder(setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
pub broadcaster_id: Cow<'a, types::UserIdRef>,
#[cfg_attr(feature = "typed-builder", builder(default, setter(into)))]
#[cfg_attr(feature = "deser_borrow", serde(borrow = "'a"))]
#[cfg_attr(not(feature = "deser_borrow"), serde(bound(deserialize = "'de: 'a")))]
pub id: types::Collection<'a, types::RewardId>,
#[cfg_attr(feature = "typed-builder", builder(default))]
pub only_manageable_rewards: Option<bool>,
}
impl<'a> GetCustomRewardRequest<'a> {
pub fn broadcaster_id(broadcaster_id: impl types::IntoCow<'a, types::UserIdRef> + 'a) -> Self {
Self {
broadcaster_id: broadcaster_id.into_cow(),
id: types::Collection::default(),
only_manageable_rewards: Default::default(),
}
}
pub fn ids(mut self, id: impl Into<types::Collection<'a, types::RewardId>>) -> Self {
self.id = id.into();
self
}
pub const fn only_manageable_rewards(mut self, only_manageable_rewards: bool) -> Self {
self.only_manageable_rewards = Some(only_manageable_rewards);
self
}
}
#[derive(PartialEq, Eq, Deserialize, Serialize, Debug, Clone)]
#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct CustomReward {
pub broadcaster_id: types::UserId,
pub broadcaster_login: types::UserName,
pub broadcaster_name: types::DisplayName,
pub id: types::RewardId,
pub title: String,
pub prompt: String,
pub cost: usize,
pub image: Option<types::Image>,
pub default_image: Option<types::Image>,
pub background_color: String,
pub is_enabled: bool,
pub is_user_input_required: bool,
pub max_per_stream_setting: types::Max,
pub max_per_user_per_stream_setting: types::Max,
pub global_cooldown_setting: types::GlobalCooldown,
pub is_paused: bool,
pub is_in_stock: bool,
pub should_redemptions_skip_request_queue: bool,
pub redemptions_redeemed_current_stream: Option<usize>,
pub cooldown_expires_at: Option<types::Timestamp>,
}
impl Request for GetCustomRewardRequest<'_> {
type Response = Vec<CustomReward>;
const PATH: &'static str = "channel_points/custom_rewards";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: twitch_oauth2::Validator = twitch_oauth2::validator![any(
twitch_oauth2::scopes::Scope::ChannelReadRedemptions,
twitch_oauth2::Scope::ChannelManageRedemptions
)];
}
impl RequestGet for GetCustomRewardRequest<'_> {}
#[cfg(test)]
#[test]
fn test_request() {
use helix::*;
let req = GetCustomRewardRequest::broadcaster_id("274637212");
let data = br##"
{
"data": [
{
"broadcaster_name": "torpedo09",
"broadcaster_login": "torpedo09",
"broadcaster_id": "274637212",
"id": "92af127c-7326-4483-a52b-b0da0be61c01",
"image": null,
"background_color": "#00E5CB",
"is_enabled": true,
"cost": 50000,
"title": "game analysis",
"prompt": "",
"is_user_input_required": false,
"max_per_stream_setting": {
"is_enabled": false,
"max_per_stream": 0
},
"max_per_user_per_stream_setting": {
"is_enabled": false,
"max_per_user_per_stream": 0
},
"global_cooldown_setting": {
"is_enabled": false,
"global_cooldown_seconds": 0
},
"is_paused": false,
"is_in_stock": true,
"default_image": {
"url_1x": "https://static-cdn.jtvnw.net/custom-reward-images/default-1.png",
"url_2x": "https://static-cdn.jtvnw.net/custom-reward-images/default-2.png",
"url_4x": "https://static-cdn.jtvnw.net/custom-reward-images/default-4.png"
},
"should_redemptions_skip_request_queue": false,
"redemptions_redeemed_current_stream": null,
"cooldown_expires_at": null
}
]
}
"##
.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/channel_points/custom_rewards?broadcaster_id=274637212"
);
dbg!(GetCustomRewardRequest::parse_response(Some(req), &uri, http_response).unwrap());
}