Commit 5ef0ccf9 by Timothy J Warren

Some minor refactoring

parent 90f81fdf
Pipeline #298 passed with stage
in 7 minutes 43 seconds
......@@ -67,6 +67,13 @@ class Model {
return $this->listItem->create($data, $type);
}
/**
* Create a list item on MAL from a Kitsu list item
*
* @param array $data
* @param string $type "anime" or "manga"
* @return Request
*/
public function createListItem(array $data, string $type = 'anime'): Request
{
if ($type === 'anime')
......@@ -91,21 +98,50 @@ class Model {
return $this->listItem->create($createData, $type);
}
public function getMangaList(): array
/**
* Get list info
*
* @param string $type "anime" or "manga"
* @return array
*/
public function getList(string $type): array
{
return $this->getList('manga');
}
$config = $this->container->get('config');
$userName = $config->get(['mal', 'username']);
$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
'headers' => [
'Accept' => 'text/xml'
],
'query' => [
'u' => $userName,
'status' => 'all',
'type' => $type
]
]);
public function getAnimeList(): array
{
return $this->getList('anime');
return $list['myanimelist'][$type] ?? [];
}
/**
* Retrieve a list item
*
* Does not apply to MAL
*
* @param string $listId
* @return array
*/
public function getListItem(string $listId): array
{
return [];
}
/**
* Update a list item
*
* @param array $data
* @param string $type "anime" or "manga"
* @return Request
*/
public function updateListItem(array $data, string $type = 'anime'): Request
{
if ($type === 'anime')
......@@ -120,26 +156,15 @@ class Model {
return $this->listItem->update($updateData['id'], $updateData['data'], $type);
}
/**
* Delete a list item
*
* @param string $id
* @param string $type "anime" or "manga"
* @return Request
*/
public function deleteListItem(string $id, string $type = 'anime'): Request
{
return $this->listItem->delete($id, $type);
}
private function getList(string $type): array
{
$config = $this->container->get('config');
$userName = $config->get(['mal', 'username']);
$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
'headers' => [
'Accept' => 'text/xml'
],
'query' => [
'u' => $userName,
'status' => 'all',
'type' => $type
]
]);
return $list['myanimelist'][$type];
}
}
\ No newline at end of file
......@@ -70,7 +70,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function sync(string $type)
{
$uType = ucfirst($type);
$malCount = count($this->malModel->{"get{$uType}List"}());
$malCount = count($this->malModel->getList($type));
$kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}();
$this->echoBox("Number of MAL {$type} list items: {$malCount}");
......@@ -138,7 +138,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function formatMALAnimeList()
{
$orig = $this->malModel->getAnimeList();
$orig = $this->malModel->getList('anime');
$output = [];
foreach($orig as $item)
......@@ -162,7 +162,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function formatMALMangaList()
{
$orig = $this->malModel->getMangaList();
$orig = $this->malModel->getList('manga');
$output = [];
foreach($orig as $item)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment