1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* Anime List Client |
4
|
|
|
* |
5
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists |
6
|
|
|
* |
7
|
|
|
* PHP version 7 |
8
|
|
|
* |
9
|
|
|
* @package AnimeListClient |
10
|
|
|
* @author Timothy J. Warren <[email protected]> |
11
|
|
|
* @copyright 2015 - 2017 Timothy J. Warren |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
13
|
|
|
* @version 4.0 |
14
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Aviat\AnimeClient\API\MAL; |
18
|
|
|
|
19
|
|
|
use Amp\Artax\Request; |
20
|
|
|
use Aviat\AnimeClient\API\MAL as M; |
21
|
|
|
use Aviat\AnimeClient\API\MAL\ListItem; |
22
|
|
|
use Aviat\AnimeClient\API\MAL\Transformer\AnimeListTransformer; |
23
|
|
|
use Aviat\AnimeClient\API\XML; |
24
|
|
|
use Aviat\Ion\Di\ContainerAware; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* MyAnimeList API Model |
28
|
|
|
*/ |
29
|
|
|
class Model { |
30
|
|
|
use ContainerAware; |
31
|
|
|
use MALTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var AnimeListTransformer |
35
|
|
|
*/ |
36
|
|
|
protected $animeListTransformer; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* KitsuModel constructor. |
40
|
|
|
*/ |
41
|
|
|
public function __construct(ListItem $listItem) |
42
|
|
|
{ |
43
|
|
|
$this->animeListTransformer = new AnimeListTransformer(); |
44
|
|
|
$this->listItem = $listItem; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function createListItem(array $data): Request |
48
|
|
|
{ |
49
|
|
|
$createData = [ |
50
|
|
|
'id' => $data['id'], |
51
|
|
|
'data' => [ |
52
|
|
|
'status' => M::KITSU_MAL_WATCHING_STATUS_MAP[$data['status']] |
53
|
|
|
] |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
return $this->listItem->create($createData); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getFullList(): array |
60
|
|
|
{ |
61
|
|
|
$config = $this->container->get('config'); |
62
|
|
|
$userName = $config->get(['mal', 'username']); |
63
|
|
|
$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [ |
64
|
|
|
'headers' => [ |
65
|
|
|
'Accept' => 'text/xml' |
66
|
|
|
], |
67
|
|
|
'query' => [ |
68
|
|
|
'u' => $userName, |
69
|
|
|
'status' => 'all' |
70
|
|
|
] |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
return $list;//['anime']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getListItem(string $listId): array |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
return []; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function updateListItem(array $data): Request |
82
|
|
|
{ |
83
|
|
|
$updateData = $this->animeListTransformer->untransform($data); |
84
|
|
|
return $this->listItem->update($updateData['id'], $updateData['data']); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function deleteListItem(string $id): Request |
88
|
|
|
{ |
89
|
|
|
return $this->listItem->delete($id); |
90
|
|
|
} |
91
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: