ani-api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ani-api.rb +85 -0
  3. metadata +39 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: faeae317c72ef02ae32b46cb7db48d606c6aa6c96c23287e8d89f4c8424646fc
4
+ data.tar.gz: a679dcdb6d9933b371e8bc19bcaad237480d710ab4d5fc4b0451a17fb3806c82
5
+ SHA512:
6
+ metadata.gz: f5bd38cfe906be40c1518db42f1edec8b7cf8e9958529c9e61faa269864eea083d895e80a327dab87a41c9bf9f973c1c12e028c2fccf133202369996dfb05238
7
+ data.tar.gz: eac1dd163ce6f13763a0f1cc027980e6500a070759b2f30a29559a7d537fcc6999821100708e04d87ff44719f86b96d2c184abbaf6640b78aa4e423d14f5c9a7
data/lib/ani-api.rb ADDED
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ class AniApi
6
+ API_URI = URI("https://graphql.anilist.co/").freeze
7
+ @rate_limit = 90
8
+
9
+ attr_reader :rate_limit
10
+ def self.media(id)
11
+ query = <<~GRAPHQL
12
+ query ($id: Int) {
13
+ Media (id: $id) {
14
+ id
15
+ type
16
+ format
17
+ episodes
18
+ duration
19
+ chapters
20
+ volumes
21
+ title {
22
+ romaji
23
+ english
24
+ native
25
+ }
26
+ seasonYear
27
+ startDate {
28
+ day, month, year
29
+ }
30
+ endDate {
31
+ day, month, year
32
+ }
33
+ coverImage {
34
+ large, medium
35
+ }
36
+ }
37
+ }
38
+ GRAPHQL
39
+
40
+ response = make_request(query, { id: id })
41
+ @rate_limit = response['X-RateLimit-Remaining'].to_i
42
+
43
+ JSON.parse(response.body)["data"]["Media"]
44
+ end
45
+
46
+ def self.search(title)
47
+ query = <<~GRAPHQL
48
+ query ($search: String) {
49
+ Page (perPage: 5) {
50
+ media (search: $search) {
51
+ id
52
+ type
53
+ }
54
+ }
55
+ }
56
+ GRAPHQL
57
+
58
+ response = make_request(query, { search: title })
59
+ data = JSON.parse(response.body)["data"]["Page"]["media"]
60
+ @rate_limit = response['X-RateLimit-Remaining'].to_i
61
+
62
+ data.map { |entry| entry }
63
+ end
64
+
65
+ private
66
+
67
+ def self.make_request(query, vars)
68
+ payload = {
69
+ query: query,
70
+ variables: vars
71
+ }
72
+
73
+ http = Net::HTTP.new(API_URI.host, API_URI.port)
74
+ http.use_ssl = true
75
+
76
+ request = Net::HTTP::Post.new(API_URI.path, {'Content-Type' => 'application/json'})
77
+ request.body = payload.to_json
78
+
79
+ http.request(request)
80
+ end
81
+
82
+ def self.rate_limit_remaining
83
+ @rate_limit
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,39 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ani-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Fürst
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email: daniel@fuerst.priv.at
13
+ executables: []
14
+ extensions: []
15
+ extra_rdoc_files: []
16
+ files:
17
+ - lib/ani-api.rb
18
+ homepage: https://github.com/Daniel-Fuerst/ani-api
19
+ licenses:
20
+ - GPL-3.0
21
+ metadata: {}
22
+ rdoc_options: []
23
+ require_paths:
24
+ - lib
25
+ required_ruby_version: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ required_rubygems_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ requirements: []
36
+ rubygems_version: 3.6.9
37
+ specification_version: 4
38
+ summary: A ruby gem that handles communication with the Anilist api
39
+ test_files: []