From 9436a3cd81d593de15653840ce4f69cee5cb573f Mon Sep 17 00:00:00 2001 From: horus Date: Thu, 19 Mar 2020 02:56:04 +0100 Subject: Add more data from anilist, namely synopsis, official hashtag and user preferred title. --- app/Anime.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/Anime.php') diff --git a/app/Anime.php b/app/Anime.php index 5fd4db3..76eca09 100644 --- a/app/Anime.php +++ b/app/Anime.php @@ -126,4 +126,39 @@ class Anime extends Model { return $data; } + public function getEnhancementFromAnilist() { + + $query = ' + query($id: Int!) { + Media(idMal: $id, type: ANIME) { + title { + userPreferred + } + description + hashtag + } + } + '; + $variables = [ + "id" => $this->mal_id, + ]; + + // Make the HTTP Api request + try { + $http = new \GuzzleHttp\Client; + $response = $http->post('https://graphql.anilist.co', [ + 'json' => [ + 'query' => $query, + 'variables' => $variables, + ] + ]); + + $data = json_decode( $response->getBody() )->data->Media; + } catch (\Exception $e) { + echo "Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n"; + return ""; + } + return $data; + + } } -- cgit v1.2.3