-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Merge: pull request #101 from Rinrin0413/dev
# 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
Showing
102 changed files
with
6,281 additions
and
5,961 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ Cargo.lock | |
TODO.md | ||
.vscode/ | ||
check_examples.sh | ||
tetr_ch_bin/ | ||
examples/bin.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.