HummingBirdAnimeClient/src/API/MAL/Model.php

103 lines
2.3 KiB
PHP
Raw Normal View History

2017-02-01 09:53:02 -05:00
<?php declare(strict_types=1);
/**
2017-02-15 16:13:32 -05:00
* Hummingbird Anime List Client
2017-02-01 09:53:02 -05:00
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
2017-02-15 16:13:32 -05:00
* @package HummingbirdAnimeClient
2017-02-01 09:53:02 -05:00
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2017 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
2017-02-01 09:53:02 -05:00
*/
namespace Aviat\AnimeClient\API\MAL;
use Amp\Artax\Request;
2017-02-04 15:18:34 -05:00
use Aviat\AnimeClient\API\MAL\ListItem;
use Aviat\AnimeClient\API\MAL\Transformer\AnimeListTransformer;
2017-02-01 09:53:02 -05:00
use Aviat\AnimeClient\API\XML;
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
2017-02-01 09:53:02 -05:00
use Aviat\Ion\Di\ContainerAware;
/**
* MyAnimeList API Model
*/
class Model {
use ContainerAware;
use MALTrait;
/**
* @var AnimeListTransformer
*/
protected $animeListTransformer;
2017-02-22 14:46:35 -05:00
/**
* @var ListItem
*/
protected $listItem;
2017-02-01 09:53:02 -05:00
/**
* MAL Model constructor.
2017-02-17 10:55:17 -05:00
*
* @param ListItem $listItem
2017-02-01 09:53:02 -05:00
*/
public function __construct(ListItem $listItem)
{
2017-02-04 15:18:34 -05:00
$this->animeListTransformer = new AnimeListTransformer();
2017-02-01 09:53:02 -05:00
$this->listItem = $listItem;
}
public function createFullListItem(array $data): Request
{
return $this->listItem->create($data);
}
2017-02-01 09:53:02 -05:00
public function createListItem(array $data): Request
2017-02-01 09:53:02 -05:00
{
2017-02-04 15:18:34 -05:00
$createData = [
'id' => $data['id'],
'data' => [
'status' => AnimeWatchingStatus::KITSU_TO_MAL[$data['status']]
2017-02-04 15:18:34 -05:00
]
];
return $this->listItem->create($createData);
}
public function getFullList(): array
{
$config = $this->container->get('config');
$userName = $config->get(['mal', 'username']);
$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
'headers' => [
'Accept' => 'text/xml'
],
'query' => [
'u' => $userName,
'status' => 'all'
]
]);
return $list['myanimelist']['anime'];
2017-02-01 09:53:02 -05:00
}
public function getListItem(string $listId): array
{
return [];
}
public function updateListItem(array $data): Request
2017-02-01 09:53:02 -05:00
{
2017-02-04 15:18:34 -05:00
$updateData = $this->animeListTransformer->untransform($data);
return $this->listItem->update($updateData['id'], $updateData['data']);
2017-02-01 09:53:02 -05:00
}
public function deleteListItem(string $id): Request
2017-02-01 09:53:02 -05:00
{
return $this->listItem->delete($id);
}
2016-12-20 12:55:43 -05:00
}