Rework the rest of the mappings
This commit is contained in:
parent
52e1d1822a
commit
ed01b28c0d
31
src/API/Enum/AnimeWatchingStatus/Route.php
Normal file
31
src/API/Enum/AnimeWatchingStatus/Route.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Hummingbird Anime List Client
|
||||
*
|
||||
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Enum\AnimeWatchingStatus;
|
||||
|
||||
use Aviat\Ion\Enum as Enum;
|
||||
|
||||
/**
|
||||
* Possible values for current watching status of anime
|
||||
*/
|
||||
class Route extends Enum {
|
||||
const ALL = 'all';
|
||||
const WATCHING = 'watching';
|
||||
const PLAN_TO_WATCH = 'plan_to_watch';
|
||||
const DROPPED = 'dropped';
|
||||
const ON_HOLD = 'on_hold';
|
||||
const COMPLETED = 'completed';
|
||||
}
|
31
src/API/Enum/AnimeWatchingStatus/Title.php
Normal file
31
src/API/Enum/AnimeWatchingStatus/Title.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Hummingbird Anime List Client
|
||||
*
|
||||
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Enum\AnimeWatchingStatus;
|
||||
|
||||
use Aviat\Ion\Enum as Enum;
|
||||
|
||||
/**
|
||||
* Possible values for current watching status of anime
|
||||
*/
|
||||
class Title extends Enum {
|
||||
const ALL = 'All';
|
||||
const WATCHING = 'Currently Watching';
|
||||
const PLAN_TO_WATCH = 'Plan to Watch';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
}
|
@ -16,11 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API;
|
||||
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\{
|
||||
AnimeAiringStatus,
|
||||
AnimeWatchingStatus,
|
||||
MangaReadingStatus
|
||||
};
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
|
||||
use DateTimeImmutable;
|
||||
|
||||
const AUTH_URL = 'https://kitsu.io/api/oauth/token';
|
||||
@ -35,38 +31,6 @@ class Kitsu {
|
||||
const AUTH_USER_ID_KEY = 'kitsu-auth-userid';
|
||||
const AUTH_TOKEN_CACHE_KEY = 'kitsu-auth-token';
|
||||
|
||||
/**
|
||||
* Map of Kitsu status to label for select menus
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStatusToSelectMap()
|
||||
{
|
||||
return [
|
||||
AnimeWatchingStatus::WATCHING => 'Currently Watching',
|
||||
AnimeWatchingStatus::PLAN_TO_WATCH => 'Plan to Watch',
|
||||
AnimeWatchingStatus::COMPLETED => 'Completed',
|
||||
AnimeWatchingStatus::ON_HOLD => 'On Hold',
|
||||
AnimeWatchingStatus::DROPPED => 'Dropped'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of Kitsu Manga status to label for select menus
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStatusToMangaSelectMap()
|
||||
{
|
||||
return [
|
||||
MangaReadingStatus::READING => 'Currently Reading',
|
||||
MangaReadingStatus::PLAN_TO_READ => 'Plan to Read',
|
||||
MangaReadingStatus::COMPLETED => 'Completed',
|
||||
MangaReadingStatus::ON_HOLD => 'On Hold',
|
||||
MangaReadingStatus::DROPPED => 'Dropped'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether an anime is airing, finished airing, or has not yet aired
|
||||
*
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Mapping;
|
||||
|
||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{Route, Title};
|
||||
use Aviat\AnimeClient\API\{
|
||||
Kitsu\Enum\AnimeWatchingStatus as Kitsu,
|
||||
MAL\Enum\AnimeWatchingStatus as MAL
|
||||
@ -39,29 +39,39 @@ class AnimeWatchingStatus extends Enum {
|
||||
MAL::DROPPED => Kitsu::DROPPED
|
||||
];
|
||||
|
||||
const KITSU_TO_TITLE = [
|
||||
'all' => Title::ALL,
|
||||
Kitsu::WATCHING => Title::WATCHING,
|
||||
Kitsu::PLAN_TO_WATCH => Title::PLAN_TO_WATCH,
|
||||
Kitsu::ON_HOLD => Title::ON_HOLD,
|
||||
Kitsu::DROPPED => Title::DROPPED,
|
||||
Kitsu::COMPLETED => Title::COMPLETED
|
||||
];
|
||||
|
||||
const ROUTE_TO_KITSU = [
|
||||
'watching' => Kitsu::WATCHING,
|
||||
'plan_to_watch' => Kitsu::PLAN_TO_WATCH,
|
||||
'on_hold' => Kitsu::ON_HOLD,
|
||||
'all' => 'all',
|
||||
'dropped' => Kitsu::DROPPED,
|
||||
'completed' => Kitsu::COMPLETED
|
||||
Route::WATCHING => Kitsu::WATCHING,
|
||||
Route::PLAN_TO_WATCH => Kitsu::PLAN_TO_WATCH,
|
||||
Route::ON_HOLD => Kitsu::ON_HOLD,
|
||||
Route::ALL => 'all',
|
||||
Route::DROPPED => Kitsu::DROPPED,
|
||||
Route::COMPLETED => Kitsu::COMPLETED
|
||||
];
|
||||
|
||||
const ROUTE_TO_TITLE = [
|
||||
'all' => 'All',
|
||||
'watching' => 'Currently Watching',
|
||||
'plan_to_watch' => 'Plan to Watch',
|
||||
'on_hold' => 'On Hold',
|
||||
'dropped' => 'Dropped',
|
||||
'completed' => 'Completed'
|
||||
Route::ALL => Title::ALL,
|
||||
Route::WATCHING => Title::WATCHING,
|
||||
Route::PLAN_TO_WATCH => Title::PLAN_TO_WATCH,
|
||||
Route::ON_HOLD => Title::ON_HOLD,
|
||||
Route::DROPPED => Title::DROPPED,
|
||||
Route::COMPLETED => Title::COMPLETED
|
||||
];
|
||||
|
||||
const KITSU_TO_TITLE = [
|
||||
Kitsu::WATCHING => 'Currently Watching',
|
||||
Kitsu::PLAN_TO_WATCH => 'Plan to Watch',
|
||||
Kitsu::ON_HOLD => 'On Hold',
|
||||
Kitsu::DROPPED => 'Dropped',
|
||||
Kitsu::COMPLETED => 'Completed'
|
||||
const TITLE_TO_ROUTE = [
|
||||
Title::ALL => Route::ALL,
|
||||
Title::WATCHING => Route::WATCHING,
|
||||
Title::PLAN_TO_WATCH => Route::PLAN_TO_WATCH,
|
||||
Title::ON_HOLD => Route::ON_HOLD,
|
||||
Title::DROPPED => Route::DROPPED,
|
||||
Title::COMPLETED => Route::COMPLETED
|
||||
];
|
||||
}
|
||||
}
|
||||
|
33
src/API/Title.java
Normal file
33
src/API/Title.java
Normal file
@ -0,0 +1,33 @@
|
||||
package API;
|
||||
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Hummingbird Anime List Client
|
||||
*
|
||||
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Enum\MangaReadingStatus;
|
||||
|
||||
use Aviat\Ion\Enum as Enum;
|
||||
|
||||
/**
|
||||
* Possible values for current reading status of manga
|
||||
*/
|
||||
class Title extends Enum {
|
||||
const ALL = 'All';
|
||||
const READING = 'Currently Reading';
|
||||
const PLAN_TO_READ = 'Plan to Read';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\AnimeClient\API\Kitsu;
|
||||
use Aviat\AnimeClient\API\Kitsu\{
|
||||
Enum\AnimeWatchingStatus as KitsuWatchingStatus,
|
||||
Transformer\AnimeListTransformer
|
||||
|
@ -17,11 +17,7 @@
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\AnimeClient\Controller;
|
||||
use Aviat\AnimeClient\API\Kitsu;
|
||||
use Aviat\AnimeClient\API\Kitsu\{
|
||||
Enum\MangaReadingStatus as KitsuReadingStatus,
|
||||
Transformer\MangaListTransformer
|
||||
};
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
@ -219,7 +215,7 @@ class Manga extends Controller {
|
||||
{
|
||||
if ($this->request->getHeader('content-type')[0] === 'application/json')
|
||||
{
|
||||
$data = JSON::decode((string)$this->request->getBody());
|
||||
$data = Json::decode((string)$this->request->getBody());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -16,12 +16,8 @@
|
||||
|
||||
namespace Aviat\AnimeClient\Model;
|
||||
|
||||
use function Amp\some;
|
||||
use function Amp\wait;
|
||||
|
||||
use Amp\Artax\Client;
|
||||
use Aviat\AnimeClient\API\ParallelAPIRequest;
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeWatchingStatus;
|
||||
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Json;
|
||||
|
||||
@ -29,26 +25,6 @@ use Aviat\Ion\Json;
|
||||
* Model for handling requests dealing with the anime list
|
||||
*/
|
||||
class Anime extends API {
|
||||
|
||||
// Display constants
|
||||
const WATCHING = 'Watching';
|
||||
const PLAN_TO_WATCH = 'Plan to Watch';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
|
||||
/**
|
||||
* Map of API status constants to display constants
|
||||
* @var array
|
||||
*/
|
||||
protected $const_map = [
|
||||
AnimeWatchingStatus::WATCHING => self::WATCHING,
|
||||
AnimeWatchingStatus::PLAN_TO_WATCH => self::PLAN_TO_WATCH,
|
||||
AnimeWatchingStatus::ON_HOLD => self::ON_HOLD,
|
||||
AnimeWatchingStatus::DROPPED => self::DROPPED,
|
||||
AnimeWatchingStatus::COMPLETED => self::COMPLETED,
|
||||
];
|
||||
|
||||
/**
|
||||
* Model for making requests to Kitsu API
|
||||
*
|
||||
@ -75,7 +51,7 @@ class Anime extends API {
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$config = $container->get('config');
|
||||
$this->kitsuModel = $container->get('kitsu-model');
|
||||
@ -95,8 +71,10 @@ class Anime extends API {
|
||||
$data = $this->kitsuModel->getAnimeList($status);
|
||||
$this->sortByName($data, 'anime');
|
||||
|
||||
$key = AnimeWatchingStatus::KITSU_TO_TITLE[$status];
|
||||
|
||||
$output = [];
|
||||
$output[$this->const_map[$status]] = $data;
|
||||
$output[$key] = $data;
|
||||
|
||||
return $output;
|
||||
}
|
||||
@ -167,7 +145,7 @@ class Anime extends API {
|
||||
$requester->addRequest($this->malModel->createListItem($malData), 'mal');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$requester->addRequest($this->kitsuModel->createListItem($data), 'kitsu');
|
||||
|
||||
$results = $requester->makeRequests(TRUE);
|
||||
@ -183,8 +161,8 @@ class Anime extends API {
|
||||
*/
|
||||
public function updateLibraryItem(array $data): array
|
||||
{
|
||||
$requester = new ParallelAPIRequest();
|
||||
|
||||
$requester = new ParallelAPIRequest();
|
||||
|
||||
if ($this->useMALAPI)
|
||||
{
|
||||
$requester->addRequest($this->malModel->updateListItem($data), 'mal');
|
||||
@ -193,7 +171,7 @@ class Anime extends API {
|
||||
$requester->addRequest($this->kitsuModel->updateListItem($data), 'kitsu');
|
||||
|
||||
$results = $requester->makeRequests(TRUE);
|
||||
|
||||
|
||||
return [
|
||||
'body' => Json::decode($results[1]['kitsu']->getBody()),
|
||||
'statusCode' => $results[1]['kitsu']->getStatus()
|
||||
|
@ -17,48 +17,21 @@
|
||||
namespace Aviat\AnimeClient\Tests\API;
|
||||
|
||||
use Aviat\AnimeClient\API\Kitsu;
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\{
|
||||
AnimeAiringStatus,
|
||||
AnimeWatchingStatus,
|
||||
MangaReadingStatus
|
||||
};
|
||||
use DateTimeImmutable;
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class KitsuTest extends TestCase {
|
||||
public function testGetStatusToSelectMap()
|
||||
{
|
||||
$this->assertEquals([
|
||||
AnimeWatchingStatus::WATCHING => 'Currently Watching',
|
||||
AnimeWatchingStatus::PLAN_TO_WATCH => 'Plan to Watch',
|
||||
AnimeWatchingStatus::COMPLETED => 'Completed',
|
||||
AnimeWatchingStatus::ON_HOLD => 'On Hold',
|
||||
AnimeWatchingStatus::DROPPED => 'Dropped'
|
||||
], Kitsu::getStatusToSelectMap());
|
||||
}
|
||||
|
||||
public function testGetStatusToMangaSelectMap()
|
||||
{
|
||||
$this->assertEquals([
|
||||
MangaReadingStatus::READING => 'Currently Reading',
|
||||
MangaReadingStatus::PLAN_TO_READ => 'Plan to Read',
|
||||
MangaReadingStatus::COMPLETED => 'Completed',
|
||||
MangaReadingStatus::ON_HOLD => 'On Hold',
|
||||
MangaReadingStatus::DROPPED => 'Dropped'
|
||||
], Kitsu::getStatusToMangaSelectMap());
|
||||
}
|
||||
|
||||
public function testGetAiringStatus()
|
||||
{
|
||||
$actual = Kitsu::getAiringStatus('next week', 'next year');
|
||||
$this->assertEquals(AnimeAiringStatus::NOT_YET_AIRED, $actual);
|
||||
}
|
||||
|
||||
|
||||
public function testParseStreamingLinksEmpty()
|
||||
{
|
||||
$this->assertEquals([], Kitsu::parseStreamingLinks([]));
|
||||
}
|
||||
|
||||
|
||||
public function testTitleIsUniqueEmpty()
|
||||
{
|
||||
$actual = Kitsu::filterTitles([
|
||||
|
Loading…
Reference in New Issue
Block a user