summaryrefslogtreecommitdiff
path: root/app/Anime.php
diff options
context:
space:
mode:
authorhorus2020-03-19 02:56:04 +0100
committerhorus2020-03-19 02:56:04 +0100
commit9436a3cd81d593de15653840ce4f69cee5cb573f (patch)
tree813fb2494ee6b6b59dde7dc6ee206a83d9cd10c7 /app/Anime.php
parent6ee98957635ec027fc98382befb9fd154d88889e (diff)
downloadsenpai-9436a3cd81d593de15653840ce4f69cee5cb573f.tar.gz
Add more data from anilist, namely synopsis, official hashtag and user preferred title.
Diffstat (limited to 'app/Anime.php')
-rw-r--r--app/Anime.php35
1 files changed, 35 insertions, 0 deletions
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;
+
+ }
}