Crate twitch_api2[][src]

githubcrates-iodocs-rs-big


Rust library for talking with the new Twitch API aka. "Helix", TMI and more! Use Twitch endpoints fearlessly!

Examples

Get information about a channel with the Get Channel Information helix endpoint.

use twitch_api2::{TwitchClient, helix::channels::GetChannelInformationRequest};
use twitch_oauth2::client::surf_http_client;
use twitch_oauth2::{AppAccessToken, Scope, TwitchToken, tokens::errors::TokenError};

let token =
    match AppAccessToken::get_app_access_token(surf_http_client, client_id, client_secret, Scope::all()).await {
        Ok(t) => t,
        Err(TokenError::Request(e)) => panic!("got error: {:?}", e),
        Err(e) => panic!(e),
    };
let client = TwitchClient::new();
let req = GetChannelInformationRequest::builder()
    .broadcaster_id("27620241")
    .build();

println!("{:?}", &client.helix.req_get(req, &token).await?.data.unwrap().title);

Features

This crate provides almost no functionality by default, only exposing types. To enable more features, refer to below table.

Feature
twitch_oauth2Gives scopes for endpoints and topics that are needed to call them.
clientGives a client abstraction for endpoints. See for example TmiClient and HelixClient
helixEnables Helix endpoints
tmiEnables TMI endpoints
eventsubEnables deserializable structs for EventSub
pubsubEnables deserializable structs for PubSub
surf_clientEnables surf for HttpClient
reqwest_clientEnables reqwest for HttpClient
allEnables all above features. Including reqwest and surf. Do not use this in production, it's better if you specify exactly what you need
unsupportedEnables undocumented or experimental endpoints or topics. Breakage may occur
allow_unknown_fieldsRemoves #[serde(deny_unknown_fields)] on all applicable structs/enums

Re-exports

pub use twitch_oauth2;
pub use client::Client as HttpClient;

Modules

clientclient

Different clients you can use with this crate to call endpoints.

eventsubeventsub

Holds serializable EventSub stuff

helixhelix

Helix endpoints or the New Twitch API

pubsubpubsub

Holds serializable pubsub stuff

tmitmi

TMI Endpoint, twitch's unsupported api for better chatters retrieval

types

Twitch types

Structs

HelixClientclient and helix

Client for Helix or the New Twitch API

TmiClientclient and tmi

Client for the twitch TMI endpoint, almost entirely undocumented and certainly not supported.

TwitchClientclient and (helix or tmi)

Client for Twitch APIs.

Statics

TWITCH_HELIX_URLhelix

Location of Twitch Helix

TWITCH_PUBSUB_URLpubsub

Location to twitch PubSub

TWITCH_TMI_URLtmi

Location of Twitch TMI