jikan.rb 0.0.5 → 0.0.6

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.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,14 +1,19 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "jikan"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- Pry.start
12
-
13
- # require "irb"
14
- # IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jikan"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ def reload!
14
+ files = $LOADED_FEATURES.select { |feat| feat =~ /\/jikan\// }
15
+ files.each { |file| load file }
16
+ end
17
+
18
+ # require "irb"
19
+ # IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,42 +1,43 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "jikan/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "jikan.rb"
8
- spec.version = Jikan::VERSION
9
- spec.authors = ["Zerocchi"]
10
- spec.email = ["slaveration@gmail.com"]
11
-
12
- spec.summary = %q{A simple Ruby wrapper for jikan.me API.}
13
- spec.description = %q{This is a wrapper for unofficial MyAnimeList API, Jikan.me.
14
- Consult Jikan.me documentation to learn more. }
15
- spec.homepage = "https://github.com/Zerocchi/jikan.rb"
16
- spec.license = "MIT"
17
-
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
- if spec.respond_to?(:metadata)
21
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
- else
23
- raise "RubyGems 2.0 or newer is required to protect against " \
24
- "public gem pushes."
25
- end
26
-
27
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features)/})
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.add_runtime_dependency "http", "~> 3.0.0"
35
-
36
- spec.add_development_dependency "bundler", "~> 1.16"
37
- spec.add_development_dependency "pry"
38
- spec.add_development_dependency "rake", "~> 10.0"
39
- spec.add_development_dependency "rspec", "~> 3.0"
40
- spec.add_development_dependency "vcr"
41
- spec.add_development_dependency "webmock"
42
- end
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jikan/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jikan.rb"
8
+ spec.version = Jikan::VERSION
9
+ spec.authors = ["Zerocchi"]
10
+ spec.email = ["slaveration@gmail.com"]
11
+
12
+ spec.summary = %q{A simple Ruby wrapper for jikan.me API.}
13
+ spec.description = %q{This is a wrapper for unofficial MyAnimeList API, Jikan.me.
14
+ Consult Jikan.me documentation to learn more. }
15
+ spec.homepage = "https://github.com/Zerocchi/jikan.rb"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency "http", "~> 3.0.0"
35
+ spec.add_runtime_dependency "require_all", "~> 2.0.0"
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.16"
38
+ spec.add_development_dependency "pry"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "vcr"
42
+ spec.add_development_dependency "webmock"
43
+ end
@@ -1,38 +1,55 @@
1
- require 'jikan/query'
2
-
3
- module Jikan
4
- class FlagError < StandardError; end
5
- class ClientError < StandardError; end
6
-
7
- BASE_URL = "http://api.jikan.moe"
8
- BASE_URL_SSL = "https://api.jikan.moe"
9
-
10
- FLAGS = {
11
- 'anime' => [ :episodes, :characters_staff, :news, :pictures, :videos, :stats ],
12
- 'manga' => [ :character, :news, :pictures, :stats ],
13
- 'character' => [ :pictures ],
14
- 'person' => [ :pictures ],
15
- 'search' => [:anime, :manga, :person, :character]
16
- }
17
-
18
- # shortcut methods
19
- def self.anime(id, flag=nil)
20
- Jikan::Query.new.anime_id(id, flag)
21
- end
22
-
23
- def self.manga(id, flag=nil)
24
- Jikan::Query.new.manga_id(id, flag)
25
- end
26
-
27
- def self.character(id, flag=nil)
28
- Jikan::Query.new.character_id(id, flag)
29
- end
30
-
31
- def self.person(id, flag=nil)
32
- Jikan::Query.new.person_id(id, flag)
33
- end
34
-
35
- def self.search(query, flag=:anime, page=1)
36
- Jikan::Query.new.search(query, flag, page)
37
- end
38
- end
1
+ require 'jikan/query'
2
+
3
+ module Jikan
4
+ class FlagError < StandardError; end
5
+ class ClientError < StandardError; end
6
+
7
+ BASE_URL = "http://api.jikan.moe"
8
+ BASE_URL_SSL = "https://api.jikan.moe"
9
+ BASE_URL_V3 = "http://api.jikan.moe/v3"
10
+ BASE_URL_V3_SSL = "https://api.jikan.moe/v3"
11
+
12
+ FLAGS = {
13
+ 'anime' => [ :episodes, :characters_staff, :news, :pictures, :videos, :stats, :reviews, :recommendations, :userupdates ],
14
+ 'manga' => [ :character, :news, :pictures, :stats, :reviews, :recommendations, :userupdates ],
15
+ 'character' => [ :pictures ],
16
+ 'person' => [ :pictures ],
17
+ 'search' => [:anime, :manga, :person, :character],
18
+ 'season' => [:summer, :spring, :fall, :winter, :later],
19
+ 'user' => [:profile, :history, :friends, :animelist, :mangalist],
20
+ 'club' => [:members]
21
+ }
22
+
23
+ # shortcut methods
24
+ def self.anime(id, flag=nil)
25
+ Jikan::Query.new.anime_id(id, flag)
26
+ end
27
+
28
+ def self.manga(id, flag=nil)
29
+ Jikan::Query.new.manga_id(id, flag)
30
+ end
31
+
32
+ def self.character(id, flag=nil)
33
+ Jikan::Query.new.character_id(id, flag)
34
+ end
35
+
36
+ def self.person(id, flag=nil)
37
+ Jikan::Query.new.person_id(id, flag)
38
+ end
39
+
40
+ def self.search(query, flag=:anime, page=1)
41
+ Jikan::Query.new.search(query, flag, page)
42
+ end
43
+
44
+ def self.season(season, year)
45
+ Jikan::Query.new.season(season, year)
46
+ end
47
+
48
+ def self.club(id, flag=nil)
49
+ Jikan::Query.new.club(id, flag)
50
+ end
51
+
52
+ def self.user(name, flag=nil)
53
+ Jikan::Query.new.user(name, flag)
54
+ end
55
+ end
@@ -1,60 +1,66 @@
1
- require "http"
2
- require "json"
3
-
4
- module Jikan
5
- class API
6
-
7
- def initialize(use_ssl=true)
8
- @endpoint = ""
9
- @id = nil
10
- @flag = nil
11
- @selected_base = if use_ssl then Jikan::BASE_URL_SSL else Jikan::BASE_URL end
12
- end
13
-
14
- def get(endpoint, id, flag=nil, qry='')
15
- @endpoint = endpoint
16
- @id = id
17
- @flag = flag
18
- @query = qry
19
-
20
- construct_url
21
- get_data
22
- end
23
-
24
- private
25
-
26
- def construct_url
27
- @end_url = "#{@selected_base}/#{@endpoint}"
28
- @url = "#{@end_url}/#{@id}"
29
-
30
- if @endpoint.eql?('search')
31
- unless Jikan::FLAGS[@endpoint].include? @flag
32
- raise Jikan::FlagError, 'Flag not supported'
33
- else
34
- # This is inconsistencies in the API.
35
- if @flag == :anime || @flag == :manga
36
- @url = "#{@end_url}/#{@flag.to_s}/#{@query.downcase.delete(' ')}/#{@id}"
37
- elsif @flag == :character || @flag == :person
38
- @url = "#{@end_url}/#{@flag.to_s}/#{@query.downcase.gsub!(' ', '_')}/#{@id}"
39
- end
40
- end
41
- end
42
-
43
- unless @flag.nil? || @endpoint.eql?('search')
44
- unless Jikan::FLAGS[@endpoint].include? @flag
45
- raise Jikan::FlagError, 'Flag not supported'
46
- end
47
- @url << "/#{@flag.to_s}"
48
- end
49
- end
50
-
51
- def get_data
52
- res = HTTP.get(@url)
53
- if res.status >= 400
54
- raise ClientError, "#{res.status}: error on endpoint #{@endpoint} (URL: #{@url})"
55
- end
56
-
57
- JSON.parse(res.body)
58
- end
59
- end
1
+ require "http"
2
+ require "json"
3
+ require "uri"
4
+
5
+ module Jikan
6
+ class API
7
+
8
+ def initialize(use_ssl=true)
9
+ @endpoint = ""
10
+ @id = nil
11
+ @flag = nil
12
+ @year = nil
13
+ @page = nil
14
+ @query = nil
15
+ @selected_base = if use_ssl then Jikan::BASE_URL_V3_SSL else Jikan::BASE_URL_v3 end
16
+ end
17
+
18
+ def get(endpoint:, flag: nil, id: 0, query: nil, year: Date.today.year, page: 1)
19
+ @endpoint = endpoint
20
+ @id = id
21
+ @flag = flag
22
+ @query = query
23
+ @year = year
24
+ @page = page
25
+
26
+ construct_url
27
+ get_data
28
+ end
29
+
30
+ private
31
+
32
+ def construct_url
33
+ @end_url = "#{@selected_base}/#{@endpoint}"
34
+
35
+ unless @flag.nil? || Jikan::FLAGS[@endpoint].include?(@flag)
36
+ raise Jikan::FlagError, 'Flag not supported'
37
+ end
38
+
39
+ if @endpoint.eql?('season')
40
+ if @flag.eql?(:later)
41
+ @url = URI.encode("#{@end_url}/#{@flag}")
42
+ elsif
43
+ @url = URI.encode("#{@end_url}/#{@year}/#{@flag}")
44
+ end
45
+ elsif @endpoint.eql?('search')
46
+ @url = URI.encode("#{@end_url}/#{@flag.to_s}?q=#{@query}&page=#{@page}")
47
+ elsif @endpoint.eql?('user')
48
+ @url = URI.encode("#{@end_url}/#{@query}/#{@flag.to_s}")
49
+ else
50
+ @url = "#{@end_url}/#{@id}"
51
+ unless @flag.nil?
52
+ @url << "/#{@flag.to_s}"
53
+ end
54
+ end
55
+ end
56
+
57
+ def get_data
58
+ res = HTTP.get(@url)
59
+ if res.status >= 400
60
+ raise ClientError, "#{res.status}: error on endpoint #{@endpoint} (URL: #{@url})"
61
+ end
62
+
63
+ JSON.parse(res.body)
64
+ end
65
+ end
60
66
  end
@@ -1,72 +1,74 @@
1
- require 'jikan/entity'
2
-
3
- module Jikan
4
- class Anime < MediaEntity
5
-
6
- def aired
7
- raw['aired']
8
- end
9
-
10
- def adaptation
11
- raw['related']['adaptation']
12
- end
13
-
14
- def background
15
- raw['background']
16
- end
17
-
18
- def broadcast
19
- raw['broadcast']
20
- end
21
-
22
- def duration
23
- raw['duration']
24
- end
25
-
26
- def ending
27
- raw['ending_theme']
28
- end
29
-
30
- def episodes
31
- raw['episodes']
32
- end
33
-
34
- def eps_list
35
- raw['episode']
36
- end
37
-
38
- def licensor
39
- raw['licensor']
40
- end
41
-
42
- def opening
43
- raw['opening_theme']
44
- end
45
-
46
- def premiered
47
- raw['premiered']
48
- end
49
-
50
- def producer
51
- raw['producer']
52
- end
53
-
54
- def related
55
- raw['related']
56
- end
57
-
58
- def side_story
59
- raw['side_story']
60
- end
61
-
62
- def studio
63
- raw['studio']
64
- end
65
- end
66
-
67
- class AnimeResult < Anime
68
- def details(flag=nil)
69
- Jikan::anime id, flag
70
- end
71
- end
72
- end
1
+ require 'jikan/models/entity'
2
+
3
+ module Jikan
4
+ class Anime < MediaEntity
5
+
6
+ def aired
7
+ raw['aired']
8
+ end
9
+
10
+ def adaptation
11
+ raw['related']['adaptation']
12
+ end
13
+
14
+ def background
15
+ raw['background']
16
+ end
17
+
18
+ def broadcast
19
+ raw['broadcast']
20
+ end
21
+
22
+ def duration
23
+ raw['duration']
24
+ end
25
+
26
+ def ending
27
+ raw['ending_theme'] || raw['ending_themes']
28
+ end
29
+
30
+ def episodes
31
+ raw['episodes']
32
+ end
33
+
34
+ def eps_list
35
+ raw['episode'] || raw['episodes']
36
+ end
37
+
38
+ def licensor
39
+ raw['licensor'] || raw['licensors']
40
+ end
41
+
42
+ def opening
43
+ raw['opening_theme'] || raw['opening_themes']
44
+ end
45
+
46
+ def premiered
47
+ raw['premiered']
48
+ end
49
+
50
+ def producer
51
+ raw['producer'] || raw['producers']
52
+ end
53
+
54
+ def related
55
+ raw['related']
56
+ end
57
+
58
+ def side_story
59
+ raw['side_story']
60
+ end
61
+
62
+ def studio
63
+ raw['studio'] || raw['studios']
64
+ end
65
+ end
66
+
67
+ class AnimeResult < Anime
68
+ def details(flag=nil)
69
+ Jikan::anime id, flag
70
+ end
71
+ end
72
+
73
+ class BasicAnime < Entityography; end
74
+ end