jikan.rb 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '098873c3d87b219dd5c77c292913347ec28d5780ac5bf46e41674e84a58e5909'
4
- data.tar.gz: 257119827597b7ffa12b8db033a24c5941ad6d3288c63b7966be0d49ce3eb545
3
+ metadata.gz: bae09e79312c387a9c47086ef0dee5abfbdcf30b5a64a3f1a30912f7ef879d4f
4
+ data.tar.gz: 5b59b649df57bc6eb1901fff87d9fed194fdab9380bae9fec5f3c1d74f71b480
5
5
  SHA512:
6
- metadata.gz: 66e2efa11330d262d301f2782fae6f1ebab30b9eaa0c8bae4ce45dc54cccdaa348decec9e8c79c1d23e3379acb5eee4c4c2dee61b6d5b374be00ecade8a69190
7
- data.tar.gz: a557f123bdc392f1f3509e0a5b3a4966b3ab8c26187ea350a79701e9ecca9bfbee24314fe6c6bf0512bbfeae670c0e78ccc397152fd9c5b1cf4f094858fadd18
6
+ metadata.gz: d5ab097f9f58bfb558c3d62251e0697e64a07969be2a1cfaef8d7d1b5a1a285e5e54bef9f7a2c9fa88d7558d7c3ec307ef2af8ea905672eff202e7f46e0f73b4
7
+ data.tar.gz: 85f55c4e65258b4e6f341220553c680120995db31617d8a5af9226c5d9a1d4ec726fcfc5c79fad76d61bbd511c7285a0a5bc7158c47e5d0511c674d6b0dadac9
@@ -2,4 +2,4 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
- before_install: gem install bundler -v 1.16.1
5
+ before_install: gem install bundler
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jikan (0.0.1)
4
+ jikan.rb (0.0.1)
5
5
  http (~> 3.0.0)
6
6
 
7
7
  GEM
@@ -59,7 +59,7 @@ PLATFORMS
59
59
 
60
60
  DEPENDENCIES
61
61
  bundler (~> 1.16)
62
- jikan!
62
+ jikan.rb!
63
63
  pry
64
64
  rake (~> 10.0)
65
65
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Jikan.rb
2
2
 
3
+ [![Build Status](https://img.shields.io/travis/Zerocchi/jikan.rb.svg)](https://github.com/Zerocchi/jikan.rb/tree/master) [![Gem Version](https://img.shields.io/gem/v/jikan.rb.svg)](https://rubygems.org/gems/jikan.rb) [![Total Downloads](https://img.shields.io/gem/dt/jikan.rb.svg?colorB=6495ed)](https://rubygems.org/gems/jikan.rb) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php) [![Dart](https://img.shields.io/badge/language-Ruby-red.svg)](https://www.ruby-lang.org/)
4
+
3
5
  This is a thin Ruby wrapper for [jikan.me](http://jikan.me) inspired by [JikanPy](https://github.com/AWConant/jikanpy). For more information, please refer to [Jikan.ME documentation](https://jikan.me/docs).
4
6
 
5
7
  ## Installation
6
8
 
7
- **NOTE: This does not work yet until the gem is uploaded.**
8
-
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'jikan'
12
+ gem 'jikan.rb'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -18,19 +18,26 @@ And then execute:
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install jikan
21
+ $ gem install jikan.rb
22
22
 
23
23
  ## Usage
24
24
 
25
+ ```diff
26
+ - NOTE: As per documentation there's a rate limit of 2000 requests per IP per day, and two concurrent requests
27
+ - per second. This wrapper does not have any attempt of blocking the limit so please use it wisely.
28
+ - More information available at https://jikan.docs.apiary.io/#introduction/information
29
+ ```
30
+
25
31
  **Get anime and manga information based on their ID**
26
32
 
27
33
  ```ruby
28
34
  # https://myanimelist.net/anime/34798/Yuru_Camp
29
35
  >> qry = Jikan::Query.new
30
- => #<Jikan::Query:0x026ed9d0>
36
+ => <Jikan::Query:0x026ed9d0>
31
37
 
32
38
  >> yurucamp = qry.anime_id 34798 # manga_id for manga
33
- # You can also specify flag as second parameter
39
+ >> yurucamp = Jikan::anime 34798 # shortcut method without instaniating Query object, both are valid
40
+ # You can also specify flag as second parameter to get more information
34
41
  # >> yurucamp = qry.anime_id 34798, :episodes
35
42
  # All flags are symbol, please refer https://jikan.me/docs#chaining-methods to see all available flags
36
43
  => <Jikan::Anime:0x0168c4e0>
@@ -58,12 +65,12 @@ Or install it yourself as:
58
65
  ```ruby
59
66
  # https://myanimelist.net/character/16521/Kagome_Ikaruga
60
67
  >> qry = Jikan::Query.new
61
- => #<Jikan::Query:0x027554b8>
68
+ => <Jikan::Query:0x027554b8>
62
69
 
63
70
  >> ikaruga = qry.character_id 16521
64
- => #<Jikan::Character:0x0134b080>
71
+ => <Jikan::Character:0x0134b080>
65
72
 
66
- >> ikaruga.raw # only raw method is available for now for both character and people
73
+ >> ikaruga.raw # only raw method is available for now for both character and person
67
74
  =>{
68
75
  "mal_id"=>16521,
69
76
  "link_canonical"=>"https://myanimelist.net/character/16521/Kagome_Ikaruga",
@@ -79,12 +86,12 @@ Or install it yourself as:
79
86
  **Search**
80
87
  ``` ruby
81
88
  >> qry = Jikan::Query.new
82
- => #<Jikan::Query:0x027d70e8>
89
+ => <Jikan::Query:0x027d70e8>
83
90
 
84
- >> railgun = qry.search("railgun", :anime) # other parameter tokens are :manga, :character, :person
85
- => #<Jikan::Search:0x016fd760>
91
+ >> railgun = qry.search("railgun", :anime) # other flags are :manga, :character, :person
92
+ => <Jikan::Search:0x016fd760>
86
93
 
87
- >> railgun.raw # only raw method is available for now
94
+ >> railgun.raw # return raw result
88
95
  =>{"result"=>
89
96
  [
90
97
  {
@@ -105,6 +112,42 @@ Or install it yourself as:
105
112
  }
106
113
  ]
107
114
  }
115
+
116
+ # Return each result items wrapped in their respective object
117
+ # :person and :character only return raw objects for now so this method isn't available for those flags
118
+ >> res = railgun.result
119
+ => [<Jikan::Anime:0x0196c968>, <Jikan::Anime:0x0196c950>, <Jikan::Anime:0x019f1610>, <Jikan::Anime:0x019f15f8>, ...]
120
+
121
+ >> first_anime = res[0]
122
+ => <Jikan::Anime:0x0196c968>
123
+
124
+ >> first_anime.title
125
+ => "Toaru Kagaku no Railgun"
126
+
127
+ # Method name follow Jikan::Anime object so it will slighly differ from raw result keys
128
+ # e.g. raw result key is image_url but Jikan::Anime method is image.
129
+ >> first_anime.image
130
+ => "https://myanimelist.cdn-dena.com/r/100x140/images/anime/8/53581.jpg?s=4003b92ef0e723389087b69a8a08d742"
131
+
132
+ >> first_anime.synopsis # same goes to description which is truncated in search result. We use synopsis method instead.
133
+ => "The student-filled Academy City is at the forefront of scientific advancement and home to the esper
134
+ development program. The seven \"Level 5\" espers are the most powerful in Academy City, and ranked th..."
135
+
136
+ # Eventhough the result method return specific objects array, it is still bound to the raw result above.
137
+ # So you don't get full information the same way when you do Jikan::anime(id)
138
+ >> first_anime.opening # this will return nil because search result doesn't have opening information
139
+ => nil
140
+
141
+ # To get detailed anime information you can assign special details method on search result object.
142
+ # This method will call Jikan::Anime(id) or equivalent and get detailed information from the API and return new object.
143
+ # You can also pass flag as you would do in normal Query or shortcut methods.
144
+ >> full_info = first_anime.details
145
+ => <Jikan::Anime:0x01ad4170>
146
+
147
+ >> full_info.opening
148
+ >> first_anime.details.opening # shorter way but this will call the API again if you change the rightmost method
149
+ => ["#1: \"only my railgun\" by fripSide (eps 2-14)", "#2: \"LEVEL 5 -judgelight-\" by fripSide (eps 15-23)"]
150
+
108
151
  ```
109
152
 
110
153
  ## To-Do
@@ -14,4 +14,25 @@ module Jikan
14
14
  'person' => [ :pictures ],
15
15
  'search' => [:anime, :manga, :person, :character]
16
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
17
38
  end
@@ -24,7 +24,7 @@ module Jikan
24
24
  end
25
25
 
26
26
  def ending
27
- raw['ending-theme']
27
+ raw['ending_theme']
28
28
  end
29
29
 
30
30
  def episodes
@@ -35,12 +35,20 @@ module Jikan
35
35
  raw['episode']
36
36
  end
37
37
 
38
+ def details(flag=nil)
39
+ unless raw.has_key?('opening') || raw.has_key?('studio')
40
+ Jikan::anime id, flag
41
+ else
42
+ raise NoMethodError, "Method only available for Anime object within Jikan::Search results."
43
+ end
44
+ end
45
+
38
46
  def licensor
39
47
  raw['licensor']
40
48
  end
41
49
 
42
50
  def opening
43
- raw['opening-theme']
51
+ raw['opening_theme']
44
52
  end
45
53
 
46
54
  def premiered
@@ -31,7 +31,12 @@ module Jikan
31
31
  unless Jikan::FLAGS[@endpoint].include? @flag
32
32
  raise Jikan::FlagError, 'Flag not supported'
33
33
  else
34
- @url = "#{@end_url}/#{@flag.to_s}/#{@query}/#{@id}"
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}/#{@id}"
39
+ end
35
40
  end
36
41
  end
37
42
 
@@ -46,7 +51,7 @@ module Jikan
46
51
  def get_data
47
52
  res = HTTP.get(@url)
48
53
  if res.status >= 400
49
- raise ClientError, "#{res.status}: error on endpoint #{@endpoint}"
54
+ raise ClientError, "#{res.status}: error on endpoint #{@endpoint} (URL: #{@url})"
50
55
  end
51
56
 
52
57
  JSON.parse(res.body)
@@ -19,8 +19,12 @@ module Jikan
19
19
  raw['genre']
20
20
  end
21
21
 
22
+ def id
23
+ raw['id'] || raw['mal_id']
24
+ end
25
+
22
26
  def image
23
- raw['image']
27
+ raw['image'] || raw['image_url']
24
28
  end
25
29
 
26
30
  def members
@@ -56,11 +60,11 @@ module Jikan
56
60
  end
57
61
 
58
62
  def synopsis
59
- raw['synopsis']
63
+ raw['synopsis'] || raw['description']
60
64
  end
61
65
 
62
66
  def link
63
- raw['link_canonical']
67
+ raw['link_canonical'] || raw['url']
64
68
  end
65
69
 
66
70
  def title
@@ -9,6 +9,14 @@ module Jikan
9
9
  raw['chapters']
10
10
  end
11
11
 
12
+ def details(flag=nil)
13
+ unless raw.has_key?('published') || raw.has_key?('popularity')
14
+ Jikan::manga id, flag
15
+ else
16
+ raise NoMethodError, "Method only available for Manga object within Jikan::Search results."
17
+ end
18
+ end
19
+
12
20
  def published
13
21
  raw['published']
14
22
  end
@@ -34,7 +34,7 @@ module Jikan
34
34
 
35
35
  def search(title, type=:anime, page=1)
36
36
  @json = Jikan::API.new.get("search", page, type, title)
37
- Jikan::Search.new(@json)
37
+ Jikan::Search.new(@json, type)
38
38
  end
39
39
 
40
40
  end
@@ -1,23 +1,49 @@
1
1
  module Jikan
2
2
  class Search < BaseEntity
3
3
 
4
+ def initialize(json, type)
5
+ super(json)
6
+ @type = type
7
+ @search = true
8
+ end
9
+
10
+ def is_search?
11
+ @search
12
+ end
13
+
4
14
  def id
5
- iter('id')
15
+ iter { |i| i['id'] }
6
16
  end
7
17
 
8
18
  def title
9
- iter('title')
19
+ iter { |i| i['title'] }
10
20
  end
11
21
 
12
22
  def url
13
- iter('url')
23
+ iter { |i| i['url'] }
24
+ end
25
+
26
+ # returns each result items wrapped in their respective objects
27
+ def result
28
+ case @type
29
+ when :anime
30
+ iter { |i| Jikan::Anime.new(i) }
31
+ when :manga
32
+ iter { |i| Jikan::Manga.new(i) }
33
+ when :character
34
+ raise NoMethodError, "Character only return raw result for now."
35
+ when :person
36
+ raise NoMethodError, "Person only return raw result for now."
37
+ end
14
38
  end
15
39
 
16
40
  private
17
41
 
18
- def iter(key)
42
+ def iter
19
43
  @raw['result'].map do |item|
20
- item[key]
44
+ if block_given?
45
+ yield item
46
+ end
21
47
  end
22
48
  end
23
49
  end
@@ -1,3 +1,3 @@
1
1
  module Jikan
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jikan.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zerocchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-29 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http