Skip to content

Commit

Permalink
Update README and added a little test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Vernieuwe committed Sep 17, 2022
1 parent 4a919f9 commit 8ed230c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@ composer require jikan/jikan-php

# Getting Started

## Instantiate the client

```php
$jikan = new \Jikan\JikanPHP\JikanPHPClient();
## Require your client implementation
For example
```sh
composer require php-http/guzzle7-adapter
```

## Use it to request MAL data
## Instantiate the client

```php
$request = new \JikanPHP\Request\Anime\AnimeRequest(1);
$anime = $jikan->getAnime($request);
$jikan = Client::create();
```

All responses are converted to PHP classes.

# Customize guzzle

## Use it to request MAL data
Check the client for the correct type hint
```php
$guzzle = new GuzzleHttp\Client();
// Add middlewares to the client, or configs
$jikan = new \Jikan\JikanPHP\JikanPHPClient($guzzle);
// The configured client is now used internally
/** @var AnimeIdGetResponse200 $anime */
$anime = $jikan->getAnimeById(5114);
```

Using the client should be self-explanatory since it is fully type-hinted.

If you experience any issues, open an issue, or even better a Pull Request!
10 changes: 1 addition & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.11",
"jane-php/open-api-3": "^7.3",
"php-http/guzzle7-adapter": "^1.0",
"phpro/grumphp": "^1.13",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7"
Expand All @@ -21,15 +22,6 @@
"psr-4": {
"Jikan\\JikanPHP\\": [
"src"
],
"JikanPHP\\Model\\": [
"model"
],
"JikanPHP\\Request\\": [
"request"
],
"JikanPHP\\Helper\\": [
"helper"
]
}
},
Expand Down
17 changes: 17 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

use Jikan\JikanPHP\Client;
use Jikan\JikanPHP\Model\AnimeIdGetResponse200;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{
public function test_it_gets_anime(): void
{
self::markTestSkipped('will perform actual request');
$jikan = Client::create();
/** @var AnimeIdGetResponse200 $anime */
$anime = $jikan->getAnimeById(5114);
self::assertEquals('Fullmetal Alchemist: Brotherhood', $anime->getData()->getTitle());
}
}

0 comments on commit 8ed230c

Please sign in to comment.