Struct twitch_api2::HelixClient [−][src]
pub struct HelixClient<'a, C> where
C: HttpClient<'a>, { /* fields omitted */ }
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>(
&'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
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,
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
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,
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
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,
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
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,
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_api2::helix;
use futures::TryStreamExt;
let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
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,
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,
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>>> + '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>>> + '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>(
&'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,
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,
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_api2::helix;
use futures::TryStreamExt;
let subs: Vec<helix::subscriptions::BroadcasterSubscription> = client.get_broadcaster_subscriptions(&token).try_collect().await?;
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,
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_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>(
&'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
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,
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,
pub async fn get_games_by_id<T>(
&'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>(
&'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>(
&'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
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,
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
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,
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_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?;
pub 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
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,
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
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,
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
pub async fn get_emote_sets<T>(
&'a self,
emote_sets: &[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: &[EmoteSetId],
token: &T
) -> Result<Vec<Emote>, ClientRequestError<<C as HttpClient<'a>>::Error>> where
T: TwitchToken + ?Sized,
Get emotes in emote set
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>(
&'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::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>(
&'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
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,
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
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,
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
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,
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
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,
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,
Request on a valid RequestGet
endpoint, with the ability to return borrowed data and specific fields.
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,
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,
Request on a valid RequestPost
endpoint, with the ability to return borrowed data and specific fields.
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>,
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>,
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
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>,
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>,
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
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>,
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>,
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
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
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
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