Struct twitch_api::HelixClient
source · [−]pub struct HelixClient<'a, C>where
C: HttpClient<'a>,{ /* private fields */ }
client
and helix
only.Expand description
Client for Helix or the New Twitch API
Use HelixClient::new
or HelixClient::with_client
to create a new client.
use twitch_api::HelixClient;
let helix: HelixClient<reqwest::Client> = HelixClient::new();
See req_get
for GET
,
req_put
for PUT
,
req_post
for POST
,
req_patch
for PATCH
and
req_delete
for DELETE
Most clients will be able to use the 'static
lifetime
pub struct MyStruct {
twitch: HelixClient<'static, reqwest::Client>,
token: twitch_oauth2::AppAccessToken,
}
// etc
See HttpClient
for implemented http clients, you can also define your own if needed.
Examples
Get a user from their login name.
use twitch_api::helix::{users::User, HelixClient};
let client: HelixClient<'static, reqwest::Client> = HelixClient::default();
let user: Option<User> = client
.get_user_from_login("justintv", &token)
.await
.unwrap();
Implementations
sourceimpl<'a, C: HttpClient<'a> + Sync> HelixClient<'a, C>
impl<'a, C: HttpClient<'a> + Sync> HelixClient<'a, C>
sourcepub async fn get_user_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<User>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_user_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<User>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get User from user login
Examples found in repository?
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
pub async fn get_channel_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<helix::channels::ChannelInformation>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_from_id(user.id, token).await
} else {
Ok(None)
}
}
/// Get [ChannelInformation](helix::channels::ChannelInformation) from a broadcasters id
pub async fn get_channel_from_id<T>(
&'a self,
id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::channels::ChannelInformation>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
self.req_get(
helix::channels::GetChannelInformationRequest::broadcaster_id(id),
token,
)
.await
.map(|response| response.first())
}
/// Get chatters in a stream [Chatter][helix::chat::Chatter]
///
/// `batch_size` sets the amount of chatters to retrieve per api call, max 1000, defaults to 100.
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let chatters: Vec<helix::chat::Chatter> = client.get_chatters("1234", "4321", 1000, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_chatters<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
batch_size: impl Into<Option<usize>>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::chat::Chatter, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::chat::GetChattersRequest {
first: batch_size.into(),
..helix::chat::GetChattersRequest::new(broadcaster_id, moderator_id)
};
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Search [Categories](helix::search::Category)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn search_categories<T>(
&'a self,
query: impl Into<String>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::search::Category, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::search::SearchCategoriesRequest::query(query).first(100);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Search [Channels](helix::search::Channel) via channel name or description
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let channel: Vec<helix::search::Channel> = client.search_channels("twitchdev", false, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn search_channels<T>(
&'a self,
query: impl Into<String>,
live_only: bool,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::search::Channel, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::search::SearchChannelsRequest::query(query.into()).live_only(live_only);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get information on a [follow relationship](helix::users::FollowRelationship)
///
/// Can be used to see if X follows Y
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::{types, helix};
/// use futures::TryStreamExt;
///
/// // Get the followers of channel "1234"
/// let followers: Vec<helix::users::FollowRelationship> = client.get_follow_relationships(types::UserId::from("1234"), None, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_follow_relationships<T>(
&'a self,
to_id: impl Into<Option<types::UserId>>,
from_id: impl Into<Option<types::UserId>>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::users::FollowRelationship, ClientError<'a, C>>>
+ Send
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let mut req = helix::users::GetUsersFollowsRequest::empty();
req.to_id = to_id.into();
req.from_id = from_id.into();
make_stream(req, token, self, |s| {
std::collections::VecDeque::from(s.follow_relationships)
})
}
/// Get authenticated users' followed [streams](helix::streams::Stream)
///
/// Requires token with scope [`user:read:follows`](twitch_oauth2::Scope::UserReadFollows).
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let channels: Vec<helix::streams::Stream> = client.get_followed_streams(&token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_followed_streams<T>(
&'a self,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::streams::Stream, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
use futures::StreamExt;
let user_id = match token
.user_id()
.ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
{
Ok(t) => t,
Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
};
let req = helix::streams::GetFollowedStreamsRequest::user_id(user_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get authenticated broadcasters' [subscribers](helix::subscriptions::BroadcasterSubscription)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let subs: Vec<helix::subscriptions::BroadcasterSubscription> = client.get_broadcaster_subscriptions(&token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_broadcaster_subscriptions<T>(
&'a self,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<
Item = Result<
helix::subscriptions::BroadcasterSubscription,
ClientError<'a, C>,
>,
> + 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
use futures::StreamExt;
let user_id = match token
.user_id()
.ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
{
Ok(t) => t,
Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
};
let req = helix::subscriptions::GetBroadcasterSubscriptionsRequest::broadcaster_id(user_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get all moderators in a channel [Get Moderators](helix::moderation::GetModeratorsRequest)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let moderators: Vec<helix::moderation::Moderator> = client.get_moderators_in_channel_from_id("twitchdev", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_moderators_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::moderation::Moderator, ClientError<'a, C>>>
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::moderation::GetModeratorsRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get all banned users in a channel [Get Banned Users](helix::moderation::GetBannedUsersRequest)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let moderators: Vec<helix::moderation::BannedUser> = client.get_banned_users_in_channel_from_id("twitchdev", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_banned_users_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::moderation::BannedUser, ClientError<'a, C>>>
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::moderation::GetBannedUsersRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get a users, with login, follow count
pub async fn get_total_followers_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<i64>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_total_followers_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get a users, with id, follow count
///
/// # Notes
///
/// This returns zero if the user doesn't exist
pub async fn get_total_followers_from_id<T>(
&'a self,
to_id: impl Into<types::UserId>,
token: &T,
) -> Result<i64, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let resp = self
.req_get(
helix::users::GetUsersFollowsRequest::followers(to_id),
token,
)
.await?;
Ok(resp.data.total)
}
/// Get games by ID. Can only be at max 100 ids.
pub async fn get_games_by_id<T>(
&'a self,
ids: impl IntoIterator<Item = impl Into<types::CategoryId>>,
token: &T,
) -> Result<std::collections::HashMap<types::CategoryId, helix::games::Game>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let ids: Vec<_> = ids.into_iter().take(101).map(Into::into).collect();
if ids.len() > 100 {
return Err(ClientRequestError::Custom("too many IDs, max 100".into()));
}
let resp = self
.req_get(helix::games::GetGamesRequest::ids(ids), token)
.await?;
Ok(resp
.data
.into_iter()
.map(|g: helix::games::Game| (g.id.clone(), g))
.collect())
}
/// Block a user
pub async fn block_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::BlockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_put(
helix::users::BlockUserRequest::block_user(target_user_id),
helix::EmptyBody,
token,
)
.await?
.data)
}
/// Unblock a user
pub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::UnblockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::users::UnblockUserRequest::unblock_user(target_user_id),
token,
)
.await?
.data)
}
/// Ban a user
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
reason: impl std::fmt::Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_post(
helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
helix::moderation::BanUserBody::new(target_user_id, reason.to_string(), duration),
token,
)
.await?
.data)
}
/// Unban a user
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::moderation::UnbanUserRequest::new(
broadcaster_id,
moderator_id,
target_user_id,
),
token,
)
.await?
.data)
}
// FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
/// Get all scheduled streams in a channel.
///
/// # Notes
///
/// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
///
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let schedule: Vec<helix::schedule::Segment> = client
/// .get_channel_schedule("twitchdev", &token)
/// .try_take_while(|s| {
/// futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
/// })
/// .try_collect()
/// .await?;
///
/// # Ok(()) }
/// ```
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
}
/// Get all global emotes
pub async fn get_global_emotes<T>(
&'a self,
token: &T,
) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetGlobalEmotesRequest::new();
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user id
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user login
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
sourcepub async fn get_user_from_id<T>(
&'a self,
id: impl Into<UserId>,
token: &T
) -> Result<Option<User>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_user_from_id<T>(
&'a self,
id: impl Into<UserId>,
token: &T
) -> Result<Option<User>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get User from user id
sourcepub async fn get_channel_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<ChannelInformation>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_channel_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<ChannelInformation>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get ChannelInformation from a broadcasters login
sourcepub async fn get_channel_from_id<T>(
&'a self,
id: impl Into<UserId>,
token: &T
) -> Result<Option<ChannelInformation>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_channel_from_id<T>(
&'a self,
id: impl Into<UserId>,
token: &T
) -> Result<Option<ChannelInformation>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get ChannelInformation from a broadcasters id
Examples found in repository?
41 42 43 44 45 46 47 48 49 50 51 52 53 54
pub async fn get_channel_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<helix::channels::ChannelInformation>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_from_id(user.id, token).await
} else {
Ok(None)
}
}
sourcepub fn get_chatters<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
batch_size: impl Into<Option<usize>>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Chatter, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_chatters<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
batch_size: impl Into<Option<usize>>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Chatter, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
sourcepub fn search_categories<T>(
&'a self,
query: impl Into<String>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Category, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn search_categories<T>(
&'a self,
query: impl Into<String>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Category, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Search Categories
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
sourcepub fn search_channels<T>(
&'a self,
query: impl Into<String>,
live_only: bool,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Channel, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn search_channels<T>(
&'a self,
query: impl Into<String>,
live_only: bool,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Channel, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
sourcepub fn get_follow_relationships<T>(
&'a self,
to_id: impl Into<Option<UserId>>,
from_id: impl Into<Option<UserId>>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<FollowRelationship, ClientRequestError<<C as HttpClient<'a>>::Error>>> + Send + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_follow_relationships<T>(
&'a self,
to_id: impl Into<Option<UserId>>,
from_id: impl Into<Option<UserId>>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<FollowRelationship, ClientRequestError<<C as HttpClient<'a>>::Error>>> + Send + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get information on a follow relationship
Can be used to see if X follows Y
Examples
use twitch_api::{types, helix};
use futures::TryStreamExt;
// Get the followers of channel "1234"
let followers: Vec<helix::users::FollowRelationship> = client.get_follow_relationships(types::UserId::from("1234"), None, &token).try_collect().await?;
sourcepub fn get_followed_streams<T>(
&'a self,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Stream, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_followed_streams<T>(
&'a self,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Stream, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get authenticated users’ followed streams
Requires token with scope user:read:follows
.
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let channels: Vec<helix::streams::Stream> = client.get_followed_streams(&token).try_collect().await?;
sourcepub fn get_broadcaster_subscriptions<T>(
&'a self,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<BroadcasterSubscription, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_broadcaster_subscriptions<T>(
&'a self,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<BroadcasterSubscription, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get authenticated broadcasters’ subscribers
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let subs: Vec<helix::subscriptions::BroadcasterSubscription> = client.get_broadcaster_subscriptions(&token).try_collect().await?;
sourcepub fn get_moderators_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Moderator, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_moderators_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Moderator, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get all moderators in a channel Get Moderators
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let moderators: Vec<helix::moderation::Moderator> = client.get_moderators_in_channel_from_id("twitchdev", &token).try_collect().await?;
sourcepub fn get_banned_users_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<BannedUser, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_banned_users_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<BannedUser, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get all banned users in a channel Get Banned Users
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let moderators: Vec<helix::moderation::BannedUser> = client.get_banned_users_in_channel_from_id("twitchdev", &token).try_collect().await?;
sourcepub async fn get_total_followers_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<i64>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_total_followers_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<i64>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get a users, with login, follow count
sourcepub async fn get_total_followers_from_id<T>(
&'a self,
to_id: impl Into<UserId>,
token: &T
) -> Result<i64, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_total_followers_from_id<T>(
&'a self,
to_id: impl Into<UserId>,
token: &T
) -> Result<i64, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Examples found in repository?
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
pub async fn get_total_followers_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<i64>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_total_followers_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
sourcepub async fn get_games_by_id<T>(
&'a self,
ids: impl IntoIterator<Item = impl Into<CategoryId>>,
token: &T
) -> Result<HashMap<CategoryId, Game>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_games_by_id<T>(
&'a self,
ids: impl IntoIterator<Item = impl Into<CategoryId>>,
token: &T
) -> Result<HashMap<CategoryId, Game>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get games by ID. Can only be at max 100 ids.
sourcepub async fn block_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
token: &T
) -> Result<BlockUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn block_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
token: &T
) -> Result<BlockUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Block a user
sourcepub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
token: &T
) -> Result<UnblockUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
token: &T
) -> Result<UnblockUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Unblock a user
sourcepub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
reason: impl Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<BanUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
reason: impl Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<BanUser, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Ban a user
sourcepub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<UnbanUserResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<UserId>,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<UnbanUserResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Unban a user
sourcepub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Segment, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Segment, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get all scheduled streams in a channel.
Notes
Make sure to limit the data here using try_take_while
, otherwise this will never end on recurring scheduled streams.
Examples
use twitch_api::helix;
use futures::TryStreamExt;
let schedule: Vec<helix::schedule::Segment> = client
.get_channel_schedule("twitchdev", &token)
.try_take_while(|s| {
futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
})
.try_collect()
.await?;
sourcepub async fn get_global_emotes<T>(
&'a self,
token: &T
) -> Result<Vec<GlobalEmote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_global_emotes<T>(
&'a self,
token: &T
) -> Result<Vec<GlobalEmote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get all global emotes
sourcepub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<UserId>,
token: &T
) -> Result<Vec<ChannelEmote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<UserId>,
token: &T
) -> Result<Vec<ChannelEmote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get channel emotes in channel with user id
Examples found in repository?
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
sourcepub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<Vec<ChannelEmote>>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<UserName>,
token: &T
) -> Result<Option<Vec<ChannelEmote>>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get channel emotes in channel with user login
sourcepub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<EmoteSetId>>,
token: &T
) -> Result<Vec<Emote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<EmoteSetId>>,
token: &T
) -> Result<Vec<Emote>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get emotes in emote set
sourcepub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<Option<UserId>>,
token: &T
) -> Result<ChatSettings, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<Option<UserId>>,
token: &T
) -> Result<ChatSettings, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get a broadcaster’s chat settings
sourcepub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
message: impl Display,
color: impl TryInto<AnnouncementColor, Error = E>,
token: &T
) -> Result<SendChatAnnouncementResponse, ClientExtError<'a, C, E>>where
T: TwitchToken + ?Sized,
pub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
message: impl Display,
color: impl TryInto<AnnouncementColor, Error = E>,
token: &T
) -> Result<SendChatAnnouncementResponse, ClientExtError<'a, C, E>>where
T: TwitchToken + ?Sized,
Send a chat announcement
sourcepub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
message_id: impl Into<MsgId>,
token: &T
) -> Result<DeleteChatMessagesResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
message_id: impl Into<MsgId>,
token: &T
) -> Result<DeleteChatMessagesResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Delete a specific chat message
sourcepub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<DeleteChatMessagesResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<DeleteChatMessagesResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Delete all chat messages in a broadcasters chat room
sourcepub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<UserId>,
to_broadcaster_id: impl Into<UserId>,
token: &T
) -> Result<StartARaidResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<UserId>,
to_broadcaster_id: impl Into<UserId>,
token: &T
) -> Result<StartARaidResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Start a raid
sourcepub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &T
) -> Result<CancelARaidResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &T
) -> Result<CancelARaidResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Cancel a raid
sourcepub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<UserId>,
token: &T
) -> Result<Option<UserChatColor>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<UserId>,
token: &T
) -> Result<Option<UserChatColor>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get a users chat color
sourcepub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<UserId>,
color: impl Into<NamedUserColor<'static>>,
token: &T
) -> Result<UpdateUserChatColorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<UserId>,
color: impl Into<NamedUserColor<'static>>,
token: &T
) -> Result<UpdateUserChatColorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get a users chat color
sourcepub async fn get_users_chat_colors<T>(
&'a self,
user_ids: impl IntoIterator<Item = impl Into<UserId>>,
token: &T
) -> Result<Vec<UserChatColor>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn get_users_chat_colors<T>(
&'a self,
user_ids: impl IntoIterator<Item = impl Into<UserId>>,
token: &T
) -> Result<Vec<UserChatColor>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Get multiple users chat colors
sourcepub async fn add_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<AddChannelModeratorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn add_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<AddChannelModeratorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Add a channel moderator
sourcepub async fn remove_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<RemoveChannelModeratorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn remove_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
moderator_id: impl Into<UserId>,
token: &T
) -> Result<RemoveChannelModeratorResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Remove a channel moderator
sourcepub fn get_vips_in_channel<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Vip, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_vips_in_channel<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
token: &'a T
) -> Pin<Box<dyn Stream<Item = Result<Vip, ClientRequestError<<C as HttpClient<'a>>::Error>>> + 'a>>where
T: TwitchToken + Send + Sync + ?Sized,
Get channel VIPs
sourcepub async fn add_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
user_id: impl Into<UserId>,
token: &T
) -> Result<AddChannelVipResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn add_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
user_id: impl Into<UserId>,
token: &T
) -> Result<AddChannelVipResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Add a channel vip
sourcepub async fn remove_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
user_id: impl Into<UserId>,
token: &T
) -> Result<RemoveChannelVipResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn remove_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<UserId>,
user_id: impl Into<UserId>,
token: &T
) -> Result<RemoveChannelVipResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Remove a channel vip
sourcepub async fn send_whisper<T>(
&'a self,
from: impl Into<UserId>,
to: impl Into<UserId>,
message: impl Display,
token: &T
) -> Result<SendWhisperResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
pub async fn send_whisper<T>(
&'a self,
from: impl Into<UserId>,
to: impl Into<UserId>,
message: impl Display,
token: &T
) -> Result<SendWhisperResponse, ClientRequestError<<C as HttpClient<'a>>::Error>>where
T: TwitchToken + ?Sized,
Send a whisper
sourceimpl<'a, C: HttpClient<'a>> HelixClient<'a, C>
impl<'a, C: HttpClient<'a>> HelixClient<'a, C>
sourcepub async fn req_get_custom<'d, R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestGet,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
Available on crate feature unsupported
only.
pub async fn req_get_custom<'d, R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestGet,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
unsupported
only.Request on a valid RequestGet
endpoint, with the ability to return borrowed data and specific fields.
sourcepub async fn req_post_custom<'d, R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPost + RequestPost<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
Available on crate feature unsupported
only.
pub async fn req_post_custom<'d, R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPost + RequestPost<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
unsupported
only.Request on a valid RequestPost
endpoint, with the ability to return borrowed data and specific fields.
sourcepub async fn req_patch_custom<'d, R, B, D, T, F>(
&'a self,
request: R,
body: B,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPatch + RequestPatch<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestPatchError>,
Available on crate feature unsupported
only.
pub async fn req_patch_custom<'d, R, B, D, T, F>(
&'a self,
request: R,
body: B,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPatch + RequestPatch<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestPatchError>,
unsupported
only.Request on a valid RequestPatch
endpoint, with the ability to return borrowed data and specific fields.
Notes
This is probably not useful, as PATCH
endpoints do not usually return json
sourcepub async fn req_delete_custom<'d, R, D, T, F>(
&'a self,
request: R,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestDelete,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestDeleteError>,
Available on crate feature unsupported
only.
pub async fn req_delete_custom<'d, R, D, T, F>(
&'a self,
request: R,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestDelete,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestDeleteError>,
unsupported
only.Request on a valid RequestDelete
endpoint, with the ability to return borrowed data and specific fields.
Notes
This is probably not useful, as DELETE
endpoints do not usually return json
sourcepub async fn req_put_custom<'d, R, B, D, T, F>(
&'a self,
request: R,
body: B,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPut + RequestPut<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestDeleteError>,
Available on crate feature unsupported
only.
pub async fn req_put_custom<'d, R, B, D, T, F>(
&'a self,
request: R,
body: B,
token: &T,
function: F
) -> Result<CustomResponse<'d, R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request + RequestPut + RequestPut<Body = B>,
B: HelixRequestBody,
D: Deserialize<'d> + 'd,
T: TwitchToken + ?Sized,
C: Send,
F: Fn(&R, &Uri, &str, StatusCode) -> Result<(), HelixRequestDeleteError>,
unsupported
only.Request on a valid RequestPut
endpoint, with the ability to return borrowed data and specific fields.
Notes
This is probably not useful, as PUT
endpoints do not usually return json
sourceimpl<'a, C: HttpClient<'a>> HelixClient<'a, C>
impl<'a, C: HttpClient<'a>> HelixClient<'a, C>
sourcepub fn with_client(client: C) -> HelixClient<'a, C>
pub fn with_client(client: C) -> HelixClient<'a, C>
Create a new client with an existing client
Examples found in repository?
More examples
sourcepub fn new() -> HelixClient<'a, C>where
C: ClientDefault<'a>,
pub fn new() -> HelixClient<'a, C>where
C: ClientDefault<'a>,
Create a new HelixClient
with a default HttpClient
sourcepub fn clone_client(&self) -> Cwhere
C: Clone,
pub fn clone_client(&self) -> Cwhere
C: Clone,
Retrieve a clone of the HttpClient
inside this HelixClient
sourcepub fn get_client(&self) -> &C
pub fn get_client(&self) -> &C
Retrieve a reference of the HttpClient
inside this HelixClient
Examples found in repository?
229 230 231 232 233 234 235 236 237 238 239 240 241
pub fn get_client(&self) -> &C {
#[cfg(feature = "helix")]
{
self.helix.get_client()
}
#[cfg(not(feature = "helix"))]
{
#[cfg(feature = "tmi")]
{
self.tmi.get_client()
}
}
}
More examples
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
fn req(
&'a self,
request: http::Request<Vec<u8>>,
) -> BoxedFuture<
'a,
Result<http::Response<Vec<u8>>, <Self as twitch_oauth2::client::Client>::Error>,
> {
let client = self.get_client();
{
let request = request.map(Bytes::from);
let resp = client.req(request);
Box::pin(async {
let resp = resp.await?;
let (parts, mut body) = resp.into_parts();
Ok(http::Response::from_parts(
parts,
hyper::body::to_bytes(&mut body)
.await
.map_err(CompatError::BodyError)?
.to_vec(),
))
})
}
}
sourcepub async fn req_get<R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestGet,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
C: Send,
pub async fn req_get<R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestGet,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
C: Send,
Request on a valid RequestGet
endpoint
let req = channels::GetChannelInformationRequest::broadcaster_id("123456");
let client = HelixClient::new();
let response = client.req_get(req, &token).await;
Examples found in repository?
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
pub async fn get_user_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<helix::users::User>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
self.req_get(helix::users::GetUsersRequest::login(login), token)
.await
.map(|response| response.first())
}
/// Get [User](helix::users::User) from user id
pub async fn get_user_from_id<T>(
&'a self,
id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::users::User>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
self.req_get(helix::users::GetUsersRequest::id(id), token)
.await
.map(|response| response.first())
}
/// Get [ChannelInformation](helix::channels::ChannelInformation) from a broadcasters login
pub async fn get_channel_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<helix::channels::ChannelInformation>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_from_id(user.id, token).await
} else {
Ok(None)
}
}
/// Get [ChannelInformation](helix::channels::ChannelInformation) from a broadcasters id
pub async fn get_channel_from_id<T>(
&'a self,
id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::channels::ChannelInformation>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
self.req_get(
helix::channels::GetChannelInformationRequest::broadcaster_id(id),
token,
)
.await
.map(|response| response.first())
}
/// Get chatters in a stream [Chatter][helix::chat::Chatter]
///
/// `batch_size` sets the amount of chatters to retrieve per api call, max 1000, defaults to 100.
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let chatters: Vec<helix::chat::Chatter> = client.get_chatters("1234", "4321", 1000, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_chatters<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
batch_size: impl Into<Option<usize>>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::chat::Chatter, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::chat::GetChattersRequest {
first: batch_size.into(),
..helix::chat::GetChattersRequest::new(broadcaster_id, moderator_id)
};
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Search [Categories](helix::search::Category)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn search_categories<T>(
&'a self,
query: impl Into<String>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::search::Category, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::search::SearchCategoriesRequest::query(query).first(100);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Search [Channels](helix::search::Channel) via channel name or description
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let channel: Vec<helix::search::Channel> = client.search_channels("twitchdev", false, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn search_channels<T>(
&'a self,
query: impl Into<String>,
live_only: bool,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::search::Channel, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::search::SearchChannelsRequest::query(query.into()).live_only(live_only);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get information on a [follow relationship](helix::users::FollowRelationship)
///
/// Can be used to see if X follows Y
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::{types, helix};
/// use futures::TryStreamExt;
///
/// // Get the followers of channel "1234"
/// let followers: Vec<helix::users::FollowRelationship> = client.get_follow_relationships(types::UserId::from("1234"), None, &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_follow_relationships<T>(
&'a self,
to_id: impl Into<Option<types::UserId>>,
from_id: impl Into<Option<types::UserId>>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::users::FollowRelationship, ClientError<'a, C>>>
+ Send
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let mut req = helix::users::GetUsersFollowsRequest::empty();
req.to_id = to_id.into();
req.from_id = from_id.into();
make_stream(req, token, self, |s| {
std::collections::VecDeque::from(s.follow_relationships)
})
}
/// Get authenticated users' followed [streams](helix::streams::Stream)
///
/// Requires token with scope [`user:read:follows`](twitch_oauth2::Scope::UserReadFollows).
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let channels: Vec<helix::streams::Stream> = client.get_followed_streams(&token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_followed_streams<T>(
&'a self,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::streams::Stream, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
use futures::StreamExt;
let user_id = match token
.user_id()
.ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
{
Ok(t) => t,
Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
};
let req = helix::streams::GetFollowedStreamsRequest::user_id(user_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get authenticated broadcasters' [subscribers](helix::subscriptions::BroadcasterSubscription)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let subs: Vec<helix::subscriptions::BroadcasterSubscription> = client.get_broadcaster_subscriptions(&token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_broadcaster_subscriptions<T>(
&'a self,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<
Item = Result<
helix::subscriptions::BroadcasterSubscription,
ClientError<'a, C>,
>,
> + 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
use futures::StreamExt;
let user_id = match token
.user_id()
.ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
{
Ok(t) => t,
Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
};
let req = helix::subscriptions::GetBroadcasterSubscriptionsRequest::broadcaster_id(user_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get all moderators in a channel [Get Moderators](helix::moderation::GetModeratorsRequest)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let moderators: Vec<helix::moderation::Moderator> = client.get_moderators_in_channel_from_id("twitchdev", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_moderators_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::moderation::Moderator, ClientError<'a, C>>>
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::moderation::GetModeratorsRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get all banned users in a channel [Get Banned Users](helix::moderation::GetBannedUsersRequest)
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let moderators: Vec<helix::moderation::BannedUser> = client.get_banned_users_in_channel_from_id("twitchdev", &token).try_collect().await?;
///
/// # Ok(()) }
/// ```
pub fn get_banned_users_in_channel_from_id<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<
dyn futures::Stream<Item = Result<helix::moderation::BannedUser, ClientError<'a, C>>>
+ 'a,
>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::moderation::GetBannedUsersRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Get a users, with login, follow count
pub async fn get_total_followers_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<i64>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_total_followers_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get a users, with id, follow count
///
/// # Notes
///
/// This returns zero if the user doesn't exist
pub async fn get_total_followers_from_id<T>(
&'a self,
to_id: impl Into<types::UserId>,
token: &T,
) -> Result<i64, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let resp = self
.req_get(
helix::users::GetUsersFollowsRequest::followers(to_id),
token,
)
.await?;
Ok(resp.data.total)
}
/// Get games by ID. Can only be at max 100 ids.
pub async fn get_games_by_id<T>(
&'a self,
ids: impl IntoIterator<Item = impl Into<types::CategoryId>>,
token: &T,
) -> Result<std::collections::HashMap<types::CategoryId, helix::games::Game>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let ids: Vec<_> = ids.into_iter().take(101).map(Into::into).collect();
if ids.len() > 100 {
return Err(ClientRequestError::Custom("too many IDs, max 100".into()));
}
let resp = self
.req_get(helix::games::GetGamesRequest::ids(ids), token)
.await?;
Ok(resp
.data
.into_iter()
.map(|g: helix::games::Game| (g.id.clone(), g))
.collect())
}
/// Block a user
pub async fn block_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::BlockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_put(
helix::users::BlockUserRequest::block_user(target_user_id),
helix::EmptyBody,
token,
)
.await?
.data)
}
/// Unblock a user
pub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::UnblockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::users::UnblockUserRequest::unblock_user(target_user_id),
token,
)
.await?
.data)
}
/// Ban a user
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
reason: impl std::fmt::Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_post(
helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
helix::moderation::BanUserBody::new(target_user_id, reason.to_string(), duration),
token,
)
.await?
.data)
}
/// Unban a user
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::moderation::UnbanUserRequest::new(
broadcaster_id,
moderator_id,
target_user_id,
),
token,
)
.await?
.data)
}
// FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
/// Get all scheduled streams in a channel.
///
/// # Notes
///
/// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
///
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let schedule: Vec<helix::schedule::Segment> = client
/// .get_channel_schedule("twitchdev", &token)
/// .try_take_while(|s| {
/// futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
/// })
/// .try_collect()
/// .await?;
///
/// # Ok(()) }
/// ```
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
}
/// Get all global emotes
pub async fn get_global_emotes<T>(
&'a self,
token: &T,
) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetGlobalEmotesRequest::new();
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user id
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user login
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get emotes in emote set
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<types::EmoteSetId>>,
token: &T,
) -> Result<Vec<helix::chat::get_emote_sets::Emote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetEmoteSetsRequest::emote_set_ids(emote_sets);
Ok(self.req_get(req, token).await?.data)
}
/// Get a broadcaster's chat settings
pub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<Option<types::UserId>>,
token: &T,
) -> Result<helix::chat::ChatSettings, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let mut req = helix::chat::GetChatSettingsRequest::broadcaster_id(broadcaster_id);
if let Some(moderator_id) = moderator_id.into() {
req = req.moderator_id(moderator_id);
}
Ok(self.req_get(req, token).await?.data)
}
/// Send a chat announcement
pub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message: impl std::fmt::Display,
color: impl std::convert::TryInto<helix::chat::AnnouncementColor, Error = E>,
token: &T,
) -> Result<helix::chat::SendChatAnnouncementResponse, ClientExtError<'a, C, E>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::SendChatAnnouncementRequest::new(broadcaster_id, moderator_id);
let body = helix::chat::SendChatAnnouncementBody::new(message.to_string(), color)?;
Ok(self
.req_post(req, body, token)
.await
.map_err(ClientExtError::ClientError)?
.data)
}
/// Delete a specific chat message
pub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message_id: impl Into<types::MsgId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id)
.message_id(message_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Delete all chat messages in a broadcasters chat room
pub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Start a raid
pub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<types::UserId>,
to_broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::StartARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::StartARaidRequest::new(from_broadcaster_id, to_broadcaster_id);
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Cancel a raid
pub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::CancelARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::CancelARaidRequest::broadcaster_id(broadcaster_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Get a users chat color
pub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest {
user_id: vec![user_id.into()],
};
Ok(self.req_get(req, token).await?.first())
}
/// Get a users chat color
pub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
color: impl Into<types::NamedUserColor<'static>>,
token: &T,
) -> Result<helix::chat::UpdateUserChatColorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::UpdateUserChatColorRequest {
user_id: user_id.into(),
color: color.into(),
};
Ok(self.req_put(req, helix::EmptyBody, token).await?.data)
}
/// Get multiple users chat colors
pub async fn get_users_chat_colors<T>(
&'a self,
user_ids: impl IntoIterator<Item = impl Into<types::UserId>>,
token: &T,
) -> Result<Vec<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest::user_ids(user_ids);
Ok(self.req_get(req, token).await?.data)
}
/// Add a channel moderator
pub async fn add_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::AddChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::AddChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel moderator
pub async fn remove_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::RemoveChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::RemoveChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
/// Get channel VIPs
pub fn get_vips_in_channel<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::channels::Vip, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::channels::GetVipsRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Add a channel vip
pub async fn add_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::AddChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::AddChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel vip
pub async fn remove_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::RemoveChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::RemoveChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
/// Send a whisper
pub async fn send_whisper<T>(
&'a self,
from: impl Into<types::UserId>,
to: impl Into<types::UserId>,
message: impl std::fmt::Display,
token: &T,
) -> Result<helix::whispers::SendWhisperResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::whispers::SendWhisperRequest::new(from, to);
let body = helix::whispers::SendWhisperBody::new(message);
Ok(self.req_post(req, body, token).await?.data)
}
}
#[derive(Debug, thiserror::Error)]
pub enum ClientExtError<'a, C: crate::HttpClient<'a>, E> {
#[error(transparent)]
ClientError(ClientError<'a, C>),
#[error(transparent)]
Other(#[from] E),
}
/// Make a paginate-able request into a stream
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let req = helix::moderation::GetModeratorsRequest::broadcaster_id("1234");
///
/// helix::make_stream(req, &token, &client, std::collections::VecDeque::from).try_collect::<Vec<_>>().await?
/// # ;
/// # Ok(())
/// # }
/// ```
pub fn make_stream<
'a,
C: crate::HttpClient<'a> + Send + Sync,
T: TwitchToken + ?Sized + Send + Sync,
// FIXME: Why does this have to be clone and debug?
Req: super::Request
+ super::RequestGet
+ super::Paginated
+ Clone
+ std::fmt::Debug
+ Send
+ Sync
+ 'a,
// FIXME: this 'a seems suspicious
Item: Send + 'a,
>(
req: Req,
token: &'a T,
client: &'a super::HelixClient<'a, C>,
fun: impl Fn(<Req as super::Request>::Response) -> std::collections::VecDeque<Item>
+ Send
+ Sync
+ Copy
+ 'static,
) -> std::pin::Pin<Box<dyn futures::Stream<Item = Result<Item, ClientError<'a, C>>> + 'a + Send>>
where
// FIXME: This clone is bad. I want to be able to return the data, but not in a way that limits the response to be Default
// I also want to keep allocations low, so std::mem::take is perfect, but that makes get_next not work optimally.
<Req as super::Request>::Response: Send + Sync + std::fmt::Debug + Clone,
{
use futures::StreamExt;
enum StateMode<Req: super::Request + super::RequestGet, Item> {
/// A request needs to be done.
Req(Option<Req>),
/// We have made a request, now working through the data
Cont(
super::Response<Req, <Req as super::Request>::Response>,
std::collections::VecDeque<Item>,
),
Next(Option<super::Response<Req, <Req as super::Request>::Response>>),
/// The operation failed, allowing no further processing
Failed,
}
impl<Req: super::Request + super::RequestGet, Item> StateMode<Req, Item> {
fn take_initial(&mut self) -> Req {
match self {
StateMode::Req(ref mut r) if r.is_some() => std::mem::take(r).expect("oops"),
_ => todo!("hmmm"),
}
}
fn take_next(&mut self) -> super::Response<Req, <Req as super::Request>::Response> {
match self {
StateMode::Next(ref mut r) if r.is_some() => std::mem::take(r).expect("oops"),
_ => todo!("hmmm"),
}
}
}
struct State<
'a,
C: crate::HttpClient<'a>,
T: TwitchToken + ?Sized,
Req: super::Request + super::RequestGet,
Item,
> {
mode: StateMode<Req, Item>,
client: &'a HelixClient<'a, C>,
token: &'a T,
}
impl<
'a,
C: crate::HttpClient<'a>,
T: TwitchToken + ?Sized,
Req: super::Request + super::RequestGet + super::Paginated,
Item,
> State<'a, C, T, Req, Item>
{
/// Process a request, with a given deq
fn process(
mut self,
r: super::Response<Req, <Req as super::Request>::Response>,
d: std::collections::VecDeque<Item>,
) -> Self {
self.mode = StateMode::Cont(r, d);
self
}
fn failed(mut self) -> Self {
self.mode = StateMode::Failed;
self
}
/// get the next
fn get_next(mut self) -> Self {
match self.mode {
StateMode::Cont(r, d) => {
assert!(d.is_empty());
self.mode = StateMode::Next(Some(r));
self
}
_ => panic!("oops"),
}
}
}
let statemode = StateMode::Req(Some(req));
let state = State {
mode: statemode,
client,
token,
};
futures::stream::unfold(state, move |mut state: State<_, _, _, _>| async move {
match state.mode {
StateMode::Req(Some(_)) => {
let req = state.mode.take_initial();
let f = state.client.req_get(req, state.token);
let resp = match f.await {
Ok(resp) => resp,
Err(e) => return Some((Err(e), state.failed())),
};
let mut deq = fun(resp.data.clone());
deq.pop_front().map(|d| (Ok(d), state.process(resp, deq)))
}
StateMode::Cont(_, ref mut deq) => {
if let Some(d) = deq.pop_front() {
if deq.is_empty() {
Some((Ok(d), state.get_next()))
} else {
Some((Ok(d), state))
}
} else {
// New request returned empty.
None
}
}
StateMode::Next(Some(_)) => {
let resp = state.mode.take_next();
let f = resp.get_next(state.client, state.token);
let resp = match f.await {
Ok(Some(resp)) => resp,
Ok(None) => return None,
Err(e) => return Some((Err(e), state.failed())),
};
let mut deq = fun(resp.data.clone());
deq.pop_front().map(|d| (Ok(d), state.process(resp, deq)))
}
_ => todo!("failed to process request"),
}
})
.boxed()
}
More examples
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
pub async fn get_next<'a, C: crate::HttpClient<'a>>(
self,
client: &'a super::HelixClient<'a, C>,
token: &(impl super::TwitchToken + ?Sized),
) -> Result<
Option<Response<R, D>>,
super::ClientRequestError<<C as crate::HttpClient<'a>>::Error>,
> {
if let Some(mut req) = self.request.clone() {
if self.pagination.is_some() {
req.set_pagination(self.pagination);
let res = client.req_get(req, token).await.map(Some);
if let Ok(Some(r)) = res {
// FIXME: Workaround for https://github.com/twitchdev/issues/issues/18
if r.data == self.data {
Ok(None)
} else {
Ok(Some(r))
}
} else {
res
}
} else {
Ok(None)
}
} else {
// TODO: Make into proper error
Err(super::ClientRequestError::Custom(
"no source request attached".into(),
))
}
}
sourcepub async fn req_post<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPost<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
pub async fn req_post<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPost<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
Request on a valid RequestPost
endpoint
Examples found in repository?
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
reason: impl std::fmt::Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_post(
helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
helix::moderation::BanUserBody::new(target_user_id, reason.to_string(), duration),
token,
)
.await?
.data)
}
/// Unban a user
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::moderation::UnbanUserRequest::new(
broadcaster_id,
moderator_id,
target_user_id,
),
token,
)
.await?
.data)
}
// FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
/// Get all scheduled streams in a channel.
///
/// # Notes
///
/// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
///
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let schedule: Vec<helix::schedule::Segment> = client
/// .get_channel_schedule("twitchdev", &token)
/// .try_take_while(|s| {
/// futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
/// })
/// .try_collect()
/// .await?;
///
/// # Ok(()) }
/// ```
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
}
/// Get all global emotes
pub async fn get_global_emotes<T>(
&'a self,
token: &T,
) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetGlobalEmotesRequest::new();
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user id
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user login
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get emotes in emote set
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<types::EmoteSetId>>,
token: &T,
) -> Result<Vec<helix::chat::get_emote_sets::Emote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetEmoteSetsRequest::emote_set_ids(emote_sets);
Ok(self.req_get(req, token).await?.data)
}
/// Get a broadcaster's chat settings
pub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<Option<types::UserId>>,
token: &T,
) -> Result<helix::chat::ChatSettings, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let mut req = helix::chat::GetChatSettingsRequest::broadcaster_id(broadcaster_id);
if let Some(moderator_id) = moderator_id.into() {
req = req.moderator_id(moderator_id);
}
Ok(self.req_get(req, token).await?.data)
}
/// Send a chat announcement
pub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message: impl std::fmt::Display,
color: impl std::convert::TryInto<helix::chat::AnnouncementColor, Error = E>,
token: &T,
) -> Result<helix::chat::SendChatAnnouncementResponse, ClientExtError<'a, C, E>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::SendChatAnnouncementRequest::new(broadcaster_id, moderator_id);
let body = helix::chat::SendChatAnnouncementBody::new(message.to_string(), color)?;
Ok(self
.req_post(req, body, token)
.await
.map_err(ClientExtError::ClientError)?
.data)
}
/// Delete a specific chat message
pub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message_id: impl Into<types::MsgId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id)
.message_id(message_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Delete all chat messages in a broadcasters chat room
pub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Start a raid
pub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<types::UserId>,
to_broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::StartARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::StartARaidRequest::new(from_broadcaster_id, to_broadcaster_id);
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Cancel a raid
pub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::CancelARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::CancelARaidRequest::broadcaster_id(broadcaster_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Get a users chat color
pub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest {
user_id: vec![user_id.into()],
};
Ok(self.req_get(req, token).await?.first())
}
/// Get a users chat color
pub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
color: impl Into<types::NamedUserColor<'static>>,
token: &T,
) -> Result<helix::chat::UpdateUserChatColorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::UpdateUserChatColorRequest {
user_id: user_id.into(),
color: color.into(),
};
Ok(self.req_put(req, helix::EmptyBody, token).await?.data)
}
/// Get multiple users chat colors
pub async fn get_users_chat_colors<T>(
&'a self,
user_ids: impl IntoIterator<Item = impl Into<types::UserId>>,
token: &T,
) -> Result<Vec<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest::user_ids(user_ids);
Ok(self.req_get(req, token).await?.data)
}
/// Add a channel moderator
pub async fn add_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::AddChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::AddChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel moderator
pub async fn remove_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::RemoveChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::RemoveChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
/// Get channel VIPs
pub fn get_vips_in_channel<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::channels::Vip, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::channels::GetVipsRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Add a channel vip
pub async fn add_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::AddChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::AddChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel vip
pub async fn remove_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::RemoveChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::RemoveChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
/// Send a whisper
pub async fn send_whisper<T>(
&'a self,
from: impl Into<types::UserId>,
to: impl Into<types::UserId>,
message: impl std::fmt::Display,
token: &T,
) -> Result<helix::whispers::SendWhisperResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::whispers::SendWhisperRequest::new(from, to);
let body = helix::whispers::SendWhisperBody::new(message);
Ok(self.req_post(req, body, token).await?.data)
}
sourcepub async fn req_patch<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPatch<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
pub async fn req_patch<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPatch<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
Request on a valid RequestPatch
endpoint
sourcepub async fn req_delete<R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestDelete,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
pub async fn req_delete<R, D, T>(
&'a self,
request: R,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestDelete,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
Request on a valid RequestDelete
endpoint
Examples found in repository?
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
pub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::UnblockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::users::UnblockUserRequest::unblock_user(target_user_id),
token,
)
.await?
.data)
}
/// Ban a user
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
reason: impl std::fmt::Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_post(
helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
helix::moderation::BanUserBody::new(target_user_id, reason.to_string(), duration),
token,
)
.await?
.data)
}
/// Unban a user
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::moderation::UnbanUserRequest::new(
broadcaster_id,
moderator_id,
target_user_id,
),
token,
)
.await?
.data)
}
// FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
/// Get all scheduled streams in a channel.
///
/// # Notes
///
/// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
///
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let schedule: Vec<helix::schedule::Segment> = client
/// .get_channel_schedule("twitchdev", &token)
/// .try_take_while(|s| {
/// futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
/// })
/// .try_collect()
/// .await?;
///
/// # Ok(()) }
/// ```
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
}
/// Get all global emotes
pub async fn get_global_emotes<T>(
&'a self,
token: &T,
) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetGlobalEmotesRequest::new();
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user id
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user login
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get emotes in emote set
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<types::EmoteSetId>>,
token: &T,
) -> Result<Vec<helix::chat::get_emote_sets::Emote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetEmoteSetsRequest::emote_set_ids(emote_sets);
Ok(self.req_get(req, token).await?.data)
}
/// Get a broadcaster's chat settings
pub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<Option<types::UserId>>,
token: &T,
) -> Result<helix::chat::ChatSettings, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let mut req = helix::chat::GetChatSettingsRequest::broadcaster_id(broadcaster_id);
if let Some(moderator_id) = moderator_id.into() {
req = req.moderator_id(moderator_id);
}
Ok(self.req_get(req, token).await?.data)
}
/// Send a chat announcement
pub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message: impl std::fmt::Display,
color: impl std::convert::TryInto<helix::chat::AnnouncementColor, Error = E>,
token: &T,
) -> Result<helix::chat::SendChatAnnouncementResponse, ClientExtError<'a, C, E>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::SendChatAnnouncementRequest::new(broadcaster_id, moderator_id);
let body = helix::chat::SendChatAnnouncementBody::new(message.to_string(), color)?;
Ok(self
.req_post(req, body, token)
.await
.map_err(ClientExtError::ClientError)?
.data)
}
/// Delete a specific chat message
pub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message_id: impl Into<types::MsgId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id)
.message_id(message_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Delete all chat messages in a broadcasters chat room
pub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Start a raid
pub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<types::UserId>,
to_broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::StartARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::StartARaidRequest::new(from_broadcaster_id, to_broadcaster_id);
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Cancel a raid
pub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::CancelARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::CancelARaidRequest::broadcaster_id(broadcaster_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Get a users chat color
pub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest {
user_id: vec![user_id.into()],
};
Ok(self.req_get(req, token).await?.first())
}
/// Get a users chat color
pub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
color: impl Into<types::NamedUserColor<'static>>,
token: &T,
) -> Result<helix::chat::UpdateUserChatColorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::UpdateUserChatColorRequest {
user_id: user_id.into(),
color: color.into(),
};
Ok(self.req_put(req, helix::EmptyBody, token).await?.data)
}
/// Get multiple users chat colors
pub async fn get_users_chat_colors<T>(
&'a self,
user_ids: impl IntoIterator<Item = impl Into<types::UserId>>,
token: &T,
) -> Result<Vec<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest::user_ids(user_ids);
Ok(self.req_get(req, token).await?.data)
}
/// Add a channel moderator
pub async fn add_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::AddChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::AddChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel moderator
pub async fn remove_channel_moderator<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::RemoveChannelModeratorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::RemoveChannelModeratorRequest {
broadcaster_id: broadcaster_id.into(),
moderator_id: moderator_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
/// Get channel VIPs
pub fn get_vips_in_channel<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::channels::Vip, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::channels::GetVipsRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, std::collections::VecDeque::from)
}
/// Add a channel vip
pub async fn add_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::AddChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::AddChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Remove a channel vip
pub async fn remove_channel_vip<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::channels::RemoveChannelVipResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::channels::RemoveChannelVipRequest {
broadcaster_id: broadcaster_id.into(),
user_id: user_id.into(),
};
Ok(self.req_delete(req, token).await?.data)
}
sourcepub async fn req_put<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPut<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
pub async fn req_put<R, B, D, T>(
&'a self,
request: R,
body: B,
token: &T
) -> Result<Response<R, D>, ClientRequestError<<C as HttpClient<'a>>::Error>>where
R: Request<Response = D> + Request + RequestPut<Body = B>,
B: HelixRequestBody,
D: DeserializeOwned + PartialEq,
T: TwitchToken + ?Sized,
Request on a valid RequestPut
endpoint
Examples found in repository?
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
pub async fn block_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::BlockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_put(
helix::users::BlockUserRequest::block_user(target_user_id),
helix::EmptyBody,
token,
)
.await?
.data)
}
/// Unblock a user
pub async fn unblock_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::users::UnblockUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::users::UnblockUserRequest::unblock_user(target_user_id),
token,
)
.await?
.data)
}
/// Ban a user
pub async fn ban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
reason: impl std::fmt::Display,
duration: impl Into<Option<u32>>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_post(
helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
helix::moderation::BanUserBody::new(target_user_id, reason.to_string(), duration),
token,
)
.await?
.data)
}
/// Unban a user
pub async fn unban_user<T>(
&'a self,
target_user_id: impl Into<types::UserId>,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
Ok(self
.req_delete(
helix::moderation::UnbanUserRequest::new(
broadcaster_id,
moderator_id,
target_user_id,
),
token,
)
.await?
.data)
}
// FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
/// Get all scheduled streams in a channel.
///
/// # Notes
///
/// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
///
///
/// # Examples
///
/// ```rust, no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
/// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
/// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
/// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
/// use twitch_api::helix;
/// use futures::TryStreamExt;
///
/// let schedule: Vec<helix::schedule::Segment> = client
/// .get_channel_schedule("twitchdev", &token)
/// .try_take_while(|s| {
/// futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
/// })
/// .try_collect()
/// .await?;
///
/// # Ok(()) }
/// ```
pub fn get_channel_schedule<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
>
where
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);
make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
}
/// Get all global emotes
pub async fn get_global_emotes<T>(
&'a self,
token: &T,
) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetGlobalEmotesRequest::new();
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user id
pub async fn get_channel_emotes_from_id<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
Ok(self.req_get(req, token).await?.data)
}
/// Get channel emotes in channel with user login
pub async fn get_channel_emotes_from_login<T>(
&'a self,
login: impl Into<types::UserName>,
token: &T,
) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
if let Some(user) = self.get_user_from_login(login, token).await? {
self.get_channel_emotes_from_id(user.id, token)
.await
.map(Some)
} else {
Ok(None)
}
}
/// Get emotes in emote set
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: impl IntoIterator<Item = impl Into<types::EmoteSetId>>,
token: &T,
) -> Result<Vec<helix::chat::get_emote_sets::Emote>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetEmoteSetsRequest::emote_set_ids(emote_sets);
Ok(self.req_get(req, token).await?.data)
}
/// Get a broadcaster's chat settings
pub async fn get_chat_settings<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<Option<types::UserId>>,
token: &T,
) -> Result<helix::chat::ChatSettings, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let mut req = helix::chat::GetChatSettingsRequest::broadcaster_id(broadcaster_id);
if let Some(moderator_id) = moderator_id.into() {
req = req.moderator_id(moderator_id);
}
Ok(self.req_get(req, token).await?.data)
}
/// Send a chat announcement
pub async fn send_chat_announcement<T, E>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message: impl std::fmt::Display,
color: impl std::convert::TryInto<helix::chat::AnnouncementColor, Error = E>,
token: &T,
) -> Result<helix::chat::SendChatAnnouncementResponse, ClientExtError<'a, C, E>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::SendChatAnnouncementRequest::new(broadcaster_id, moderator_id);
let body = helix::chat::SendChatAnnouncementBody::new(message.to_string(), color)?;
Ok(self
.req_post(req, body, token)
.await
.map_err(ClientExtError::ClientError)?
.data)
}
/// Delete a specific chat message
pub async fn delete_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
message_id: impl Into<types::MsgId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id)
.message_id(message_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Delete all chat messages in a broadcasters chat room
pub async fn delete_all_chat_message<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
moderator_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Start a raid
pub async fn start_a_raid<T>(
&'a self,
from_broadcaster_id: impl Into<types::UserId>,
to_broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::StartARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::StartARaidRequest::new(from_broadcaster_id, to_broadcaster_id);
Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
}
/// Cancel a raid
pub async fn cancel_a_raid<T>(
&'a self,
broadcaster_id: impl Into<types::UserId>,
token: &T,
) -> Result<helix::raids::CancelARaidResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::raids::CancelARaidRequest::broadcaster_id(broadcaster_id);
Ok(self.req_delete(req, token).await?.data)
}
/// Get a users chat color
pub async fn get_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
token: &T,
) -> Result<Option<helix::chat::UserChatColor>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::GetUserChatColorRequest {
user_id: vec![user_id.into()],
};
Ok(self.req_get(req, token).await?.first())
}
/// Get a users chat color
pub async fn update_user_chat_color<T>(
&'a self,
user_id: impl Into<types::UserId>,
color: impl Into<types::NamedUserColor<'static>>,
token: &T,
) -> Result<helix::chat::UpdateUserChatColorResponse, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
let req = helix::chat::UpdateUserChatColorRequest {
user_id: user_id.into(),
color: color.into(),
};
Ok(self.req_put(req, helix::EmptyBody, token).await?.data)
}
Trait Implementations
sourceimpl<'a, C: Client<'a> + Sync> Client<'a> for HelixClient<'a, C>
impl<'a, C: Client<'a> + Sync> Client<'a> for HelixClient<'a, C>
sourceimpl<'a, C: Clone> Clone for HelixClient<'a, C>where
C: HttpClient<'a>,
impl<'a, C: Clone> Clone for HelixClient<'a, C>where
C: HttpClient<'a>,
sourcefn clone(&self) -> HelixClient<'a, C>
fn clone(&self) -> HelixClient<'a, C>
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more