From 4d29b4312347db1886f225736b5b37511dbd159a Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 1 Oct 2018 13:03:48 -0400 Subject: [PATCH] Fix some api mapping issues for #5 --- src/API/Anilist/ListItem.php | 8 ++++---- src/API/Anilist/Model.php | 4 ++-- src/API/HummingbirdClient.php | 2 +- src/Command/SyncLists.php | 12 +++++++----- src/Controller/Index.php | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/API/Anilist/ListItem.php b/src/API/Anilist/ListItem.php index 04172c9d..ca8d6283 100644 --- a/src/API/Anilist/ListItem.php +++ b/src/API/Anilist/ListItem.php @@ -97,19 +97,19 @@ final class ListItem implements ListItemInterface{ * @return Request */ public function update(string $id, FormItemData $data): Request - { + { $array = $data->toArray(); $notes = $data['notes'] ?? ''; $progress = array_key_exists('progress', $array) ? $data['progress'] : 0; $private = array_key_exists('private', $array) ? (bool)$data['private'] : false; - $rating = array_key_exists('rating', $array) ? $data['rating'] : NULL; + $rating = array_key_exists('ratingTwenty', $array) ? $data['ratingTwenty'] : NULL; $status = ($data['reconsuming'] === true) ? AnilistStatus::REPEATING : AnimeWatchingStatus::KITSU_TO_ANILIST[$data['status']]; - + $updateData = [ 'id' => (int)$id, 'status' => $status, - 'score' => $rating * 10, + 'score' => $rating * 5, 'progress' => $progress, 'repeat' => (int)$data['reconsumeCount'], 'private' => $private, diff --git a/src/API/Anilist/Model.php b/src/API/Anilist/Model.php index e6c9ef82..512703b7 100644 --- a/src/API/Anilist/Model.php +++ b/src/API/Anilist/Model.php @@ -89,14 +89,14 @@ final class Model throw new InvalidArgumentException('Media id missing'); } - if ($type === 'anime') + if ($type === 'ANIME') { $createData = [ 'id' => $mediaId, 'status' => AnimeWatchingStatus::KITSU_TO_ANILIST[$data['status']], ]; } - elseif ($type === 'manga') + elseif ($type === 'MANGA') { $createData = [ 'id' => $mediaId, diff --git a/src/API/HummingbirdClient.php b/src/API/HummingbirdClient.php index 430d146f..538d8aab 100644 --- a/src/API/HummingbirdClient.php +++ b/src/API/HummingbirdClient.php @@ -1,4 +1,4 @@ -sync('anime'); $this->sync('manga'); + + $this->echoBox('Finished syncing lists'); } /** @@ -363,7 +365,7 @@ final class SyncLists extends BaseCommand { 'private' => $kItem['private'], 'progress' => $kItem['progress'], 'repeat' => $kItem['reconsumeCount'], - 'score' => $kItem['ratingTwenty'] / 2, + 'score' => $kItem['ratingTwenty'] * 5, // 100 point score on Anilist 'status' => $newItemStatus, ], ]; @@ -425,7 +427,7 @@ final class SyncLists extends BaseCommand { $sameNotes = $diff['notes'] === 0; $sameStatus = $diff['status'] === 0; $sameProgress = $diff['progress'] === 0; - $sameRating = $diff['rating'] === 0; + $sameRating = $diff['ratingTwenty'] === 0; $sameRewatchCount = $diff['reconsumeCount'] === 0; // If an item is completed, make sure the 'reconsuming' flag is false @@ -497,12 +499,12 @@ final class SyncLists extends BaseCommand { { if ($kitsuItem['data']['rating'] !== 0 && $dateDiff === 1) { - $update['data']['rating'] = $kitsuItem['data']['rating']; + $update['data']['ratingTwenty'] = $kitsuItem['data']['ratingTwenty']; $return['updateType'][] = 'anilist'; } else if($dateDiff === -1) { - $update['data']['rating'] = $anilistItem['data']['rating']; + $update['data']['ratingTwenty'] = $anilistItem['data']['rating'] * 2; $return['updateType'][] = 'kitsu'; } } @@ -557,7 +559,7 @@ final class SyncLists extends BaseCommand { 'notes' => $kitsuItem['data']['notes'], 'private' => $kitsuItem['data']['private'], 'progress' => $kitsuItem['data']['progress'], - 'rating' => $kitsuItem['data']['rating'], + 'rating' => $kitsuItem['data']['ratingTwenty'] * 5, 'reconsumeCount' => $kitsuItem['data']['reconsumeCount'], 'reconsuming' => $kitsuItem['data']['reconsuming'], 'status' => $kitsuItem['data']['status'], diff --git a/src/Controller/Index.php b/src/Controller/Index.php index 58a821ad..0853fdce 100644 --- a/src/Controller/Index.php +++ b/src/Controller/Index.php @@ -201,7 +201,7 @@ final class Index extends BaseController { public function images(string $type, string $file): void { $kitsuUrl = 'https://media.kitsu.io/'; - list($id, $ext) = explode('.', basename($file)); + [$id, $ext] = explode('.', basename($file)); switch ($type) { case 'anime':