Struct twitch_api2::HelixClient [−][src]
pub struct HelixClient<'a, C> where
C: HttpClient<'a>, { /* fields omitted */ }
client
and helix
only.Expand description
Client for Helix or the New Twitch API
Provides HelixClient::req_get
for requesting endpoints which uses GET method.
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.
let client: HelixClient<'static, reqwest::Client> = HelixClient::default(); use twitch_api2::helix::{HelixClient, users::User}; let user: Option<User> = client .get_user_from_login("justintv".to_string(), &token).await.unwrap();
Implementations
pub async fn get_user_from_login<T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn get_user_from_id<T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn get_channel_from_login<T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn get_channel_from_id<T: ?Sized>(
&'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: ?Sized>(
&'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
pub fn search_categories<T: ?Sized>(
&'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: ?Sized>(
&'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_api2::helix; use futures::TryStreamExt; let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
pub fn search_channels<T: ?Sized>(
&'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: ?Sized>(
&'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 get_follow_relationships<T: ?Sized>(
&'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>>> + 'a>> where
T: TwitchToken + Send + Sync + ?Sized,
pub fn get_follow_relationships<T: ?Sized>(
&'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>>> + '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_api2::{types, helix}; use futures::TryStreamExt; // Get the followers of channel "1234" let followers: Vec<helix::users::FollowRelationship> = client.get_follow_relationships(types::UserId::new("1234"), None, &token).try_collect().await?;
pub fn get_followed_streams<T: ?Sized>(
&'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: ?Sized>(
&'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_moderators_in_channel_from_id<T: ?Sized>(
&'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: ?Sized>(
&'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_api2::helix; use futures::TryStreamExt; let moderators: Vec<helix::moderation::Moderator> = client.get_moderators_in_channel_from_id("twitchdev", &token).try_collect().await?;
pub async fn get_total_followers_from_login<T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn get_total_followers_from_id<T: ?Sized>(
&'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: ?Sized>(
&'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_games_by_id<T: ?Sized>(
&'a self,
ids: &[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: ?Sized>(
&'a self,
ids: &[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.
pub async fn block_user<T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn unblock_user<T: ?Sized>(
&'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: ?Sized>(
&'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
pub fn get_channel_schedule<T: ?Sized>(
&'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: ?Sized>(
&'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_api2::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?;
Create a new client with an existing client
Create a new HelixClient
with a default HttpClient
Retrieve a clone of the HttpClient
inside this HelixClient
pub async fn req_get<R, D, T: ?Sized>(
&'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: ?Sized>(
&'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::builder().broadcaster_id("123456").build(); let client = HelixClient::new(); let response = client.req_get(req, &token).await;
pub async fn req_post<R, B, D, T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn req_patch<R, B, D, T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn req_delete<R, D, T: ?Sized>(
&'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: ?Sized>(
&'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
pub async fn req_put<R, B, D, T: ?Sized>(
&'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: ?Sized>(
&'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
Trait Implementations
Auto Trait Implementations
impl<'a, C> RefUnwindSafe for HelixClient<'a, C> where
C: RefUnwindSafe,
impl<'a, C> Send for HelixClient<'a, C>
impl<'a, C> Sync for HelixClient<'a, C> where
C: Sync,
impl<'a, C> Unpin for HelixClient<'a, C> where
C: Unpin,
impl<'a, C> UnwindSafe for HelixClient<'a, C> where
C: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more