Merge remote-tracking branch 'origin/develop'

This commit is contained in:
Timothy Warren 2017-04-03 16:53:25 -04:00
commit d435438b20
7 changed files with 94 additions and 72 deletions

View File

@ -11,7 +11,8 @@
<section class="media-wrap"> <section class="media-wrap">
<?php foreach($items as $item): ?> <?php foreach($items as $item): ?>
<article class="media" id="a-<?= $item['hummingbird_id'] ?>"> <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"> <div class="name">
<a href="<?= $url->generate('anime.details', ['id' => $item['slug']]) ?>"> <a href="<?= $url->generate('anime.details', ['id' => $item['slug']]) ?>">
<?= $item['title'] ?> <?= $item['title'] ?>

View File

@ -57,7 +57,7 @@ class JsonAPI {
$included = static::organizeIncluded($data['included']); $included = static::organizeIncluded($data['included']);
// Inline organized data // Inline organized data
foreach($data['data'] as $i => $item) foreach($data['data'] as $i => &$item)
{ {
if (array_key_exists('relationships', $item)) if (array_key_exists('relationships', $item))
{ {
@ -66,11 +66,11 @@ class JsonAPI {
if (array_keys($props) === ['links']) 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; continue;
@ -78,18 +78,18 @@ class JsonAPI {
if (array_key_exists('links', $props)) 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 (array_key_exists('data', $props))
{ {
if (empty($props['data'])) 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; continue;
@ -99,7 +99,7 @@ class JsonAPI {
{ {
$idKey = $props['data']['id']; $idKey = $props['data']['id'];
$typeKey = $props['data']['type']; $typeKey = $props['data']['type'];
$relationship =& $data['data'][$i]['relationships'][$relType]; $relationship =& $item['relationships'][$relType];
unset($relationship['data']); unset($relationship['data']);
if (in_array($relType, $singular)) if (in_array($relType, $singular))
@ -123,7 +123,7 @@ class JsonAPI {
{ {
$idKey = $props['data'][$j]['id']; $idKey = $props['data'][$j]['id'];
$typeKey = $props['data'][$j]['type']; $typeKey = $props['data'][$j]['type'];
$relationship =& $data['data'][$i]['relationships'][$relType]; $relationship =& $item['relationships'][$relType];
unset($relationship['data'][$j]); unset($relationship['data'][$j]);
@ -235,16 +235,6 @@ class JsonAPI {
return $organized; 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 * Take organized includes and inline them, where applicable
* *
@ -305,17 +295,6 @@ class JsonAPI {
return $organized; 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 * Reorganize relationship mappings to make them simpler to use
* *
@ -349,30 +328,4 @@ class JsonAPI {
return $organized; 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;
}
} }

View File

@ -16,12 +16,7 @@
namespace Aviat\AnimeClient\API\Mapping; namespace Aviat\AnimeClient\API\Mapping;
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{ use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{Kitsu, MAL, Route, Title};
Kitsu,
MAL,
Route,
Title
};
use Aviat\Ion\Enum; use Aviat\Ion\Enum;
/** /**

View File

@ -16,12 +16,7 @@
namespace Aviat\AnimeClient\API\Mapping; namespace Aviat\AnimeClient\API\Mapping;
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{ use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{Kitsu, MAL, Title, Route};
Kitsu,
MAL,
Title,
Route
};
use Aviat\Ion\Enum; use Aviat\Ion\Enum;
/** /**

View File

@ -90,7 +90,7 @@ class SyncKitsuWithMal extends BaseCommand {
if ( ! empty($data['addToKitsu'])) if ( ! empty($data['addToKitsu']))
{ {
$this->echoBox("Adding missing anime list items to Kitsu"); $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(); $requester = new ParallelAPIRequest();
foreach($itemsToAdd as $item) foreach($itemsToAdd as $item)

View 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([]));
}
}

View 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([]));
}
}