Expand description

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::{helix::channels::GetChannelInformationRequest, TwitchClient};
use twitch_oauth2::{tokens::errors::AppAccessTokenError, AppAccessToken, Scope, TwitchToken};


let client: TwitchClient<reqwest::Client> = TwitchClient::default();
let token =
    AppAccessToken::get_app_access_token(&client, client_id, client_secret, Scope::all())
        .await?;
let req = GetChannelInformationRequest::builder()
    .broadcaster_id("27620241")
    .build();
println!(
    "{:?}",
    &client.helix.req_get(req, &token).await?.data.unwrap().title
);

There is also a convenience function for accessing channel information with a specified login name

let client = TwitchClient::default();

println!("{:?}", &client.helix.get_channel_from_login("twitch".to_string(), &token).await?.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
hmacEnable message authentication using HMAC on EventSub
timeEnable time utilities on Timestamp
allEnables all above features. Including reqwest and surf. Do not use this in production, it’s better if you specify exactly what you need
ureqEnables ureq for HttpClient.
surfEnables surf for HttpClient. Note that this does not enable any default client backend, if you get a compile error, specify surf in your Cargo.toml. By default, surf uses feature curl-client
reqwestEnables reqwest for HttpClient. Note that this does not enable any default TLS backend, if you get invalid URL, scheme is not http, specify reqwest in your Cargo.toml. By default, reqwest uses feature default-tls
unsupportedEnables undocumented or experimental endpoints, topics or features. Breakage may occur, semver compatibility not guaranteed.
trace_unknown_fieldsLogs ignored fields as WARN log messages where applicable. Please consider using this and filing an issue or PR when a new field has been added to the endpoint but not added to this library.
deny_unknown_fieldsAdds #[serde(deny_unknown_fields)] on all applicable structs/enums. Please consider using this and filing an issue or PR when a new field has been added to the endpoint but not added to this library.

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

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.

Enums

DeserErrorserde_json

A deserialization error

Statics

Location of Twitch Helix

Location to twitch PubSub

Location of Twitch TMI

Functions

parse_jsonserde_json

Parse a string as T, logging ignored fields and giving a more detailed error message on parse errors

Parse a json Value as T, logging ignored fields and giving a more detailed error message on parse errors