Version 5.1 - All the GraphQL #32
@ -11,7 +11,8 @@
|
||||
<section class="media-wrap">
|
||||
<?php foreach($items as $item): ?>
|
||||
<article class="media" id="a-<?= $item['hummingbird_id'] ?>">
|
||||
<img src="<?= $item['cover_image'] ?>" alt="<?= $item['title'] ?> cover image" />
|
||||
<img src="https://media.kitsu.io/anime/poster_images/<?= $item['hummingbird_id'] ?>/small.jpg"
|
||||
alt="<?= $item['title'] ?> cover image" />
|
||||
<div class="name">
|
||||
<a href="<?= $url->generate('anime.details', ['id' => $item['slug']]) ?>">
|
||||
<?= $item['title'] ?>
|
||||
|
@ -57,7 +57,7 @@ class JsonAPI {
|
||||
$included = static::organizeIncluded($data['included']);
|
||||
|
||||
// Inline organized data
|
||||
foreach($data['data'] as $i => $item)
|
||||
foreach($data['data'] as $i => &$item)
|
||||
{
|
||||
if (array_key_exists('relationships', $item))
|
||||
{
|
||||
@ -66,11 +66,11 @@ class JsonAPI {
|
||||
|
||||
if (array_keys($props) === ['links'])
|
||||
{
|
||||
unset($data['data'][$i]['relationships'][$relType]);
|
||||
unset($item['relationships'][$relType]);
|
||||
|
||||
if (empty($data['data'][$i]['relationships']))
|
||||
if (empty($item['relationships']))
|
||||
{
|
||||
unset($data['data'][$i]['relationships']);
|
||||
unset($item['relationships']);
|
||||
}
|
||||
|
||||
continue;
|
||||
@ -78,18 +78,18 @@ class JsonAPI {
|
||||
|
||||
if (array_key_exists('links', $props))
|
||||
{
|
||||
unset($data['data'][$i]['relationships'][$relType]['links']);
|
||||
unset($item['relationships'][$relType]['links']);
|
||||
}
|
||||
|
||||
if (array_key_exists('data', $props))
|
||||
{
|
||||
if (empty($props['data']))
|
||||
{
|
||||
unset($data['data'][$i]['relationships'][$relType]['data']);
|
||||
unset($item['relationships'][$relType]['data']);
|
||||
|
||||
if (empty($data['data'][$i]['relationships'][$relType]))
|
||||
if (empty($item['relationships'][$relType]))
|
||||
{
|
||||
unset($data['data'][$i]['relationships'][$relType]);
|
||||
unset($item['relationships'][$relType]);
|
||||
}
|
||||
|
||||
continue;
|
||||
@ -99,7 +99,7 @@ class JsonAPI {
|
||||
{
|
||||
$idKey = $props['data']['id'];
|
||||
$typeKey = $props['data']['type'];
|
||||
$relationship =& $data['data'][$i]['relationships'][$relType];
|
||||
$relationship =& $item['relationships'][$relType];
|
||||
unset($relationship['data']);
|
||||
|
||||
if (in_array($relType, $singular))
|
||||
@ -123,7 +123,7 @@ class JsonAPI {
|
||||
{
|
||||
$idKey = $props['data'][$j]['id'];
|
||||
$typeKey = $props['data'][$j]['type'];
|
||||
$relationship =& $data['data'][$i]['relationships'][$relType];
|
||||
$relationship =& $item['relationships'][$relType];
|
||||
|
||||
unset($relationship['data'][$j]);
|
||||
|
||||
@ -235,16 +235,6 @@ class JsonAPI {
|
||||
return $organized;
|
||||
}
|
||||
|
||||
public static function inlineRawIncludes(array &$data, string $key): array
|
||||
{
|
||||
foreach($data['data'] as $i => &$item)
|
||||
{
|
||||
$item[$key] = $data['included'][$i];
|
||||
}
|
||||
|
||||
return $data['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Take organized includes and inline them, where applicable
|
||||
*
|
||||
@ -305,17 +295,6 @@ class JsonAPI {
|
||||
return $organized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize 'included' data
|
||||
*
|
||||
* @param array $includes
|
||||
* @return array
|
||||
*/
|
||||
public static function lightlyOrganizeIncludes(array $includes): array
|
||||
{
|
||||
return static::organizeIncluded($includes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize relationship mappings to make them simpler to use
|
||||
*
|
||||
@ -349,30 +328,4 @@ class JsonAPI {
|
||||
|
||||
return $organized;
|
||||
}
|
||||
|
||||
public static function fillRelationshipsFromIncludes(array $relationships, array $includes): array
|
||||
{
|
||||
$output = [];
|
||||
|
||||
foreach ($relationships as $key => $block)
|
||||
{
|
||||
if (array_key_exists('data', $block) && is_array($block['data']) && ! empty($block['data']))
|
||||
{
|
||||
$output[$key] = [];
|
||||
if (array_key_exists('type', $block['data']) && array_key_exists('id', $block['data']))
|
||||
{
|
||||
$output[$key] = $includes[$block['data']['type']][$block['data']['id']];
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($block['data'] as $dBlock)
|
||||
{
|
||||
$output[$key][] = $includes[$dBlock['type']][$dBlock['id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -16,12 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API\Mapping;
|
||||
|
||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{
|
||||
Kitsu,
|
||||
MAL,
|
||||
Route,
|
||||
Title
|
||||
};
|
||||
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{Kitsu, MAL, Route, Title};
|
||||
use Aviat\Ion\Enum;
|
||||
|
||||
/**
|
||||
|
@ -16,12 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API\Mapping;
|
||||
|
||||
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{
|
||||
Kitsu,
|
||||
MAL,
|
||||
Title,
|
||||
Route
|
||||
};
|
||||
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{Kitsu, MAL, Title, Route};
|
||||
use Aviat\Ion\Enum;
|
||||
|
||||
/**
|
||||
|
@ -90,7 +90,7 @@ class SyncKitsuWithMal extends BaseCommand {
|
||||
if ( ! empty($data['addToKitsu']))
|
||||
{
|
||||
$this->echoBox("Adding missing anime list items to Kitsu");
|
||||
$this->createKitusListItems($data['addToKitsu'], 'anime');
|
||||
$this->createKitsuListItems($data['addToKitsu'], 'anime');
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,7 +373,7 @@ class SyncKitsuWithMal extends BaseCommand {
|
||||
];
|
||||
}
|
||||
|
||||
public function createKitusAnimeListItems($itemsToAdd, $type = 'anime')
|
||||
public function createKitsuListItems($itemsToAdd, $type = 'anime')
|
||||
{
|
||||
$requester = new ParallelAPIRequest();
|
||||
foreach($itemsToAdd as $item)
|
||||
|
39
tests/API/MAL/Transformer/AnimeListTransformerTest.php
Normal file
39
tests/API/MAL/Transformer/AnimeListTransformerTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\Tests\API\MAL\Transformer;
|
||||
|
||||
use Aviat\AnimeClient\API\MAL\Transformer\AnimeListTransformer;
|
||||
use Aviat\AnimeClient\Tests\AnimeClientTestCase;
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Json;
|
||||
|
||||
class AnimeListTransformerTest extends AnimeClientTestCase {
|
||||
|
||||
protected $transformer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->transformer = new AnimeListTransformer();
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$this->assertEquals([], $this->transformer->transform([]));
|
||||
}
|
||||
|
||||
}
|
39
tests/API/MAL/Transformer/MangaListTransformerTest.php
Normal file
39
tests/API/MAL/Transformer/MangaListTransformerTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\Tests\API\MAL\Transformer;
|
||||
|
||||
use Aviat\AnimeClient\API\MAL\Transformer\MangaListTransformer;
|
||||
use Aviat\AnimeClient\Tests\AnimeClientTestCase;
|
||||
use Aviat\Ion\Friend;
|
||||
use Aviat\Ion\Json;
|
||||
|
||||
class MangaListTransformerTest extends AnimeClientTestCase {
|
||||
|
||||
protected $transformer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->transformer = new MangaListTransformer();
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$this->assertEquals([], $this->transformer->transform([]));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user