Skip to content

Commit

Permalink
Merge pull request #113 from Rinrin0413/dev
Browse files Browse the repository at this point in the history
# 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]
  • Loading branch information
Rinrin0413 authored Dec 11, 2024
2 parents 052796f + cb834d6 commit c89aeb9
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 17 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +30,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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <rinrin0413.valley@gmail.com>"]
license-file = "LICENSE"
repository = "https://github.com/Rinrin0413/tetr-ch-rs.git"
Expand Down
16 changes: 8 additions & 8 deletions examples/03_get-user-summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions examples/09_get-news.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/12_get-scoreflow-leagueflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ impl Client {
/// # }
/// ```
pub async fn get_user(&self, user: &str) -> RspErr<UserResponse> {
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
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
78 changes: 77 additions & 1 deletion src/model/summary/league.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct LeagueResponse {
/// Data about how this request was cached.
pub cache: Option<CacheData>,
/// The requested data.
pub data: Option<LeagueData>,
pub data: Option<LeagueDataWrap>,
}

impl AsRef<LeagueResponse> for LeagueResponse {
Expand All @@ -27,6 +27,81 @@ impl AsRef<LeagueResponse> 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<LeagueDataWrap> 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,
Expand All @@ -46,6 +121,7 @@ pub struct LeagueData {
/// If over 100, this user is unranked.
pub rd: Option<f64>,
/// 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,
Expand Down

0 comments on commit c89aeb9

Please sign in to comment.