Remove old transformer classes
This commit is contained in:
parent
0868fb43bc
commit
b28e1f13ee
@ -21,7 +21,6 @@ use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeListTransformer;
|
|||||||
use Aviat\AnimeClient\Kitsu as K;
|
use Aviat\AnimeClient\Kitsu as K;
|
||||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
|
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeHistoryTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeHistoryTransformer;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\OldAnimeListTransformer;
|
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeTransformer;
|
||||||
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
||||||
use Aviat\AnimeClient\API\ParallelAPIRequest;
|
use Aviat\AnimeClient\API\ParallelAPIRequest;
|
||||||
@ -34,14 +33,6 @@ use Aviat\Ion\Json;
|
|||||||
* Anime-related list methods
|
* Anime-related list methods
|
||||||
*/
|
*/
|
||||||
trait AnimeTrait {
|
trait AnimeTrait {
|
||||||
/**
|
|
||||||
* Class to map anime list items
|
|
||||||
* to a common format used by
|
|
||||||
* templates
|
|
||||||
*
|
|
||||||
* @var OldAnimeListTransformer
|
|
||||||
*/
|
|
||||||
protected OldAnimeListTransformer $oldListTransformer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var AnimeTransformer
|
* @var AnimeTransformer
|
||||||
|
@ -21,7 +21,6 @@ use Aviat\AnimeClient\Kitsu as K;
|
|||||||
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\Kitsu as KitsuReadingStatus;
|
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\Kitsu as KitsuReadingStatus;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaHistoryTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaHistoryTransformer;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\OldMangaListTransformer;
|
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaTransformer;
|
||||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||||
use Aviat\AnimeClient\API\ParallelAPIRequest;
|
use Aviat\AnimeClient\API\ParallelAPIRequest;
|
||||||
@ -39,11 +38,6 @@ trait MangaTrait {
|
|||||||
*/
|
*/
|
||||||
protected MangaTransformer $mangaTransformer;
|
protected MangaTransformer $mangaTransformer;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var OldMangaListTransformer
|
|
||||||
*/
|
|
||||||
protected OldMangaListTransformer $mangaListTransformer;
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// ! Manga-specific methods
|
// ! Manga-specific methods
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
@ -29,10 +29,8 @@ use Aviat\AnimeClient\API\{
|
|||||||
};
|
};
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
||||||
AnimeTransformer,
|
AnimeTransformer,
|
||||||
OldAnimeListTransformer,
|
|
||||||
LibraryEntryTransformer,
|
LibraryEntryTransformer,
|
||||||
MangaTransformer,
|
MangaTransformer,
|
||||||
OldMangaListTransformer
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use Aviat\Banker\Exception\InvalidArgumentException;
|
use Aviat\Banker\Exception\InvalidArgumentException;
|
||||||
@ -66,9 +64,7 @@ final class Model {
|
|||||||
public function __construct(ListItem $listItem)
|
public function __construct(ListItem $listItem)
|
||||||
{
|
{
|
||||||
$this->animeTransformer = new AnimeTransformer();
|
$this->animeTransformer = new AnimeTransformer();
|
||||||
$this->oldListTransformer = new OldAnimeListTransformer();
|
|
||||||
$this->mangaTransformer = new MangaTransformer();
|
$this->mangaTransformer = new MangaTransformer();
|
||||||
$this->mangaListTransformer = new OldMangaListTransformer();
|
|
||||||
|
|
||||||
$this->listItem = $listItem;
|
$this->listItem = $listItem;
|
||||||
}
|
}
|
||||||
|
@ -1,156 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* Hummingbird Anime List Client
|
|
||||||
*
|
|
||||||
* An API client for Kitsu to manage anime and manga watch lists
|
|
||||||
*
|
|
||||||
* PHP version 7.4
|
|
||||||
*
|
|
||||||
* @package HummingbirdAnimeClient
|
|
||||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
||||||
* @copyright 2015 - 2020 Timothy J. Warren
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
||||||
* @version 5.1
|
|
||||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
|
|
||||||
|
|
||||||
use Aviat\AnimeClient\Kitsu;
|
|
||||||
use Aviat\AnimeClient\Types\{
|
|
||||||
FormItem,
|
|
||||||
AnimeListItem
|
|
||||||
};
|
|
||||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
||||||
use Aviat\Ion\Type\StringType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transformer for anime list
|
|
||||||
*/
|
|
||||||
final class OldAnimeListTransformer extends AbstractTransformer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert raw api response to a more
|
|
||||||
* logical and workable structure
|
|
||||||
*
|
|
||||||
* @param array $item API library item
|
|
||||||
* @return AnimeListItem
|
|
||||||
*/
|
|
||||||
public function transform($item): AnimeListItem
|
|
||||||
{
|
|
||||||
$included = $item['included'];
|
|
||||||
$animeId = $item['relationships']['media']['data']['id'];
|
|
||||||
$anime = $included['anime'][$animeId];
|
|
||||||
|
|
||||||
$genres = [];
|
|
||||||
|
|
||||||
foreach($anime['relationships']['categories'] as $genre)
|
|
||||||
{
|
|
||||||
$genres[] = $genre['title'];
|
|
||||||
}
|
|
||||||
|
|
||||||
sort($genres);
|
|
||||||
|
|
||||||
$rating = (int) $item['attributes']['ratingTwenty'] !== 0
|
|
||||||
? $item['attributes']['ratingTwenty'] / 2
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$total_episodes = array_key_exists('episodeCount', $anime) && (int) $anime['episodeCount'] !== 0
|
|
||||||
? (int) $anime['episodeCount']
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$MALid = NULL;
|
|
||||||
|
|
||||||
if (array_key_exists('mappings', $anime['relationships']))
|
|
||||||
{
|
|
||||||
foreach ($anime['relationships']['mappings'] as $mapping)
|
|
||||||
{
|
|
||||||
if ($mapping['externalSite'] === 'myanimelist/anime')
|
|
||||||
{
|
|
||||||
$MALid = $mapping['externalId'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$streamingLinks = array_key_exists('streamingLinks', $anime['relationships'])
|
|
||||||
? Kitsu::parseListItemStreamingLinks($included, $animeId)
|
|
||||||
: [];
|
|
||||||
|
|
||||||
$titles = Kitsu::filterTitles($anime);
|
|
||||||
$title = array_shift($titles);
|
|
||||||
|
|
||||||
return AnimeListItem::from([
|
|
||||||
'id' => $item['id'],
|
|
||||||
'mal_id' => $MALid,
|
|
||||||
'episodes' => [
|
|
||||||
'watched' => (int) $item['attributes']['progress'] !== 0
|
|
||||||
? (int) $item['attributes']['progress']
|
|
||||||
: '-',
|
|
||||||
'total' => $total_episodes,
|
|
||||||
'length' => $anime['episodeLength'],
|
|
||||||
],
|
|
||||||
'airing' => [
|
|
||||||
'status' => Kitsu::getAiringStatus($anime['startDate'], $anime['endDate']),
|
|
||||||
'started' => $anime['startDate'],
|
|
||||||
'ended' => $anime['endDate']
|
|
||||||
],
|
|
||||||
'anime' => [
|
|
||||||
'id' => $animeId,
|
|
||||||
'age_rating' => $anime['ageRating'],
|
|
||||||
'title' => $title,
|
|
||||||
'titles' => $titles,
|
|
||||||
'slug' => $anime['slug'],
|
|
||||||
'show_type' => (string)StringType::from($anime['subtype'])->upperCaseFirst(),
|
|
||||||
'cover_image' => $anime['posterImage']['small'],
|
|
||||||
'genres' => $genres,
|
|
||||||
'streaming_links' => $streamingLinks,
|
|
||||||
],
|
|
||||||
'watching_status' => $item['attributes']['status'],
|
|
||||||
'notes' => $item['attributes']['notes'],
|
|
||||||
'rewatching' => (bool) $item['attributes']['reconsuming'],
|
|
||||||
'rewatched' => (int) $item['attributes']['reconsumeCount'],
|
|
||||||
'user_rating' => $rating,
|
|
||||||
'private' => $item['attributes']['private'] ?? FALSE,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert transformed data to
|
|
||||||
* api response format
|
|
||||||
*
|
|
||||||
* @param array $item Transformed library item
|
|
||||||
* @return FormItem API library item
|
|
||||||
*/
|
|
||||||
public function untransform($item): FormItem
|
|
||||||
{
|
|
||||||
$privacy = (array_key_exists('private', $item) && $item['private']);
|
|
||||||
$rewatching = (array_key_exists('rewatching', $item) && $item['rewatching']);
|
|
||||||
|
|
||||||
$untransformed = FormItem::from([
|
|
||||||
'id' => $item['id'],
|
|
||||||
'anilist_item_id' => $item['anilist_item_id'] ?? NULL,
|
|
||||||
'mal_id' => $item['mal_id'] ?? NULL,
|
|
||||||
'data' => [
|
|
||||||
'status' => $item['watching_status'],
|
|
||||||
'reconsuming' => $rewatching,
|
|
||||||
'reconsumeCount' => $item['rewatched'],
|
|
||||||
'notes' => $item['notes'],
|
|
||||||
'private' => $privacy
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (is_numeric($item['episodes_watched']) && $item['episodes_watched'] > 0)
|
|
||||||
{
|
|
||||||
$untransformed['data']['progress'] = (int) $item['episodes_watched'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_numeric($item['user_rating']) && $item['user_rating'] > 0)
|
|
||||||
{
|
|
||||||
$untransformed['data']['ratingTwenty'] = $item['user_rating'] * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $untransformed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// End of AnimeListTransformer.php
|
|
@ -1,148 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* Hummingbird Anime List Client
|
|
||||||
*
|
|
||||||
* An API client for Kitsu to manage anime and manga watch lists
|
|
||||||
*
|
|
||||||
* PHP version 7.4
|
|
||||||
*
|
|
||||||
* @package HummingbirdAnimeClient
|
|
||||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
||||||
* @copyright 2015 - 2020 Timothy J. Warren
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
||||||
* @version 5.1
|
|
||||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
|
|
||||||
|
|
||||||
use Aviat\AnimeClient\Kitsu;
|
|
||||||
use Aviat\AnimeClient\Types\{
|
|
||||||
FormItem, FormItemData,
|
|
||||||
MangaListItem, MangaListItemDetail
|
|
||||||
};
|
|
||||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
||||||
use Aviat\Ion\Type\StringType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data transformation class for zippered Hummingbird manga
|
|
||||||
*/
|
|
||||||
final class OldMangaListTransformer extends AbstractTransformer {
|
|
||||||
/**
|
|
||||||
* Remap zipped anime data to a more logical form
|
|
||||||
*
|
|
||||||
* @param array $item manga entry item
|
|
||||||
* @return MangaListItem
|
|
||||||
*/
|
|
||||||
public function transform($item): MangaListItem
|
|
||||||
{
|
|
||||||
$included = $item['included'];
|
|
||||||
$mangaId = $item['relationships']['media']['data']['id'];
|
|
||||||
$manga = $included['manga'][$mangaId];
|
|
||||||
|
|
||||||
$genres = [];
|
|
||||||
|
|
||||||
foreach ($manga['relationships']['categories'] as $genre)
|
|
||||||
{
|
|
||||||
$genres[] = $genre['title'];
|
|
||||||
}
|
|
||||||
|
|
||||||
sort($genres);
|
|
||||||
|
|
||||||
$rating = (int) $item['attributes']['ratingTwenty'] !== 0
|
|
||||||
? $item['attributes']['ratingTwenty'] / 2
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$totalChapters = ((int) $manga['chapterCount'] !== 0)
|
|
||||||
? $manga['chapterCount']
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$totalVolumes = ((int) $manga['volumeCount'] !== 0)
|
|
||||||
? $manga['volumeCount']
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$readChapters = ((int) $item['attributes']['progress'] !== 0)
|
|
||||||
? $item['attributes']['progress']
|
|
||||||
: '-';
|
|
||||||
|
|
||||||
$MALid = NULL;
|
|
||||||
|
|
||||||
if (array_key_exists('mappings', $manga['relationships']))
|
|
||||||
{
|
|
||||||
foreach ($manga['relationships']['mappings'] as $mapping)
|
|
||||||
{
|
|
||||||
if ($mapping['externalSite'] === 'myanimelist/manga')
|
|
||||||
{
|
|
||||||
$MALid = $mapping['externalId'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$titles = Kitsu::filterTitles($manga);
|
|
||||||
$title = array_shift($titles);
|
|
||||||
|
|
||||||
return MangaListItem::from([
|
|
||||||
'id' => $item['id'],
|
|
||||||
'mal_id' => $MALid,
|
|
||||||
'chapters' => [
|
|
||||||
'read' => $readChapters,
|
|
||||||
'total' => $totalChapters
|
|
||||||
],
|
|
||||||
'volumes' => [
|
|
||||||
'read' => '-', //$item['attributes']['volumes_read'],
|
|
||||||
'total' => $totalVolumes
|
|
||||||
],
|
|
||||||
'manga' => MangaListItemDetail::from([
|
|
||||||
'genres' => $genres,
|
|
||||||
'id' => $mangaId,
|
|
||||||
'image' => $manga['posterImage']['small'],
|
|
||||||
'slug' => $manga['slug'],
|
|
||||||
'title' => $title,
|
|
||||||
'titles' => $titles,
|
|
||||||
'type' => (string)StringType::from($manga['subtype'])->upperCaseFirst(),
|
|
||||||
'url' => 'https://kitsu.io/manga/' . $manga['slug'],
|
|
||||||
]),
|
|
||||||
'reading_status' => $item['attributes']['status'],
|
|
||||||
'notes' => $item['attributes']['notes'],
|
|
||||||
'rereading' => (bool)$item['attributes']['reconsuming'],
|
|
||||||
'reread' => $item['attributes']['reconsumeCount'],
|
|
||||||
'user_rating' => $rating,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Untransform data to update the api
|
|
||||||
*
|
|
||||||
* @param array $item
|
|
||||||
* @return FormItem
|
|
||||||
*/
|
|
||||||
public function untransform($item): FormItem
|
|
||||||
{
|
|
||||||
$rereading = array_key_exists('rereading', $item) && (bool)$item['rereading'];
|
|
||||||
|
|
||||||
$map = FormItem::from([
|
|
||||||
'id' => $item['id'],
|
|
||||||
'mal_id' => $item['mal_id'],
|
|
||||||
'data' => FormItemData::from([
|
|
||||||
'status' => $item['status'],
|
|
||||||
'reconsuming' => $rereading,
|
|
||||||
'reconsumeCount' => (int)$item['reread_count'],
|
|
||||||
'notes' => $item['notes'],
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (is_numeric($item['chapters_read']) && $item['chapters_read'] > 0)
|
|
||||||
{
|
|
||||||
$map['data']['progress'] = (int)$item['chapters_read'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_numeric($item['new_rating']) && $item['new_rating'] > 0)
|
|
||||||
{
|
|
||||||
$map['data']['ratingTwenty'] = $item['new_rating'] * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// End of MangaListTransformer.php
|
|
@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\Controller;
|
|||||||
|
|
||||||
use Aura\Router\Exception\RouteNotFound;
|
use Aura\Router\Exception\RouteNotFound;
|
||||||
use Aviat\AnimeClient\Controller as BaseController;
|
use Aviat\AnimeClient\Controller as BaseController;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\OldAnimeListTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeListTransformer;
|
||||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
|
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
|
||||||
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
||||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
||||||
@ -228,7 +228,7 @@ final class Anime extends BaseController {
|
|||||||
|
|
||||||
// Do some minor data manipulation for
|
// Do some minor data manipulation for
|
||||||
// large form-based updates
|
// large form-based updates
|
||||||
$transformer = new OldAnimeListTransformer();
|
$transformer = new AnimeListTransformer();
|
||||||
$postData = $transformer->untransform($data);
|
$postData = $transformer->untransform($data);
|
||||||
$fullResult = $this->model->updateLibraryItem(FormItem::from($postData));
|
$fullResult = $this->model->updateLibraryItem(FormItem::from($postData));
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\Controller;
|
|||||||
|
|
||||||
use Aura\Router\Exception\RouteNotFound;
|
use Aura\Router\Exception\RouteNotFound;
|
||||||
use Aviat\AnimeClient\Controller;
|
use Aviat\AnimeClient\Controller;
|
||||||
use Aviat\AnimeClient\API\Kitsu\Transformer\OldMangaListTransformer;
|
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
||||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||||
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||||
use Aviat\AnimeClient\Types\FormItem;
|
use Aviat\AnimeClient\Types\FormItem;
|
||||||
@ -229,7 +229,7 @@ final class Manga extends Controller {
|
|||||||
|
|
||||||
// Do some minor data manipulation for
|
// Do some minor data manipulation for
|
||||||
// large form-based updates
|
// large form-based updates
|
||||||
$transformer = new OldMangaListTransformer();
|
$transformer = new MangaListTransformer();
|
||||||
$post_data = $transformer->untransform($data);
|
$post_data = $transformer->untransform($data);
|
||||||
$full_result = $this->model->updateLibraryItem(FormItem::from($post_data));
|
$full_result = $this->model->updateLibraryItem(FormItem::from($post_data));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user