Skip to content

Commit

Permalink
add anime/manga approval state
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan-dahir committed Jun 27, 2022
1 parent 1651002 commit be4bc57
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Model/Anime/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Anime
*/
private $titleSynonyms;

/**
* @var bool
*/
private $approved;

/**
* @var string|null
*/
Expand Down Expand Up @@ -218,6 +223,7 @@ public static function fromParser(AnimeParser $parser): Anime
$instance->title = $parser->getTitle();
$instance->url = $parser->getURL();
$instance->malId = $parser->getId();
$instance->approved = $parser->getApproved();
$instance->images = CommonImageResource::factory($parser->getImageURL());
$instance->synopsis = $parser->getSynopsis();
$instance->titleEnglish = $parser->getTitleEnglish();
Expand Down Expand Up @@ -255,6 +261,14 @@ public static function fromParser(AnimeParser $parser): Anime
return $instance;
}

/**
* @return bool
*/
public function isApproved(): bool
{
return $this->approved;
}

/**
* @return MalUrl[]
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Model/Manga/Manga.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class Manga
*/
private $titleSynonyms;

/**
* @var bool
*/
private $approved;

/**
* @var string|null
*/
Expand Down Expand Up @@ -184,6 +189,7 @@ public static function fromParser(MangaParser $parser): Manga
$instance->title = $parser->getMangaTitle();
$instance->url = $parser->getMangaURL();
$instance->malId = $parser->getMangaId();
$instance->approved = $parser->getApproved();
$instance->images = CommonImageResource::factory($parser->getMangaImageURL());
$instance->synopsis = $parser->getMangaSynopsis();
$instance->titleEnglish = $parser->getMangaTitleEnglish();
Expand Down Expand Up @@ -214,6 +220,14 @@ public static function fromParser(MangaParser $parser): Manga
return $instance;
}

/**
* @return bool
*/
public function isApproved(): bool
{
return $this->approved;
}

/**
* @return MalUrl[]
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Parser/Anime/AnimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public function getSynopsis(): ?string
return preg_match('~^Looking for information on the anime~', $synopsis) ? null : $synopsis;
}

/**
* @return bool
*/
public function getApproved(): bool
{
$node = $this->crawler->filterXPath('//*[@id="addtolist"]/span[contains(text(), "pending approval")]');

if ($node->count()) {
return false;
}

return true;
}

/**
* @return string|null
* @throws \InvalidArgumentException
Expand Down
14 changes: 14 additions & 0 deletions src/Parser/Manga/MangaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public function getMangaSynopsis(): ?string
return preg_match('~^Looking for information on the manga~', $synopsis) ? null : $synopsis;
}

/**
* @return bool
*/
public function getApproved(): bool
{
$node = $this->crawler->filterXPath('//*[@id="addtolist"]//span[contains(text(), "pending approval")]');

if ($node->count()) {
return false;
}

return true;
}

/**
* @return string|null
* @throws \InvalidArgumentException
Expand Down
18 changes: 18 additions & 0 deletions test/JikanTest/JikanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function it_gets_anime()
self::assertInstanceOf(\Jikan\Model\Anime\Anime::class, $anime);
}

/**
* @test
*/
public function it_gets_unapproved_anime()
{
$anime = $this->jikan->getAnime(new \Jikan\Request\Anime\AnimeRequest(48104));
self::assertEquals(false, $anime->isApproved());
}

/**
* @test
*/
Expand All @@ -53,6 +62,15 @@ public function it_gets_manga()
self::assertInstanceOf(\Jikan\Model\Manga\Manga::class, $manga);
}

/**
* @test
*/
public function it_gets_unapproved_manga()
{
$manga = $this->jikan->getManga(new \Jikan\Request\Manga\MangaRequest(145036));
self::assertEquals(false, $manga->isApproved());
}

/**
* @test
*/
Expand Down

0 comments on commit be4bc57

Please sign in to comment.