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; namespace Aviat\AnimeClient\API;
use Aviat\AnimeClient\API\Kitsu\Enum\{ use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
AnimeAiringStatus,
AnimeWatchingStatus,
MangaReadingStatus
};
use DateTimeImmutable; use DateTimeImmutable;
const AUTH_URL = 'https://kitsu.io/api/oauth/token'; 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_USER_ID_KEY = 'kitsu-auth-userid';
const AUTH_TOKEN_CACHE_KEY = 'kitsu-auth-token'; 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 * Determine whether an anime is airing, finished airing, or has not yet aired
* *

View File

@ -15,7 +15,7 @@
*/ */
namespace Aviat\AnimeClient\API\Mapping; namespace Aviat\AnimeClient\API\Mapping;
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{Route, Title};
use Aviat\AnimeClient\API\{ use Aviat\AnimeClient\API\{
Kitsu\Enum\AnimeWatchingStatus as Kitsu, Kitsu\Enum\AnimeWatchingStatus as Kitsu,
MAL\Enum\AnimeWatchingStatus as MAL MAL\Enum\AnimeWatchingStatus as MAL
@ -39,29 +39,39 @@ class AnimeWatchingStatus extends Enum {
MAL::DROPPED => Kitsu::DROPPED 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 = [ const ROUTE_TO_KITSU = [
'watching' => Kitsu::WATCHING, Route::WATCHING => Kitsu::WATCHING,
'plan_to_watch' => Kitsu::PLAN_TO_WATCH, Route::PLAN_TO_WATCH => Kitsu::PLAN_TO_WATCH,
'on_hold' => Kitsu::ON_HOLD, Route::ON_HOLD => Kitsu::ON_HOLD,
'all' => 'all', Route::ALL => 'all',
'dropped' => Kitsu::DROPPED, Route::DROPPED => Kitsu::DROPPED,
'completed' => Kitsu::COMPLETED Route::COMPLETED => Kitsu::COMPLETED
]; ];
const ROUTE_TO_TITLE = [ const ROUTE_TO_TITLE = [
'all' => 'All', Route::ALL => Title::ALL,
'watching' => 'Currently Watching', Route::WATCHING => Title::WATCHING,
'plan_to_watch' => 'Plan to Watch', Route::PLAN_TO_WATCH => Title::PLAN_TO_WATCH,
'on_hold' => 'On Hold', Route::ON_HOLD => Title::ON_HOLD,
'dropped' => 'Dropped', Route::DROPPED => Title::DROPPED,
'completed' => 'Completed' Route::COMPLETED => Title::COMPLETED
]; ];
const KITSU_TO_TITLE = [ const TITLE_TO_ROUTE = [
Kitsu::WATCHING => 'Currently Watching', Title::ALL => Route::ALL,
Kitsu::PLAN_TO_WATCH => 'Plan to Watch', Title::WATCHING => Route::WATCHING,
Kitsu::ON_HOLD => 'On Hold', Title::PLAN_TO_WATCH => Route::PLAN_TO_WATCH,
Kitsu::DROPPED => 'Dropped', Title::ON_HOLD => Route::ON_HOLD,
Kitsu::COMPLETED => 'Completed' 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; namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller as BaseController; use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\API\Kitsu\{ use Aviat\AnimeClient\API\Kitsu\{
Enum\AnimeWatchingStatus as KitsuWatchingStatus, Enum\AnimeWatchingStatus as KitsuWatchingStatus,
Transformer\AnimeListTransformer Transformer\AnimeListTransformer

View File

@ -17,11 +17,7 @@
namespace Aviat\AnimeClient\Controller; namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\API\Kitsu; use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
use Aviat\AnimeClient\API\Kitsu\{
Enum\MangaReadingStatus as KitsuReadingStatus,
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\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
@ -219,7 +215,7 @@ class Manga extends Controller {
{ {
if ($this->request->getHeader('content-type')[0] === 'application/json') if ($this->request->getHeader('content-type')[0] === 'application/json')
{ {
$data = JSON::decode((string)$this->request->getBody()); $data = Json::decode((string)$this->request->getBody());
} }
else else
{ {

View File

@ -16,12 +16,8 @@
namespace Aviat\AnimeClient\Model; 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\ParallelAPIRequest;
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeWatchingStatus; use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Json; use Aviat\Ion\Json;
@ -29,26 +25,6 @@ use Aviat\Ion\Json;
* Model for handling requests dealing with the anime list * Model for handling requests dealing with the anime list
*/ */
class Anime extends API { 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 * Model for making requests to Kitsu API
* *
@ -95,8 +71,10 @@ class Anime extends API {
$data = $this->kitsuModel->getAnimeList($status); $data = $this->kitsuModel->getAnimeList($status);
$this->sortByName($data, 'anime'); $this->sortByName($data, 'anime');
$key = AnimeWatchingStatus::KITSU_TO_TITLE[$status];
$output = []; $output = [];
$output[$this->const_map[$status]] = $data; $output[$key] = $data;
return $output; return $output;
} }

View File

@ -17,37 +17,10 @@
namespace Aviat\AnimeClient\Tests\API; namespace Aviat\AnimeClient\Tests\API;
use Aviat\AnimeClient\API\Kitsu; use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\API\Kitsu\Enum\{ use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
AnimeAiringStatus,
AnimeWatchingStatus,
MangaReadingStatus
};
use DateTimeImmutable;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class KitsuTest extends 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() public function testGetAiringStatus()
{ {
$actual = Kitsu::getAiringStatus('next week', 'next year'); $actual = Kitsu::getAiringStatus('next week', 'next year');