Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove tmi endpoints #407

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ jobs:
- run: cargo clippy --locked --all-targets --no-default-features -p twitch_api
- run: cargo clippy --locked --all-targets --no-default-features --features "helix" -p twitch_api
- run: cargo clippy --locked --all-targets --no-default-features --features "helix client" -p twitch_api
- run: cargo clippy --locked --all-targets --no-default-features --features "tmi" -p twitch_api
- run: cargo clippy --locked --all-targets --no-default-features --features "pubsub" -p twitch_api
- run: cargo clippy --locked --all-targets --no-default-features --features "eventsub" -p twitch_api
- run: cargo clippy --locked --all-targets --features "${{ env.CI_TWITCH_API_FEATURES }} trace_unknown_fields" -p twitch_api
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Changed `SCOPES` on `helix::Request`, `pubsub::Topic` and `eventsub::EventSubscription` to be `twitch_oauth2::Validator`
- Updated `twitch_oauth2` dependency
- Added EventSub WebSocket support, changing many methods on transport and eventsub to take this into account.
- Removed `tmi` feature ([shut down in April 2023](https://discuss.dev.twitch.com/t/legacy-chatters-endpoint-shutdown-details-and-timeline-april-2023/43161))

### Changes

Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ helix = [

deser_borrow = []

tmi = ["serde_json", "dep:serde_path_to_error", "dep:hyper"]

surf = [
"dep:surf",
"dep:http-types",
Expand Down Expand Up @@ -134,7 +132,6 @@ hmac = ["dep:crypto_hmac", "dep:sha2"]
mock_api = ["twitch_oauth2?/mock_api"]

all = [
"tmi",
"helix",
"client",
"pubsub",
Expand Down Expand Up @@ -187,7 +184,7 @@ required-features = ["reqwest", "helix"]
[[example]]
name = "get_streams"
path = "examples/get_streams.rs"
required-features = ["reqwest", "helix", "tmi"]
required-features = ["reqwest", "helix"]

[[example]]
name = "modify_channel"
Expand Down
27 changes: 1 addition & 26 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,32 +230,7 @@ impl<'c, C: Client + Sync + 'c> twitch_oauth2::client::Client for crate::HelixCl
}
}

#[cfg(feature = "tmi")]
#[allow(deprecated)]
impl<'c, C: Client + Sync + 'c> twitch_oauth2::client::Client for crate::TmiClient<'c, C> {
type Error = CompatError<<C as Client>::Error>;

fn req(
&self,
request: http::Request<Vec<u8>>,
) -> BoxedFuture<
'_,
Result<http::Response<Vec<u8>>, <Self as twitch_oauth2::client::Client>::Error>,
> {
let client = self.get_client();
{
let request = request.map(Bytes::from);
let resp = client.req(request);
Box::pin(async {
let resp = resp.await?;
let (parts, body) = resp.into_parts();
Ok(http::Response::from_parts(parts, body.to_vec()))
})
}
}
}

#[cfg(any(feature = "tmi", feature = "helix"))]
#[cfg(all(feature = "client", feature = "helix"))]
impl<'c, C: Client + Sync> twitch_oauth2::client::Client for crate::TwitchClient<'c, C> {
type Error = CompatError<<C as Client>::Error>;

Expand Down
64 changes: 10 additions & 54 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@
//! | Feature | |
//! | -------: | :------- |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>twitch_oauth2</code></span> | Gives [scopes](twitch_oauth2::Scope) for endpoints and topics that are needed to call them. |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>client</code></span> | Gives a [client abstraction](HttpClient) for endpoints. See for example [`TmiClient`] and [`HelixClient`] |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>client</code></span> | Gives a [client abstraction](HttpClient) for endpoints. See [`HelixClient`] |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>helix</code></span> | Enables [Helix](helix) endpoints |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>tmi</code></span> | Enables [TMI](tmi) endpoints |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>eventsub</code></span> | Enables deserializable structs for [EventSub](eventsub) |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>pubsub</code></span> | Enables deserializable structs for [PubSub](pubsub) |
//! | <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>hmac</code></span> | Enable [message authentication](eventsub::Event::verify_payload) using HMAC on [EventSub](eventsub) |
Expand All @@ -124,8 +123,6 @@ pub use twitch_types as types;

#[cfg(feature = "helix")]
pub mod helix;
#[cfg(feature = "tmi")]
pub mod tmi;

#[cfg(feature = "pubsub")]
pub mod pubsub;
Expand All @@ -136,13 +133,6 @@ pub mod eventsub;
#[cfg(all(feature = "helix", feature = "client"))]
#[doc(inline)]
pub use crate::helix::HelixClient;
#[cfg(all(feature = "tmi", feature = "client"))]
#[doc(inline)]
#[deprecated(
note = "All TMI functionality has been implemented with helix endpoint Get Chatters"
)]
#[allow(deprecated)]
pub use crate::tmi::TmiClient;

/// Extra types not defined in [`twitch_types`]
pub mod extra;
Expand All @@ -160,12 +150,7 @@ pub use client::Client as HttpClient;
#[cfg(feature = "client")]
pub use client::DummyHttpClient;

#[cfg(any(
feature = "helix",
feature = "tmi",
feature = "pubsub",
feature = "eventsub"
))]
#[cfg(any(feature = "helix", feature = "pubsub", feature = "eventsub"))]
/// Generate a url with a default if `mock_api` feature is disabled, or env var is not defined or is invalid utf8
macro_rules! mock_env_url {
($var:literal, $default:expr $(,)?) => {
Expand Down Expand Up @@ -193,12 +178,6 @@ macro_rules! mock_env_url {
#[cfg(feature = "helix")]
pub static TWITCH_HELIX_URL: once_cell::sync::Lazy<url::Url> =
mock_env_url!("TWITCH_HELIX_URL", "https://api.twitch.tv/helix/");
/// Location of Twitch TMI
///
/// Can be overriden when feature `mock_api` is enabled with environment variable `TWITCH_TMI_URL`.
#[cfg(feature = "tmi")]
pub static TWITCH_TMI_URL: once_cell::sync::Lazy<url::Url> =
mock_env_url!("TWITCH_TMI_URL", "https://tmi.twitch.tv/");
/// Location to twitch PubSub
///
/// Can be overriden when feature `mock_api` is enabled with environment variable `TWITCH_PUBSUB_URL`.
Expand Down Expand Up @@ -229,72 +208,49 @@ pub static TWITCH_EVENTSUB_WEBSOCKET_URL: once_cell::sync::Lazy<url::Url> = mock
/// ```
///
/// See [`client`] for implemented clients, you can also define your own if needed.
#[cfg(all(feature = "client", any(feature = "helix", feature = "tmi")))]
#[cfg(all(feature = "client", feature = "helix"))]
#[derive(Clone)]
#[non_exhaustive]
pub struct TwitchClient<'a, C>
where C: HttpClient + 'a {
/// Helix endpoint. See [`helix`]
#[cfg(feature = "helix")]
pub helix: HelixClient<'a, C>,
/// TMI endpoint. See [`tmi`]
#[cfg(feature = "tmi")]
#[allow(deprecated)]
pub tmi: TmiClient<'a, C>,
}

#[cfg(all(feature = "client", any(feature = "helix", feature = "tmi")))]
#[cfg(all(feature = "client", feature = "helix"))]
impl<C: HttpClient + 'static> TwitchClient<'static, C> {
/// Create a new [`TwitchClient`]
#[cfg(any(feature = "helix", feature = "tmi"))]
#[cfg(feature = "helix")]
pub fn new() -> TwitchClient<'static, C>
where C: Clone + client::ClientDefault<'static> {
let client = C::default_client();
Self::with_client(client)
}
}

#[cfg(all(feature = "client", any(feature = "helix", feature = "tmi")))]
#[cfg(all(feature = "client", feature = "helix"))]
impl<C: HttpClient + client::ClientDefault<'static> + 'static> Default
for TwitchClient<'static, C>
{
fn default() -> Self { Self::new() }
}

#[cfg(all(feature = "client", any(feature = "helix", feature = "tmi")))]
#[cfg(all(feature = "client", feature = "helix"))]
impl<'a, C: HttpClient + 'a> TwitchClient<'a, C> {
/// Create a new [`TwitchClient`] with an existing [`HttpClient`]
#[cfg_attr(
nightly,
doc(cfg(all(feature = "client", any(feature = "helix", feature = "tmi"))))
)]
#[cfg(any(feature = "helix", feature = "tmi"))]
#[cfg_attr(nightly, doc(cfg(all(feature = "client", feature = "helix"))))]
#[cfg(feature = "helix")]
pub fn with_client(client: C) -> TwitchClient<'a, C>
where C: Clone + 'a {
// FIXME: This Clone is not used when only using one of the endpoints
#[allow(deprecated)]
TwitchClient {
#[cfg(feature = "tmi")]
tmi: TmiClient::with_client(client.clone()),
#[cfg(feature = "helix")]
helix: HelixClient::with_client(client),
}
}

/// Retrieve a reference of the [`HttpClient`] inside this [`TwitchClient`]
pub fn get_client(&self) -> &C {
#[cfg(feature = "helix")]
{
self.helix.get_client()
}
#[cfg(not(feature = "helix"))]
{
#[cfg(feature = "tmi")]
{
self.tmi.get_client()
}
}
}
pub fn get_client(&self) -> &C { self.helix.get_client() }
}

/// A deserialization error
Expand Down
155 changes: 0 additions & 155 deletions src/tmi/mod.rs

This file was deleted.

Loading