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

@ -121,7 +121,7 @@ class APIRequestBuilder {
return $this->setBody($body);
}
/**
* Unset a request header
*
@ -227,6 +227,21 @@ class APIRequestBuilder {
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
*

View File

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