From cef79fc05c806a94db98500feb4566d78b748262 Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 00:29:04 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20`LeagueData::is=5Fdec?= =?UTF-8?q?aying`=20field=20was=20not=20renaming=20to=20correct=20name=20[?= =?UTF-8?q?#102]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/summary/league.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/model/summary/league.rs b/src/model/summary/league.rs index 108a497..d7feaf5 100644 --- a/src/model/summary/league.rs +++ b/src/model/summary/league.rs @@ -46,6 +46,7 @@ pub struct LeagueData { /// If over 100, this user is unranked. pub rd: Option, /// Whether this user's RD is rising (has not played in the last week). + #[serde(rename = "decaying")] pub is_decaying: bool, /// This user's TR (Tetra Rating), or -1 if less than 10 games were played. pub tr: f64, From c63f5137e0596fcb05ba2dc9897a3d6521f75599 Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 01:04:25 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Update:=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/03_get-user-summaries.rs | 16 ++++++++-------- examples/09_get-news.rs | 8 +++++--- examples/12_get-scoreflow-leagueflow.rs | 5 +++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/03_get-user-summaries.rs b/examples/03_get-user-summaries.rs index 7a5d224..01bf077 100644 --- a/examples/03_get-user-summaries.rs +++ b/examples/03_get-user-summaries.rs @@ -16,32 +16,32 @@ async fn main() { let user = "rinrin-rs"; // Get the summary of the user's 40 LINES games. - let _ = client.get_user_40l(user).await; + let _ = client.get_user_40l(user).await.unwrap(); // Get the summary of the user's BLITZ games. - let _ = client.get_user_blitz(user).await; + let _ = client.get_user_blitz(user).await.unwrap(); // Get the summary of the user's QUICK PLAY games. - let _ = client.get_user_zenith(user).await; + let _ = client.get_user_zenith(user).await.unwrap(); // Get the summary of the user's EXPERT QUICK PLAY games. - let _ = client.get_user_zenith_ex(user).await; + let _ = client.get_user_zenith_ex(user).await.unwrap(); // Get the summary of the user's TETRA LEAGUE standing. - let _ = client.get_user_league(user).await; + let _ = client.get_user_league(user).await.unwrap(); // Get the summary of the user's ZEN progress. - let _ = client.get_user_zen(user).await; + let _ = client.get_user_zen(user).await.unwrap(); // Get all the achievements of the user. - let _ = client.get_user_achievements(user).await; + let _ = client.get_user_achievements(user).await.unwrap(); // Get all the summaries of the user. // // WARNING: Consider whether you really need to use this method. // If you only collect data for one or two game modes, // use the methods for the individual summaries instead. - let _ = client.get_user_all_summaries(user).await; + let _ = client.get_user_all_summaries(user); // .await.unwrap(); // For more information about the data structures, see: // - 40 LINES: https://docs.rs/tetr_ch/latest/tetr_ch/model/summary/forty_lines/struct.FortyLines.html diff --git a/examples/09_get-news.rs b/examples/09_get-news.rs index 116e5b9..a7b9398 100644 --- a/examples/09_get-news.rs +++ b/examples/09_get-news.rs @@ -13,7 +13,7 @@ async fn main() { let client = Client::new(); // Get three latest news items in any stream. - let _ = client.get_news_all(3).await; + let _ = client.get_news_all(3).await.unwrap(); // Gets the latest news items in the global news stream. let _ = client @@ -23,7 +23,8 @@ async fn main() { // Three news 3, ) - .await; + .await + .unwrap(); // Gets the latest news items in the specified user's news stream. let _ = client @@ -32,7 +33,8 @@ async fn main() { NewsStreamParam::User("621db46d1d638ea850be2aa0".to_string()), 3, ) - .await; + .await + .unwrap(); // For more information about the data structure, see: // https://docs.rs/tetr_ch/latest/tetr_ch/model/news/struct.NewsItems.html diff --git a/examples/12_get-scoreflow-leagueflow.rs b/examples/12_get-scoreflow-leagueflow.rs index fe60a17..f30c84c 100644 --- a/examples/12_get-scoreflow-leagueflow.rs +++ b/examples/12_get-scoreflow-leagueflow.rs @@ -22,10 +22,11 @@ async fn main() { // 40 LINES RecordGamemode::FortyLines, ) - .await; + .await + .unwrap(); // Get the condensed graph of the user's matches in TETRA LEAGUE. - let _ = client.get_labs_leagueflow(user).await; + let _ = client.get_labs_leagueflow(user).await.unwrap(); // For more information about the data structures, see: // - Scoreflow: https://docs.rs/tetr_ch/latest/tetr_ch/model/labs/scoreflow/struct.LabsScoreflow.html From ac6d94781c78bc4ff7e05690aba2ebed5dbc330a Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 01:32:04 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=93=9A=20Docs:=20fix=20link=20typo=20?= =?UTF-8?q?[#103]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1937318..934daa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - ✨ The [`Client`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/struct.Client.html) struct now supports `X-Session-ID` header. [#97] - Use [`Client::with_session_id`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/struct.Client.html#method.with_session_id). -- ✨ Added two prelude modules [`tetr_ch::prelude`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/prelude/index.html) and [`tetr_ch::model::prelude`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/model/util/index.html). +- ✨ Added two prelude modules [`tetr_ch::prelude`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/prelude/index.html) and [`tetr_ch::model::prelude`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/model/prelude/index.html). - ✨ Added [`xp_to_level`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/util/fn.xp_to_level.html) function. ## Improvements From 9c5fecb917ee5251117773e41dd9d3a8bf261f91 Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 01:59:11 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20Remove:=20unnecessary?= =?UTF-8?q?=20`dbg`=20macro=20call=20in=20`Client::get=5Fuser=20method=20i?= =?UTF-8?q?mplementation=20[#104]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 4a07c97..772c400 100644 --- a/src/client.rs +++ b/src/client.rs @@ -178,7 +178,6 @@ impl Client { /// # } /// ``` pub async fn get_user(&self, user: &str) -> RspErr { - dbg!(encode(user.to_lowercase())); let url = format!("{}users/{}", API_URL, encode(user.to_lowercase())); let res = self.client.get(url).send().await; response(res).await From f2e0f232c239f85b1bbe5162f41a938c3057dbfc Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 15:59:59 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Change:=20`LeagueDa?= =?UTF-8?q?ta`=20struct=20is=20now=20wrapped=20in=20a=20enum=20[#107]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/summary/league.rs | 77 ++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/model/summary/league.rs b/src/model/summary/league.rs index d7feaf5..f0710af 100644 --- a/src/model/summary/league.rs +++ b/src/model/summary/league.rs @@ -18,7 +18,7 @@ pub struct LeagueResponse { /// Data about how this request was cached. pub cache: Option, /// The requested data. - pub data: Option, + pub data: Option, } impl AsRef for LeagueResponse { @@ -27,6 +27,81 @@ impl AsRef for LeagueResponse { } } +/// A league data wrapper. +/// +/// The [`LeagueDataWrap`] struct is wrapped in this enum. +/// Because the API returns an empty object when the user is banned. +/// For more information, see the [GitHub issue #107](https://github.com/Rinrin0413/tetr-ch-rs/issues/107). +#[derive(Clone, Debug, Deserialize)] +#[serde(untagged)] +#[non_exhaustive] +pub enum LeagueDataWrap { + /// A user's TETRA LEAGUE data. + Some(LeagueData), + /// An empty object if the user is banned. (maybe) + Empty {}, +} + +impl LeagueDataWrap { + /// Returns `true` if this is a [`LeagueDataWrap::Some`] value. + pub fn is_some(&self) -> bool { + matches!(self, LeagueDataWrap::Some(_)) + } + + /// Returns `true` if this is a [`LeagueDataWrap::Empty`] value. + pub fn is_empty(&self) -> bool { + matches!(self, LeagueDataWrap::Empty {}) + } + + /// Returns the contained [`LeagueDataWrap::Some`] value, consuming the `self` value. + /// + /// # Panics + /// + /// Panics if the value is a [`LeagueDataWrap::Empty`] with a custom panic message provided by + /// `msg`. + pub fn expect(self, msg: &str) -> LeagueData { + match self { + LeagueDataWrap::Some(val) => val, + LeagueDataWrap::Empty {} => panic!("{}", msg), + } + } + + /// Returns the contained [`LeagueDataWrap::Some`] value, consuming the `self` value. + /// + /// # Panics + /// + /// Panics if the self value equals [`LeagueDataWrap::Empty`]. + pub fn unwrap(self) -> LeagueData { + match self { + LeagueDataWrap::Some(val) => val, + LeagueDataWrap::Empty {} => { + panic!("called `LeagueDataWrap::unwrap()` on an `LeagueDataWrap::Empty` value") + } + } + } +} + +impl AsRef for LeagueDataWrap { + fn as_ref(&self) -> &Self { + self + } +} + +impl Default for LeagueDataWrap { + /// Returns [`LeagueDataWrap::Empty`]. + /// + /// # Examples + /// + /// ``` + /// # use tetr_ch::model::summary::league::LeagueDataWrap; + /// let wrap: LeagueDataWrap = LeagueDataWrap::default(); + /// assert!(wrap.is_empty()); + /// ``` + fn default() -> LeagueDataWrap { + LeagueDataWrap::Empty {} + } +} + /// A struct that describes a summary of a user's TETRA LEAGUE standing. /// /// Season information is only saved if the user had finished placements in the season, From f947af8796eddfbb6fd304a6790de0a64379eb44 Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 16:26:44 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9C=A8=20Add:=20re-export=20`Client`=20f?= =?UTF-8?q?rom=20the=20crate=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3a6bf30..acc9618 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,8 @@ //! //! [![MIT](https://img.shields.io/github/license/Rinrin0413/tetr-ch-rs?color=%23A11D32&style=for-the-badge)](https://docs.rs/crate/tetr_ch/latest/source/LICENSE) +pub use crate::client::Client; + pub mod client; pub mod constants; pub mod model; From cb834d6890a11459d314aaf5fc3266d57ec51ec2 Mon Sep 17 00:00:00 2001 From: "Rinrin.rs" Date: Wed, 11 Dec 2024 16:55:09 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=94=96=20Upgrade:=20v0.6.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 19 +++++++++++++++++++ Cargo.toml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 934daa5..2775650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# v0.6.1 2024-12-11 + +## Features + +- ✨ Re-exported the [`Client`](https://docs.rs/tetr_ch/0.6.1/tetr_ch/client/struct.Client.html) struct to the [crate root](https://docs.rs/tetr_ch/0.6.1/tetr_ch/index.html#reexports). [#106] + +## Bug Fixes + +- 🐛 Fixed deserialization errors when using the [`Client::get_user_league`](https://docs.rs/tetr_ch/0.6.1/tetr_ch/client/struct.Client.html#method.get_user_league) method. [#102 #107] + - 🛠️ The [`LeagueData`](https://docs.rs/tetr_ch/0.6.1/tetr_ch/model/summary/league/struct.LeagueData.html) struct is now wrapped in new enum [`LeagueDataWrap`](https://docs.rs/tetr_ch/0.6.1/tetr_ch/model/summary/league/enum.LeagueDataWrap.html). [f2e0f232c239f85b1bbe5162f41a938c3057dbfc] +- ⚰️ Removed an unnecessary `dbg` macro call in the [`Client::get_user`](https://docs.rs/tetr_ch/0.6.1/tetr_ch/client/struct.Client.html#method.get_user) method implementation. [#104] + +## Other Changes + +- 📚 Fixed an incorrect link in the `CHANGELOG.md`. [#103] +- 🛠️ Adjusted the examples. [c63f5137e0596fcb05ba2dc9897a3d6521f75599] + +--- + # v0.6.0 2024-12-07 ## Breaking Changes diff --git a/Cargo.toml b/Cargo.toml index 1aace20..e41064f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tetr_ch" description = "A Rust wrapper for the TETRA CHANNEL API. " -version = "0.6.0" +version = "0.6.1" authors = ["Rinrin.rs "] license-file = "LICENSE" repository = "https://github.com/Rinrin0413/tetr-ch-rs.git"