Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ankddev/codewars-api-rs

A Rust crate for interacting with the Codewars API
https://github.com/ankddev/codewars-api-rs

api codewars rest-api rust rust-lang

Last synced: about 1 month ago
JSON representation

A Rust crate for interacting with the Codewars API

Awesome Lists containing this project

README

        

codewars-api-rs


Full-featured crate to interact with Codewars API. Check official documentation for more information about API.


crates.io downloads


GitHub commit activity
Test status

> [!NOTE]
> At this moment, Codewars API is [minimal and inconsistent](https://dev.codewars.com/#introduction).
> So, you can't to do some things with API and this crate

# Features
- [x] Interact with the Codewars REST API
- [x] Get user info
- [x] Get list of completed challenges
- [x] Get list of authored challenges
- [x] Get kata info
- [ ] Interact with the Codewars API using webhooks
# Installing
You can install this crate from Crates.io using Cargo:
```shell
$ 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:
```rust
use codewars_api::rest_api::client::RestCodewarsClient;
```
Then, initialize the client:
```rust
let client = RestCodewarsClient::new();
```
And you can use methods of client:
```rust
let user = client.get_user("username").await.unwrap();
let challenges = client.get_completed_challenges("username", 1).await.unwrap();
```
> [!TIP]
> If you want to use it in `main` function you should install `tokio`
> ```shell
> $ cargo add tokio
> ```
> And then you can use it in `main` function:
> ```rust
> 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 [docs.rs](https://docs.rs/codewars-api/latest/codewars_api)
Also, you can see examples of using this crate in [examples](./examples). To run example clone this repo and run this:
```shell
$ cargo run --example
```
For example:
```shell
$ cargo run --example print_name
```
# See Also
- [conemu-progressbar-go](https://github.com/ankddev/conemu-progressbar-go) - Progress bar for ConEmu for Go
- [envfetch](https://github.com/ankddev/envfetch) - Lightweight crossplatform CLI tool for working with environment variables
- [terminal-go](https://github.com/ankddev/terminal-go) - Go library for working with ANSI/VT terminal sequences
- [zapret-discord-youtube](https://github.com/ankddev/zapret-discord-youtube) - Zapret build for Windows for fixing Discord and YouTube in Russia or othher services
# Contributing
Firstly, you should install [Git](https://git-scm.com/download) and [Rust](https://www.rust-lang.org/tools/install).
* Create fork of this repo by pressing button on the top of this page.
* Clone your fork
```shell
$ git clone https://github.com/username/codewars-api-rs.git
```
* Go to directory where you cloned repo
```shell
$ cd codewars-api-rs
```
* Create new branch
* Make your changes
* Run tests:
```shell
$ cargo test
```
* [Write tests and documentation for your changes](#writing-tests)
* Format and lint code:
```shell
$ cargo fmt
$ cargo clippy
```
* Commit changes
* Create PR
## Writing tests
You can learn more about writing tests in the [official documentation](https://doc.rust-lang.org/book/ch11-01-writing-tests.html).
We test all methods of `RestCodewarsClient` struct in [doctests](https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html).
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](https://docs.rs/mockito/latest/mockito/) for more information. Mocks are stored in `tests/mocks` directory. All mocks are from Codewars documentation.