1 stable release
1.0.0 | Dec 1, 2024 |
---|
#735 in Web programming
21 downloads per month
30KB
310 lines
codewars-api-rs
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
Features
- Interact with the Codewars REST API
- Get user info
- Get list of completed challenges
- Get list of authored challenges
- Get kata info
- Interact with the Codewars API using webhooks
Installing
You can install this crate from Crates.io using Cargo:
$ cargo add codewars-api
Usage
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 inmain
function you should installtokio
$ cargo add tokio
And then you can use it in
main
function: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
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
Contributing
Firstly, you should install Git Rust and Cargo.
- Create fork of this repo by pressing button on the top of this page.
- Clone your fork
$ git clone https://github.com/username/codewars-api-rs.git
- Go to directory where you cloned repo
$ cd codewars-api-rs
- Create new branch
- Make your changes
- Run tests:
$ cargo test
- Write tests and documentation for your changes
- Format and lint code:
$ cargo fmt
$ cargo clippy
- Commit changes
- Create PR
Writing tests
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.
Dependencies
~11–23MB
~325K SLoC