2018-08-10 20:10:19 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2018-08-10 20:10:19 -04:00
|
|
|
*
|
|
|
|
* PHP version 7
|
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 4.0
|
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\API\Anilist;
|
|
|
|
|
2018-09-20 10:41:28 -04:00
|
|
|
use Amp\Artax\Request;
|
|
|
|
|
|
|
|
use Aviat\AnimeClient\API\ListItemInterface;
|
|
|
|
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
|
|
|
use Aviat\AnimeClient\Types\FormItemData;
|
2018-08-10 20:10:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CRUD operations for MAL list items
|
|
|
|
*/
|
2018-09-20 10:41:28 -04:00
|
|
|
final class ListItem implements ListItemInterface{
|
2018-08-10 20:10:19 -04:00
|
|
|
use AnilistTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a list item
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return Request
|
|
|
|
*/
|
2018-09-20 10:41:28 -04:00
|
|
|
public function create(array $data): Request
|
2018-08-10 20:10:19 -04:00
|
|
|
{
|
2018-09-20 10:41:28 -04:00
|
|
|
return $this->mutateRequest('CreateMediaListEntry', $data);
|
2018-08-10 20:10:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a list item
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @param string $type
|
|
|
|
* @return Request
|
|
|
|
*/
|
|
|
|
public function delete(string $id, string $type = 'anime'): Request
|
|
|
|
{
|
2018-08-15 08:51:37 -04:00
|
|
|
// @TODO: implement
|
2018-08-10 20:10:19 -04:00
|
|
|
}
|
|
|
|
|
2018-09-20 10:41:28 -04:00
|
|
|
/**
|
|
|
|
* Get the data for a list item
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-08-10 20:10:19 -04:00
|
|
|
public function get(string $id): array
|
|
|
|
{
|
2018-09-20 10:41:28 -04:00
|
|
|
return $this->runQuery('MediaListItem', ['id' => $id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase the progress on the medium by 1
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @param FormItemData $data
|
|
|
|
* @return Request
|
|
|
|
*/
|
|
|
|
public function increment(string $id, FormItemData $data): Request
|
|
|
|
{
|
|
|
|
return $this->mutateRequest('IncrementMediaListEntry', [
|
|
|
|
'id' => $id,
|
|
|
|
'progress' => $data['progress'],
|
|
|
|
]);
|
2018-08-10 20:10:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a list item
|
|
|
|
*
|
|
|
|
* @param string $id
|
2018-09-20 10:41:28 -04:00
|
|
|
* @param FormItemData $data
|
2018-08-10 20:10:19 -04:00
|
|
|
* @return Request
|
|
|
|
*/
|
2018-09-20 10:41:28 -04:00
|
|
|
public function update(string $id, FormItemData $data): Request
|
2018-08-10 20:10:19 -04:00
|
|
|
{
|
2018-09-20 10:41:28 -04:00
|
|
|
// @TODO Handle weirdness with reWatching
|
|
|
|
return $this->mutateRequest('UpdateMediaListEntry', [
|
|
|
|
'id' => $id,
|
|
|
|
'status' => AnimeWatchingStatus::KITSU_TO_ANILIST[$data['status']],
|
|
|
|
'score' => $data['rating'] * 20,
|
|
|
|
'progress' => $data['progress'],
|
|
|
|
'repeat' => (int)$data['reconsumeCount'],
|
|
|
|
'private' => (bool)$data['private'],
|
|
|
|
'notes' => $data['notes'],
|
|
|
|
]);
|
2018-08-10 20:10:19 -04:00
|
|
|
}
|
|
|
|
}
|