Skip to content

Commit c89aeb9

Browse files
authored
Merge pull request #113 from Rinrin0413/dev
# v0.6.1 ## Features - ✨ Re-exported the `Client` struct to the crate root [close #106] ## Bug Fixes - 🐛 Fixed deserialization errors when using the `Client::get_user_league` method [close #102 close #107] - 🛠️ The `LeagueData` struct is now wrapped in new enum `LeagueDataWrap` [f2e0f23] - ⚰️ Removed an unnecessary `dbg` macro call in the `Client::get_user` method implementation [close #104] ## Other Changes - 📚 Fixed an incorrect link in the `CHANGELOG.md` [close #103] - 🛠️ Adjusted the examples [c63f513]
2 parents 052796f + cb834d6 commit c89aeb9

File tree

8 files changed

+116
-17
lines changed

8 files changed

+116
-17
lines changed

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# v0.6.1 2024-12-11
2+
3+
## Features
4+
5+
- ✨ 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]
6+
7+
## Bug Fixes
8+
9+
- 🐛 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]
10+
- 🛠️ 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]
11+
- ⚰️ 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]
12+
13+
## Other Changes
14+
15+
- 📚 Fixed an incorrect link in the `CHANGELOG.md`. [#103]
16+
- 🛠️ Adjusted the examples. [c63f5137e0596fcb05ba2dc9897a3d6521f75599]
17+
18+
---
19+
120
# v0.6.0 2024-12-07
221

322
## Breaking Changes
@@ -11,7 +30,7 @@
1130

1231
- ✨ The [`Client`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/struct.Client.html) struct now supports `X-Session-ID` header. [#97]
1332
- Use [`Client::with_session_id`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/struct.Client.html#method.with_session_id).
14-
- ✨ 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).
33+
- ✨ 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).
1534
- ✨ Added [`xp_to_level`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/util/fn.xp_to_level.html) function.
1635

1736
## Improvements

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tetr_ch"
33
description = "A Rust wrapper for the TETRA CHANNEL API. "
4-
version = "0.6.0"
4+
version = "0.6.1"
55
authors = ["Rinrin.rs <rinrin0413.valley@gmail.com>"]
66
license-file = "LICENSE"
77
repository = "https://github.com/Rinrin0413/tetr-ch-rs.git"

examples/03_get-user-summaries.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,32 @@ async fn main() {
1616
let user = "rinrin-rs";
1717

1818
// Get the summary of the user's 40 LINES games.
19-
let _ = client.get_user_40l(user).await;
19+
let _ = client.get_user_40l(user).await.unwrap();
2020

2121
// Get the summary of the user's BLITZ games.
22-
let _ = client.get_user_blitz(user).await;
22+
let _ = client.get_user_blitz(user).await.unwrap();
2323

2424
// Get the summary of the user's QUICK PLAY games.
25-
let _ = client.get_user_zenith(user).await;
25+
let _ = client.get_user_zenith(user).await.unwrap();
2626

2727
// Get the summary of the user's EXPERT QUICK PLAY games.
28-
let _ = client.get_user_zenith_ex(user).await;
28+
let _ = client.get_user_zenith_ex(user).await.unwrap();
2929

3030
// Get the summary of the user's TETRA LEAGUE standing.
31-
let _ = client.get_user_league(user).await;
31+
let _ = client.get_user_league(user).await.unwrap();
3232

3333
// Get the summary of the user's ZEN progress.
34-
let _ = client.get_user_zen(user).await;
34+
let _ = client.get_user_zen(user).await.unwrap();
3535

3636
// Get all the achievements of the user.
37-
let _ = client.get_user_achievements(user).await;
37+
let _ = client.get_user_achievements(user).await.unwrap();
3838

3939
// Get all the summaries of the user.
4040
//
4141
// WARNING: Consider whether you really need to use this method.
4242
// If you only collect data for one or two game modes,
4343
// use the methods for the individual summaries instead.
44-
let _ = client.get_user_all_summaries(user).await;
44+
let _ = client.get_user_all_summaries(user); // .await.unwrap();
4545

4646
// For more information about the data structures, see:
4747
// - 40 LINES: https://docs.rs/tetr_ch/latest/tetr_ch/model/summary/forty_lines/struct.FortyLines.html

examples/09_get-news.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn main() {
1313
let client = Client::new();
1414

1515
// Get three latest news items in any stream.
16-
let _ = client.get_news_all(3).await;
16+
let _ = client.get_news_all(3).await.unwrap();
1717

1818
// Gets the latest news items in the global news stream.
1919
let _ = client
@@ -23,7 +23,8 @@ async fn main() {
2323
// Three news
2424
3,
2525
)
26-
.await;
26+
.await
27+
.unwrap();
2728

2829
// Gets the latest news items in the specified user's news stream.
2930
let _ = client
@@ -32,7 +33,8 @@ async fn main() {
3233
NewsStreamParam::User("621db46d1d638ea850be2aa0".to_string()),
3334
3,
3435
)
35-
.await;
36+
.await
37+
.unwrap();
3638

3739
// For more information about the data structure, see:
3840
// https://docs.rs/tetr_ch/latest/tetr_ch/model/news/struct.NewsItems.html

examples/12_get-scoreflow-leagueflow.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ async fn main() {
2222
// 40 LINES
2323
RecordGamemode::FortyLines,
2424
)
25-
.await;
25+
.await
26+
.unwrap();
2627

2728
// Get the condensed graph of the user's matches in TETRA LEAGUE.
28-
let _ = client.get_labs_leagueflow(user).await;
29+
let _ = client.get_labs_leagueflow(user).await.unwrap();
2930

3031
// For more information about the data structures, see:
3132
// - Scoreflow: https://docs.rs/tetr_ch/latest/tetr_ch/model/labs/scoreflow/struct.LabsScoreflow.html

src/client.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ impl Client {
178178
/// # }
179179
/// ```
180180
pub async fn get_user(&self, user: &str) -> RspErr<UserResponse> {
181-
dbg!(encode(user.to_lowercase()));
182181
let url = format!("{}users/{}", API_URL, encode(user.to_lowercase()));
183182
let res = self.client.get(url).send().await;
184183
response(res).await

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
//!
104104
//! [![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)
105105
106+
pub use crate::client::Client;
107+
106108
pub mod client;
107109
pub mod constants;
108110
pub mod model;

src/model/summary/league.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct LeagueResponse {
1818
/// Data about how this request was cached.
1919
pub cache: Option<CacheData>,
2020
/// The requested data.
21-
pub data: Option<LeagueData>,
21+
pub data: Option<LeagueDataWrap>,
2222
}
2323

2424
impl AsRef<LeagueResponse> for LeagueResponse {
@@ -27,6 +27,81 @@ impl AsRef<LeagueResponse> for LeagueResponse {
2727
}
2828
}
2929

30+
/// A league data wrapper.
31+
///
32+
/// The [`LeagueDataWrap`] struct is wrapped in this enum.
33+
/// Because the API returns an empty object when the user is banned.
34+
/// For more information, see the [GitHub issue #107](https://github.com/Rinrin0413/tetr-ch-rs/issues/107).
35+
#[derive(Clone, Debug, Deserialize)]
36+
#[serde(untagged)]
37+
#[non_exhaustive]
38+
pub enum LeagueDataWrap {
39+
/// A user's TETRA LEAGUE data.
40+
Some(LeagueData),
41+
/// An empty object if the user is banned. (maybe)
42+
Empty {},
43+
}
44+
45+
impl LeagueDataWrap {
46+
/// Returns `true` if this is a [`LeagueDataWrap::Some`] value.
47+
pub fn is_some(&self) -> bool {
48+
matches!(self, LeagueDataWrap::Some(_))
49+
}
50+
51+
/// Returns `true` if this is a [`LeagueDataWrap::Empty`] value.
52+
pub fn is_empty(&self) -> bool {
53+
matches!(self, LeagueDataWrap::Empty {})
54+
}
55+
56+
/// Returns the contained [`LeagueDataWrap::Some`] value, consuming the `self` value.
57+
///
58+
/// # Panics
59+
///
60+
/// Panics if the value is a [`LeagueDataWrap::Empty`] with a custom panic message provided by
61+
/// `msg`.
62+
pub fn expect(self, msg: &str) -> LeagueData {
63+
match self {
64+
LeagueDataWrap::Some(val) => val,
65+
LeagueDataWrap::Empty {} => panic!("{}", msg),
66+
}
67+
}
68+
69+
/// Returns the contained [`LeagueDataWrap::Some`] value, consuming the `self` value.
70+
///
71+
/// # Panics
72+
///
73+
/// Panics if the self value equals [`LeagueDataWrap::Empty`].
74+
pub fn unwrap(self) -> LeagueData {
75+
match self {
76+
LeagueDataWrap::Some(val) => val,
77+
LeagueDataWrap::Empty {} => {
78+
panic!("called `LeagueDataWrap::unwrap()` on an `LeagueDataWrap::Empty` value")
79+
}
80+
}
81+
}
82+
}
83+
84+
impl AsRef<LeagueDataWrap> for LeagueDataWrap {
85+
fn as_ref(&self) -> &Self {
86+
self
87+
}
88+
}
89+
90+
impl Default for LeagueDataWrap {
91+
/// Returns [`LeagueDataWrap::Empty`].
92+
///
93+
/// # Examples
94+
///
95+
/// ```
96+
/// # use tetr_ch::model::summary::league::LeagueDataWrap;
97+
/// let wrap: LeagueDataWrap = LeagueDataWrap::default();
98+
/// assert!(wrap.is_empty());
99+
/// ```
100+
fn default() -> LeagueDataWrap {
101+
LeagueDataWrap::Empty {}
102+
}
103+
}
104+
30105
/// A struct that describes a summary of a user's TETRA LEAGUE standing.
31106
///
32107
/// Season information is only saved if the user had finished placements in the season,
@@ -46,6 +121,7 @@ pub struct LeagueData {
46121
/// If over 100, this user is unranked.
47122
pub rd: Option<f64>,
48123
/// Whether this user's RD is rising (has not played in the last week).
124+
#[serde(rename = "decaying")]
49125
pub is_decaying: bool,
50126
/// This user's TR (Tetra Rating), or -1 if less than 10 games were played.
51127
pub tr: f64,

0 commit comments

Comments
 (0)