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, Request}; |
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): Request |
34
|
|
|
{ |
35
|
|
|
$id = $data['id']; |
36
|
|
|
$createData = [ |
37
|
|
|
'id' => $id, |
38
|
|
|
'data' => XML::toXML([ |
39
|
|
|
'entry' => $data['data'] |
40
|
|
|
]) |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$config = $this->container->get('config'); |
44
|
|
|
|
45
|
|
|
return $this->requestBuilder->newRequest('POST', "animelist/add/{$id}.xml") |
46
|
|
|
->setFormFields($createData) |
47
|
|
|
->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password'])) |
48
|
|
|
->getFullRequest(); |
49
|
|
|
|
50
|
|
|
/* $response = $this->getResponse('POST', "animelist/add/{$id}.xml", [ |
|
|
|
|
51
|
|
|
'body' => $this->fixBody((new FormBody)->addFields($createData)) |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
return $response->getBody() === 'Created'; */ |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function delete(string $id): Request |
58
|
|
|
{ |
59
|
|
|
$config = $this->container->get('config'); |
60
|
|
|
|
61
|
|
|
return $this->requestBuilder->newRequest('DELETE', "animelist/delete/{$id}.xml") |
62
|
|
|
->setFormFields([ |
63
|
|
|
'id' => $id |
64
|
|
|
]) |
65
|
|
|
->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password'])) |
66
|
|
|
->getFullRequest(); |
67
|
|
|
|
68
|
|
|
/*$response = $this->getResponse('DELETE', "animelist/delete/{$id}.xml", [ |
|
|
|
|
69
|
|
|
'body' => $this->fixBody((new FormBody)->addField('id', $id)) |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
return $response->getBody() === 'Deleted';*/ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function get(string $id): array |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
return []; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function update(string $id, array $data): Request |
81
|
|
|
{ |
82
|
|
|
$config = $this->container->get('config'); |
83
|
|
|
|
84
|
|
|
$xml = XML::toXML(['entry' => $data]); |
85
|
|
|
$body = (new FormBody) |
|
|
|
|
86
|
|
|
->addField('id', $id) |
87
|
|
|
->addField('data', $xml); |
88
|
|
|
|
89
|
|
|
return $this->requestBuilder->newRequest('POST', "animelist/update/{$id}.xml") |
90
|
|
|
->setFormFields([ |
91
|
|
|
'id' => $id, |
92
|
|
|
'data' => $xml |
93
|
|
|
]) |
94
|
|
|
->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password'])) |
95
|
|
|
->getFullRequest(); |
96
|
|
|
|
97
|
|
|
/* return $this->getResponse('POST', "animelist/update/{$id}.xml", [ |
|
|
|
|
98
|
|
|
'body' => $this->fixBody($body) |
99
|
|
|
]); */ |
100
|
|
|
} |
101
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.