|
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\FormBody; |
|
20
|
|
|
use Aviat\AnimeClient\API\{ |
|
21
|
|
|
AbstractListItem, |
|
22
|
|
|
XML |
|
23
|
|
|
}; |
|
24
|
|
|
use Aviat\Ion\Di\ContainerAware; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* CRUD operations for MAL list items |
|
28
|
|
|
*/ |
|
29
|
|
|
class ListItem { |
|
30
|
|
|
use ContainerAware; |
|
31
|
|
|
use MALTrait; |
|
32
|
|
|
|
|
33
|
|
|
public function create(array $data): bool |
|
34
|
|
|
{ |
|
35
|
|
|
$id = $data['id']; |
|
36
|
|
|
$createData = [ |
|
37
|
|
|
'id' => $id, |
|
38
|
|
|
'data' => XML::toXML([ |
|
39
|
|
|
'entry' => $data['data'] |
|
40
|
|
|
]) |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
$response = $this->getResponse('POST', "animelist/add/{$id}.xml", [ |
|
44
|
|
|
'body' => $this->fixBody((new FormBody)->addFields($createData)) |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
return $response->getBody() === 'Created'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function delete(string $id): bool |
|
51
|
|
|
{ |
|
52
|
|
|
$response = $this->getResponse('DELETE', "animelist/delete/{$id}.xml", [ |
|
53
|
|
|
'body' => $this->fixBody((new FormBody)->addField('id', $id)) |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
return $response->getBody() === 'Deleted'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function get(string $id): array |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function update(string $id, array $data) |
|
65
|
|
|
{ |
|
66
|
|
|
$xml = XML::toXML(['entry' => $data]); |
|
67
|
|
|
$body = (new FormBody) |
|
68
|
|
|
->addField('id', $id) |
|
69
|
|
|
->addField('data', $xml); |
|
70
|
|
|
|
|
71
|
|
|
return $this->getResponse('POST', "animelist/update/{$id}.xml", [ |
|
72
|
|
|
'body' => $this->fixBody($body) |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.