Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
9 changed files with 140 additions and 125 deletions
Showing only changes of commit 88f6a3fc4f - Show all commits

View 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';
}

View 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';
}

View File

@ -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
*

View File

@ -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
View 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';
}

View File

@ -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

View File

@ -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
{

View File

@ -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
*
@ -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;
}

View File

@ -17,37 +17,10 @@
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');