Skip to content

Commit

Permalink
πŸ”€ Merge: pull request #101 from Rinrin0413/dev
Browse files Browse the repository at this point in the history
# v0.6.0

## Breaking Changes

- πŸ’₯ Added support for TETR.IO BETA 1.2.0+ [close #15]
    - πŸ› οΈ Conformed to the new endpoints:
        - close #16
        - ✨ Conform to new Server Activity endpoint [23a3d17]
        - close #19
        - close #21
        - close #51
    - ✨ Implemented new methods for the new endpoints:
        - ✨ Implemented new methods for the User Summaries endpoints:
            - close #23
            - close #25
            - close #27
            - close #29
            - close #31
            - close #33
            - close #35
            - close #37
        - close #39
        - close #41
        - close #43
        - close #45
        - close #47
            - close  #71
        - close #49    
        - ✨ Implement new methods for the Labs endpoints:
            - close #53
            - close #55
            - close #57
        - close #59
    - ✨ Added the new rank X+ [close #61]
    - πŸ”₯ Removed the elements for the discontinued endpoints [close #64]
    - ♻️ Improved the structures of the files and elements [close #63]
    - ✨ Implemented some useful methods for the models [close #67]
    - πŸ“š Improved the documentation [close #69]
    - πŸ› οΈ Conformed to the new error response structure [close #84]
    - 🩹 Fixed some problems:
        - 🩹 The `RecordsLeaderboardId::to_param` method was ignoring its `revolution_id` field [close #73]
        - πŸ“š  Wrote missing "Panics" sections in some documentations [close #77]
        - πŸ› The `SearchCriteria::init` methods are now working [f90cbc1]
    - πŸ› οΈ Final adjustments:
        - πŸ› οΈ The option in the `Client::get_news_all` method is now mandatory, just like the `Client::get_news_latest` method [close #75]
        - ♻️ Improved the panic handling [close #79]
        - πŸ› οΈ  A deserialization is now tried before returning a HTTP error [close #82]
        - πŸ› οΈ The color constant for the XX rank is now deprecated [b361c0f]
        - πŸ› οΈ The optional boolean fields in the models are now completely boolean [close #87]
        - πŸ› οΈ The enumerators of the `ResponseError` enum now have appropriate types [close #89]
        - πŸ“š Added mentions about the exceptions in the API responses in the documentation [04aed5a]
        - ✨ Added re-exports in the `model::util` module [0ead1dd, 8da2a1c]
        - ✨ Added `model::prelude` module [96fc77b, eba3236]
        - ✨ Added `crate::prelude` module [28739db, 14dc0d6, 47626a8]
        - πŸ› οΈ Added the derives `Clone` and `Debug` to some types for parameters [64f9ac7]
        - πŸ› οΈ Added URL encodings [21443e4]
    - ✏️ Renamed some models to appropriate names [close #91]
    - ✨ Provided additional utility types [close #93]
    - ♻️ Implement some methods of the models with macros [close #95]
        - 🚚 Moved the utility types to `model::util` module
        - πŸ› οΈ Some methods of the `Client` struct now have generic parameters
    - ✨ Added support for `X-Session-ID` [close #97]
        - πŸ› οΈ The `Client` struct is now reusable [ed10aef]
    - πŸ› οΈ Updated the examples [close #81]
    - πŸ› οΈ Updated the READMEs. (`README.md` and `src/lib.rs`) [b76b8e4]

## Bug Fixes

- πŸ› The API URLs in the fetch request were incorrect [close #12]
  • Loading branch information
Rinrin0413 authored Dec 7, 2024
2 parents ca322b5 + ad7f06c commit 052796f
Show file tree
Hide file tree
Showing 102 changed files with 6,281 additions and 5,961 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Cargo.lock
TODO.md
.vscode/
check_examples.sh
tetr_ch_bin/
examples/bin.rs
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
# v0.6.0 2024-12-07

## Breaking Changes

- πŸ’₯ [TETR.IO BETA 1.2.0](https://tetr.io/about/patchnotes/#chlog_BETA_1_2_0)+ are now supported. [#15]
- ✨ Added new methods of the [`Client`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/struct.Client.html) struct for the new API endpoints.
- πŸ”₯ Removed the methods and elements for the discontinued endpoints. [#64]
- ✨ Added support for the new rank X+. [#61]

## Features

- ✨ 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 [`xp_to_level`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/util/fn.xp_to_level.html) function.

## Improvements

- πŸ› οΈ Parameters that are used in the URL are now encoded.
- πŸ“š Improved the documentation.

## Other Changes

- πŸ› οΈ The enumerators of the [`ResponseError`](https://docs.rs/tetr_ch/0.6.0/tetr_ch/client/error/enum.ResponseError.html) enum now have each error type. [#89]

---

# v0.5.1 (hotfix) 2023-12-01

## Fixes

- Decoding error when the property `ts` of the object "badges" was not present

---

# v0.5.0 2023-11-30

## Fixes
Expand Down Expand Up @@ -31,6 +60,8 @@

- Update `.gitignore`

---

# v0.4.0 2023-06-29

## Changes
Expand All @@ -47,6 +78,8 @@ This has significantly changed the structure around records.

- Make `ResponseError` a standard error type by [@jlkn](https://github.com/jlkn) in [[#2](https://github.com/Rinrin0413/tetr-ch-rs/pull/2)]

---

# v0.3.5 2023-05-23

## Improvements
Expand All @@ -57,10 +90,16 @@ This has significantly changed the structure around records.

- Fixed redundant and raggedly named functions.

---

# v0.3.4 2022-12-18

---

# v0.3.3 2022-12-12

---

# v0.3.2 2022-10-28

## Additions
Expand Down
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[package]
name = "tetr_ch"
description = "A library for the TETRA CHANNEL API."
version = "0.5.1"
description = "A Rust wrapper for the TETRA CHANNEL API. "
version = "0.6.0"
authors = ["Rinrin.rs <rinrin0413.valley@gmail.com>"]
license-file = "LICENSE"
repository = "https://github.com/Rinrin0413/tetr-ch-rs.git"
readme = "README.md"
keywords = ["tetrio", "tetr-io", "tetr_io", "tetra-channel-api", "tetra_channel_api"]
keywords = ["tetrio", "tetr-io", "tetr_io", "tetra-channel-api", "wrapper"]
edition = "2021"

[dependencies]
http = "0.2.8"
percent-encoding = "2.3.1"
serde_json = "1.0.108"

[dependencies.reqwest]
Expand All @@ -26,5 +27,10 @@ version = "0.4.19"
default-features = false
features = ["clock"]

[dependencies.uuid]
version = "1.11.0"
features = ["v4"]

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
tokio-test = "0.4.2"
21 changes: 16 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
MIT License

Copyright 2023 Rinrin.rs
Copyright (c) 2023-2024 Rinrin.rs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
121 changes: 83 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,108 @@
# tetr-ch-rs ![Latest release version](https://img.shields.io/github/v/release/Rinrin0413/tetr-ch-rs?color=007722&label=Latest%20release&style=flat-square) [![Codecov](https://img.shields.io/codecov/c/github/Rinrin0413/tetr-ch-rs?color=%23ff0077&logo=Codecov&style=flat-square)](https://app.codecov.io/gh/Rinrin0413/tetr-ch-rs)

tetr-ch-rs is a Rust library for the [TETRA CHANNEL API](https://tetr.io/about/api/).

You can get the following from the TETRA CHANNEL API with this library:

- Public details for each user.
- Some single player records.
- Some statistics about the [TETR.IO](https://tetr.io).
- Graph of user activity.
- Some streams.
- TETRA LEAGUE Leaderboard.
- XP Leaderboard.
- The latest news.

Also you can search for [TETR.IO](https://tetr.io) accounts by Discord account.

But TETRA CHANNEL API is in alpha.
So this library may not work properly in the future:(

**\* This library is NOT official.**

# Installation
A Rust wrapper for the [TETRA CHANNEL API](https://tetr.io/about/api).

You can get the following data by using this library:

- Detailed user information
- User's summaries
- 40 LINES
- BLITZ
- QUICK PLAY
- EXPERT QUICK PLAY
- TETRA LEAGUE
- ZEN
- Achievements
- User leaderboards
- User records
- Record leaderboards
- Rank metadata
- and more...

Also you can:

- Search for TETR.IO account by social connections.
- Search for record by user ID and timestamp.

> [!WARNING]
>
> This library is not an officially provided wrapper.
>
> TETR.IO is an ongoing project in continuous development.
> The TETRA CHANNEL API may change with or without notice between updates.
> So this wrapper may be outdated in the future.
>
> <details>
> <summary>And read the TETRA CHANNEL API rules before using this library:</summary>
> <div>
>
> <br />
>
> > Usage of the TETRA CHANNEL API does not require an account or bot account.
> > Please do note that requests are logged. Some simple rules:
> >
> > - **Do not flood the API with requests.** This should be obvious, but just to be sure.
> > Please keep the amount of requests at a moderate rate - once a second should be fine for most cases, short bursts are OK.
> > Please consider other users!
> > - **Honor caching data.** If a response indicates its cache will expire after 10 minutes,
> > please do not rerequest the data during that time, as the data should not change in that time,
> > assuming you are sending an `X-Session-ID` header.
> > - **Send an `X-Session-ID` header** if you are often rerequesting the same datasets.
> > This not only assures the data you receive is consistent, it also helps reduce database calls on our side.
> > - **Don't use a `X-Session-ID` header for requests that are not related.** That way, load balancing can function as expected.
> > - **Do not use the API in ways that break the TETR.IO [Terms of Service](https://tetr.io/about/terms/).** Should be obvious.
> >
> > ― https://tetr.io/about/api
>
> </div>
> </details>
## Installation

Run the following Cargo command in your project directory:

```bash
cargo add tetr_ch
```

# Examples
## Examples

The following example is a template for getting user details.

```rust
use tetr_ch::client::Client;
use tetr_ch::prelude::*;

#[tokio::main]
async fn main() {
// Set the user (name or id).
let user = "rinrin-rs";

// Create a new client.
let client = Client::new();

// Get the user details.
// And send the requested data or error message.
match client.get_user(user).await {
Ok(u) => {
println!("{:?}\n", u);
}
Err(err) => {
eprintln!("Error: {}\n", err.to_string());
}
// Set the username or user ID to get the information.
let user = "rinrin-rs";

// Get the data.
let response = match client.get_user(user).await {
Ok(res) => res,
Err(err) => panic!("Response error: {}\n", err),
};

// Check if there is an error.
// An error "No such user!" will be returned here if the user does not exist.
if let Some(err) = response.error {
panic!("Error: {}\n", err.msg.expect("no error message"));
}

let data = response.data.unwrap();
println!("Name: {}", data.username);
println!("ID: {}", data.id);
println!("XP: {}", data.xp);
println!("Level: {}", data.level());
println!("Avatar URL: {}", data.avatar_url());
}
```

See [full examples](./examples/).
All the examples can be found in the [`examples`](/examples) directory.

And see the [docs](https://docs.rs/tetr_ch).
For more information about this library, see the [documentation](https://docs.rs/tetr_ch).

[![MIT](https://img.shields.io/github/license/Rinrin0413/tetr-ch-rs?color=%23A11D32&style=for-the-badge)](./LICENSE)
[![MIT](https://img.shields.io/github/license/Rinrin0413/tetr-ch-rs?color=%23A11D32&style=for-the-badge)](/LICENSE)
43 changes: 43 additions & 0 deletions examples/01_get-user-info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Gets the detailed information about the specified user.
//!
//! Run the following Cargo command to run this example:
//!
//! ```bash
//! cargo run --example 01_get-user-info
//! ```
use tetr_ch::prelude::*;

#[tokio::main]
async fn main() {
// Create a new client.
let client = Client::new();

// Set the username or user ID to get the information.
let user = "rinrin-rs";

// Get the information.
let response = match client.get_user(user).await {
Ok(res) => res,
Err(err) => panic!("Response error: {}\n", err),
};

// Check if there is an error.
// An error "No such user!" will be returned here if the user does not exist.
if let Some(err) = response.error {
panic!("Error: {}\n", err.msg.expect("no error message"));
}

let data = response.data.unwrap();
println!("Name: {}", data.username);
println!("ID: {}", data.id);
println!("XP: {}", data.xp);
println!("Level: {}", data.level());
println!("Role: {}", data.role);
println!("Country: {:?}", data.country);
println!("Avatar URL: {}", data.avatar_url());
println!("Discord: {:?}", data.connections.discord);

// For more information about the data structure, see:
// https://docs.rs/tetr_ch/latest/tetr_ch/model/user/struct.User.html
}
35 changes: 35 additions & 0 deletions examples/02_search-for-account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Searches for a TETR.IO user account by the social connection.
//!
//! Run the following Cargo command to run this example:
//!
//! ```bash
//! cargo run --example 02_search-for-account
//! ```
use tetr_ch::prelude::*;

#[tokio::main]
async fn main() {
let client = Client::new();

// Set the social connection to search for.
// The API document says searching for the other social links will be added in the near future.
let social_connection = SocialConnection::Discord("724976600873041940".to_string());

// Search for the account.
let response = match client.search_user(social_connection).await {
Ok(res) => res,
Err(err) => panic!("Response error: {}\n", err),
};

if let Some(err) = response.error {
panic!("Error: {}\n", err.msg.expect("no error message"));
}

let data = response.data.unwrap().user.unwrap();
println!("Name: {}", data.username);
println!("ID: {}", data.id);

// For more information about the data structure, see:
// https://docs.rs/tetr_ch/latest/tetr_ch/model/searched_user/struct.UserData.html
}
Loading

0 comments on commit 052796f

Please sign in to comment.