pub struct HelixClient<'a, C> where
    C: HttpClient<'a>, 
{ /* private fields */ }
Available on crate features 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::{users::User, HelixClient};
let user: Option<User> = client
    .get_user_from_login("justintv".to_string(), &token)
    .await
    .unwrap();

Implementations

Get User from user login

Get User from user id

Get ChannelInformation from a broadcasters login

Get ChannelInformation from a broadcasters id

Search Categories

Examples
use twitch_api2::helix;
use futures::TryStreamExt;

let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;

Search Channels via channel name or description

Examples
use twitch_api2::helix;
use futures::TryStreamExt;

let channel: Vec<helix::search::Channel> = client.search_channels("twitchdev", false, &token).try_collect().await?;

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?;

Get authenticated users’ followed streams

Examples
use twitch_api2::helix;
use futures::TryStreamExt;

let channels: Vec<helix::streams::Stream> = client.get_followed_streams(&token).try_collect().await?;

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?;

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?;

Get all banned users in a channel Get Banned Users

Examples
use twitch_api2::helix;
use futures::TryStreamExt;

let moderators: Vec<helix::moderation::BannedUser> = client.get_banned_users_in_channel_from_id("twitchdev", &token).try_collect().await?;

Get a users, with login, follow count

Get a users, with id, follow count

Notes

This returns zero if the user doesn’t exist

Get games by ID. Can only be at max 100 ids.

Block a user

Unblock a user

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?;

Get all global emotes

Get channel emotes in channel with user id

Get channel emotes in channel with user login

Get emotes in emote set

Available on crate feature unsupported only.

Request on a valid RequestGet endpoint, with the ability to return borrowed data and specific fields.

source

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

Available on crate feature unsupported only.

Request on a valid RequestPost endpoint, with the ability to return borrowed data and specific fields.

Available on crate feature 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

Available on crate feature 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

Available on crate feature 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

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

Retrieve a reference of the HttpClient inside this HelixClient

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;
source

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

Request on a valid RequestPatch endpoint

Request on a valid RequestDelete endpoint

Request on a valid RequestPut endpoint

Trait Implementations

Error returned by the client

Send a request

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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