|
| 1 | +# Codewars API Client |
| 2 | + |
| 3 | +[](https://github.com/jamesrweb/codewars-api-client) |
| 4 | +[](https://github.com/jamesrweb/codewars-api-client/blob/master/LICENSE) |
| 5 | +[](https://GitHub.com/jamesrweb/codewars-api-client/graphs/contributors/) |
| 6 | +[](https://GitHub.com/jamesrweb/codewars-api-client/issues/) |
| 7 | +[](https://GitHub.com/jamesrweb/codewars-api-client/pulls/) |
| 8 | + |
| 9 | +A library built to interact with the Codewars API and platform. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Use the package manager [composer](https://getcomposer.org/) to install the library using the following command. |
| 14 | + |
| 15 | +```bash |
| 16 | +composer require jamesrweb/codewars-api-client |
| 17 | +``` |
| 18 | + |
| 19 | +## Basic Usage |
| 20 | + |
| 21 | +Once the package has been installed, we can create the required clients like. |
| 22 | + |
| 23 | +```php |
| 24 | +<?php |
| 25 | + |
| 26 | +declare(strict_types=1); |
| 27 | + |
| 28 | +require __DIR__ . '/vendor/autoload.php'; |
| 29 | + |
| 30 | +use CodewarsApiClient\Client; |
| 31 | + |
| 32 | +$client = new Client("your-api-key"); |
| 33 | +``` |
| 34 | + |
| 35 | +## The `Client` |
| 36 | + |
| 37 | +A `Client` instance allows us to interact with the codewars API in a consistent manner. |
| 38 | + |
| 39 | +### Methods |
| 40 | + |
| 41 | +#### Get information about the user |
| 42 | + |
| 43 | +To get information regarding the user, you can run: |
| 44 | + |
| 45 | +```php |
| 46 | +$client->user(string $username); |
| 47 | +``` |
| 48 | + |
| 49 | +#### Get challenges created by the user |
| 50 | + |
| 51 | +To get a list of challenges the user created, you can run: |
| 52 | +```php |
| 53 | +$client->authored(string $username); |
| 54 | +``` |
| 55 | + |
| 56 | +#### Get challenges completed by the user |
| 57 | + |
| 58 | +To get a list of challenges the user completed, you can run: |
| 59 | + |
| 60 | +```php |
| 61 | +$client->completed(string $username); |
| 62 | +``` |
| 63 | + |
| 64 | +#### Get information about a specific challenge |
| 65 | + |
| 66 | +To get an overview regarding a specific challenge, you can run: |
| 67 | + |
| 68 | +```php |
| 69 | +$client->challenge(string $id); |
| 70 | +``` |
| 71 | + |
| 72 | +#### Get information about multiple challenges |
| 73 | + |
| 74 | +To get an overview of multiple challenges at once, you can run: |
| 75 | + |
| 76 | +```php |
| 77 | +$client->challenges(array<string> $ids); |
| 78 | +``` |
| 79 | + |
| 80 | +## Interfaces |
| 81 | + |
| 82 | +There are a number of interfaces exposed for you to use if required. These are namespaced under the `CodewarsApiClient\Interfaces` namespace. |
| 83 | + |
| 84 | +### The `ChallengeInterface` |
| 85 | + |
| 86 | +This interface is for the methods that access challenge specific data. |
| 87 | + |
| 88 | +### The `UserInterface` |
| 89 | + |
| 90 | +This interface is for the methods that access user specific data. |
| 91 | + |
| 92 | +### The `ClientInterface` |
| 93 | + |
| 94 | +This interface is for the methods that are accessible to use via a `Client` instance and is contains all methods defined in the `ChallengeInterface` and `UserInterface` interfaces. |
| 95 | + |
| 96 | +## Contributing |
| 97 | + |
| 98 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
| 99 | + |
| 100 | +Please make sure to update tests as appropriate. |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +This project uses [an MIT license](https://choosealicense.com/licenses/mit/). If you wish to view [the license](https://github.com/jamesrweb/codewars-api-client/blob/master/LICENSE), it can be found in the project root. |
0 commit comments