Simplify syncing script

This commit is contained in:
Timothy Warren 2018-01-10 16:34:25 -05:00
parent f205ba8cff
commit bd61bd734b
2 changed files with 22 additions and 10 deletions

View File

@ -227,6 +227,21 @@ class APIRequestBuilder {
return $this->request; return $this->request;
} }
/**
* Get the data from the response of the passed request
*
* @param Request $request
* @return mixed
* @throws \Error
* @throws \Throwable
* @throws \TypeError
*/
public function getResponseData(Request $request)
{
$response = wait((new HummingbirdClient)->request($request));
return wait($response->getBody());
}
/** /**
* Create a new http request * Create a new http request
* *

View File

@ -16,9 +16,6 @@
namespace Aviat\AnimeClient\Command; namespace Aviat\AnimeClient\Command;
use function Amp\Promise\{all, wait};
use Amp\Artax\Client;
use Aviat\AnimeClient\API\{ use Aviat\AnimeClient\API\{
FailedResponseException, FailedResponseException,
JsonAPI, JsonAPI,
@ -27,8 +24,7 @@ use Aviat\AnimeClient\API\{
Mapping\MangaReadingStatus Mapping\MangaReadingStatus
}; };
use Aviat\AnimeClient\API\MAL\Transformer\{ use Aviat\AnimeClient\API\MAL\Transformer\{
AnimeListTransformer as ALT, AnimeListTransformer as ALT
MangaListTransformer as MLT
}; };
use Aviat\Ion\Json; use Aviat\Ion\Json;
@ -78,9 +74,10 @@ class SyncKitsuWithMal extends BaseCommand {
$malCount = 0; $malCount = 0;
if ( ! empty($malList)) if ( ! empty($malList))
{ {
$malCount = (array_key_exists(0, $malList)) $malCount = count(array_key_exists(0, $malList)
? count($malList) ? $malList
: count([$malList]); : [$malList]
);
} }
try try
@ -485,7 +482,7 @@ class SyncKitsuWithMal extends BaseCommand {
$responseData = Json::decode($response); $responseData = Json::decode($response);
$id = $itemsToUpdate[$key]['mal_id']; $id = $itemsToUpdate[$key]['mal_id'];
if ( ! array_key_exists('errors', $responseData)); if ( ! array_key_exists('errors', $responseData))
{ {
$verb = ($action === 'update') ? 'updated' : 'created'; $verb = ($action === 'update') ? 'updated' : 'created';
$this->echoBox("Successfully {$verb} Kitsu {$type} list item with id: {$id}"); $this->echoBox("Successfully {$verb} Kitsu {$type} list item with id: {$id}");