| Crates.io | codewars-api |
| lib.rs | codewars-api |
| version | 1.0.0 |
| created_at | 2024-12-01 10:36:33.94455+00 |
| updated_at | 2024-12-01 10:36:33.94455+00 |
| description | A library for interacting with the Codewars API |
| homepage | |
| repository | https://github.com/ankddev/codewars-api-rs |
| max_upload_size | |
| id | 1467320 |
| size | 78,275 |
Full-featured crate to interact with Codewars API. Check official documentation for more information about API.
[!NOTE]
At this moment, Codewars API is minimal and inconsistent. So, you can't to do some things with API and this crate
You can install this crate from Crates.io using Cargo:
$ cargo add codewars-api
At this moment only REST API is supported, webhook support will be added in the future. Import it in your project:
use codewars_api::rest_api::client::RestCodewarsClient;
Then, initialize the client:
let client = RestCodewarsClient::new();
And you can use methods of client:
let user = client.get_user("username").await.unwrap();
let challenges = client.get_completed_challenges("username", 1).await.unwrap();
[!NOTE]
If you want to use it inmainfunction you should installtokio$ cargo add tokioAnd then you can use it in
mainfunction:use tokio; use codewars_api::rest_api::client::RestCodewarsClient; #[tokio::main] async fn main() { let client = RestCodewarsClient::new(); let user = client.get_user("username").await.unwrap(); let challenges = client.get_completed_challenges("username", 1).await.unwrap(); }
Documentation for this crate can be found at crates.io Also, you can see examples of using this crate in examples. To run example clone this repo and run this:
$ cargo run --example <example_name>
For example:
$ cargo run --example print_name
Firstly, you should install Git Rust and Cargo.
$ git clone https://github.com/username/codewars-api-rs.git
$ cd codewars-api-rs
$ cargo test
$ cargo fmt
$ cargo clippy
You can learn more about writing tests in the official documentation.
We test all methods of RestCodewarsClient struct in doctests.
At this moment, we don't use mock in doctests, so you should add no_run attribute for doctests, like this:
# Examples
```no_run
use codewars_api::rest_api::client::RestCodewarsClient;
...
```
In unit tests we use mockito library for mock testing. See it's official documentation for more information. Mocks are stored in tests/mocks directory. All mocks are from Codewars documentation.