kitsu 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f943121091547937bc46c6169e4d378e9d8f2799
4
- data.tar.gz: 68c80f8d8d4d125f4282c913acf2a0f3a23dba56
2
+ SHA256:
3
+ metadata.gz: 196dd61559dcc36f8c60adc5766f97a7e2d2af08977cc1dc8b743cad6c7a69eb
4
+ data.tar.gz: 21cb9695a5b4a21d4c9d088dd206a64cf3481541809c396ff6d2ac598bf3450f
5
5
  SHA512:
6
- metadata.gz: '059432d1d1afff0cf5b4eeb96630d1f127207ab02cb7535c1f4246922525f1d9e71335e9f5c747566ed8171fc2b1e82ad3d04312d5fe1a2c27296ee332698416'
7
- data.tar.gz: 027ef0730c187057b9f6cb2b5ba1b36b7b35a3412155e6f951093e81306b0981a312905e4f50e0dedb860c64fdeb3ae70ab2536d09fdb300cc9f92920a590e87
6
+ metadata.gz: 7aebd5e258ec695fa4c888cd7cc095d0f0a583b947e2b17d35350ec8bcc9719c171c36acc7fcf8e61f4537122341f77ac8b8202aa585c74fcfe75e4a0f5c414f
7
+ data.tar.gz: b773e9bc31a70382b5e0695956450daad30a7fd21620b2039655f062a2526f8506cb01f4719d0a964314bdb22b649f75ecb819ef52692773a56ac540dfba4040
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Urothis
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Urothis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,43 +1,43 @@
1
- # Kitsu
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kitsu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'kitsu'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install kitsu
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kitsu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the Kitsu project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kitsu/blob/master/CODE_OF_CONDUCT.md).
1
+ # Kitsu
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kitsu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kitsu'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kitsu
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kitsu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Kitsu project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kitsu/blob/master/CODE_OF_CONDUCT.md).
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "kitsu"
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 "kitsu"
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__)
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
data/lib/kitsu.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'twitter_cldr'
2
- require 'byebug'
3
-
4
- require_relative 'kitsu/version'
5
- require_relative 'kitsu/anime'
6
- require_relative 'kitsu/api'
7
- require_relative 'kitsu/library_entry'
8
- require_relative 'kitsu/producer'
9
- require_relative 'kitsu/user'
10
- require_relative 'kitsu/user_library'
1
+ require 'twitter_cldr'
2
+ require 'byebug'
3
+
4
+ require_relative 'kitsu/version'
5
+ require_relative 'kitsu/anime'
6
+ require_relative 'kitsu/api'
7
+ require_relative 'kitsu/library_entry'
8
+ require_relative 'kitsu/producer'
9
+ require_relative 'kitsu/user'
10
+ require_relative 'kitsu/user_library'
data/lib/kitsu/anime.rb CHANGED
@@ -1,39 +1,39 @@
1
- module Kitsu
2
- class Anime
3
- attr_accessor :data
4
-
5
- SEASON_PATTERNS = [
6
- '(\d+)\w{2}\sSeason$',
7
- 'Season (\d+)',
8
- '(\w+)\sSeason$',
9
- '(\w+\-\w+)\sSeason$'
10
- ].freeze
11
-
12
- def initialize(parsed)
13
- @parsed = parsed
14
- @data = @parsed['data']
15
- end
16
-
17
- def ordinalized_words_to_numbers
18
- @ordinalized_words_to_numbers_map ||= Hash[(1..100).to_a.map do |number|
19
- word = number.localize.to_rbnf_s('SpelloutRules', 'spellout-ordinal')
20
- number = number.to_s
21
- [word, number]
22
- end]
23
- end
24
-
25
- def title
26
- en_jp_title = data['attributes']['titles']['en_jp']
27
- en_jp_title.match(/(^.+?)($|\s\d+\w{2}\sSeason)/).captures[0]
28
- end
29
-
30
- def season
31
- pattern = /#{SEASON_PATTERNS.join('|')}/
32
- matches = @data['attributes']['titles']['en_jp'].match(pattern)
33
- return '1' if matches.nil?
34
- season = matches.captures.compact.first
35
- return ordinalized_words_to_numbers[season] if season.to_i.zero?
36
- season
37
- end
38
- end
39
- end
1
+ module Kitsu
2
+ class Anime
3
+ attr_accessor :data
4
+
5
+ SEASON_PATTERNS = [
6
+ '(\d+)\w{2}\sSeason$',
7
+ 'Season (\d+)',
8
+ '(\w+)\sSeason$',
9
+ '(\w+\-\w+)\sSeason$'
10
+ ].freeze
11
+
12
+ def initialize(parsed)
13
+ @parsed = parsed
14
+ @data = @parsed['data']
15
+ end
16
+
17
+ def ordinalized_words_to_numbers
18
+ @ordinalized_words_to_numbers_map ||= Hash[(1..100).to_a.map do |number|
19
+ word = number.localize.to_rbnf_s('SpelloutRules', 'spellout-ordinal')
20
+ number = number.to_s
21
+ [word, number]
22
+ end]
23
+ end
24
+
25
+ def title
26
+ en_jp_title = data['attributes']['titles']['en_jp']
27
+ en_jp_title.match(/(^.+?)($|\s\d+\w{2}\sSeason)/).captures[0]
28
+ end
29
+
30
+ def season
31
+ pattern = /#{SEASON_PATTERNS.join('|')}/
32
+ matches = @data['attributes']['titles']['en_jp'].match(pattern)
33
+ return '1' if matches.nil?
34
+ season = matches.captures.compact.first
35
+ return ordinalized_words_to_numbers[season] if season.to_i.zero?
36
+ season
37
+ end
38
+ end
39
+ end
data/lib/kitsu/api.rb CHANGED
@@ -1,16 +1,16 @@
1
- require 'httparty'
2
-
3
- module Kitsu
4
- class API
5
- include HTTParty
6
-
7
- BASE_URL = 'https://kitsu.io/api/edge/'.freeze
8
-
9
- def self.get(path)
10
- path = path.gsub(BASE_URL, '')
11
- url = "#{BASE_URL}/#{path}"
12
- response = super(url)
13
- JSON.parse(response)
14
- end
15
- end
16
- end
1
+ require 'httparty'
2
+
3
+ module Kitsu
4
+ class API
5
+ include HTTParty
6
+
7
+ BASE_URL = 'https://kitsu.io/api/edge/'.freeze
8
+
9
+ def self.get(path)
10
+ path = path.gsub(BASE_URL, '')
11
+ url = "#{BASE_URL}/#{path}"
12
+ response = super(url)
13
+ JSON.parse(response)
14
+ end
15
+ end
16
+ end
@@ -1,14 +1,20 @@
1
- module Kitsu
2
- class LibraryEntry
3
- def initialize(parsed)
4
- @parsed = parsed
5
- @data = @parsed['data']
6
- end
7
-
8
- def related_anime
9
- @data.map do |d|
10
- API.get(d['relationships']['anime']['links']['related'])
11
- end
12
- end
13
- end
14
- end
1
+ module Kitsu
2
+ class LibraryEntry
3
+ def initialize(parsed)
4
+ @parsed = parsed
5
+ @data = @parsed['data']
6
+ end
7
+
8
+ def related_anime
9
+ @data.map do |d|
10
+ API.get(d['relationships']['anime']['links']['related'])
11
+ end
12
+ end
13
+
14
+ def studio_anime
15
+ @data.map do |s|
16
+ API.get(s['relationships']['anime']['links']['related'])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,8 +1,54 @@
1
- module Kitsu
2
- class Producer
3
- def self.find(studio)
4
- parsed = API.get("producers?filter[slug]=#{studio}")
5
- self.class.new(parsed['data'].first)
6
- end
7
- end
8
- end
1
+ module Kitsu
2
+ class Producer
3
+
4
+ attr_accessor :data
5
+
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+
11
+
12
+ def anime(**filters)
13
+ anime = anime_related.map do |parsed|
14
+ Kitsu::Anime.new(parsed)
15
+ end
16
+ anime.select do |a|
17
+ filters.all? do |key, value|
18
+ a.data['attributes'][key.to_s] == value
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+
26
+ def anime_related
27
+ library_entries.map(&:related_anime).flatten
28
+ end
29
+
30
+
31
+
32
+
33
+ def library_entries
34
+ parsed = API.get(@data['relationships']['animeProductions']['links']['related'])
35
+
36
+ library_entries = [parsed]
37
+ loop do
38
+ parsed = API.get(parsed['links']['next'])
39
+ library_entries << parsed
40
+ break unless parsed['links'].key? 'next'
41
+ end
42
+
43
+ library_entries.flatten.map do |parsed|
44
+ Kitsu::LibraryEntry.new(parsed)
45
+ end
46
+ end
47
+
48
+
49
+ def self.find(studio)
50
+ parsed = API.get("producers?filter[slug]=#{studio}")
51
+ self.new(parsed['data'].first)
52
+ end
53
+ end
54
+ end
data/lib/kitsu/user.rb CHANGED
@@ -1,43 +1,44 @@
1
- module Kitsu
2
- class User
3
- attr_accessor :data
4
-
5
- def initialize(data)
6
- @data = data
7
- end
8
-
9
- def anime(**filters)
10
- anime = anime_related.map do |parsed|
11
- Kitsu::Anime.new(parsed)
12
- end
13
- anime.select do |a|
14
- filters.all? do |key, value|
15
- a.data['attributes'][key.to_s] == value
16
- end
17
- end
18
- end
19
-
20
- def anime_related
21
- library_entries.map(&:related_anime).flatten
22
- end
23
-
24
- def library_entries
25
- parsed = API.get(@data['relationships']['libraryEntries']['links']['related'])
26
-
27
- library_entries = [parsed]
28
- loop do
29
- parsed = API.get(parsed['links']['next'])
30
- library_entries << parsed
31
- break unless parsed['links'].key? 'next'
32
- end
33
- library_entries.flatten.map do |parsed|
34
- Kitsu::LibraryEntry.new(parsed)
35
- end
36
- end
37
-
38
- def self.find(username)
39
- parsed = API.get("users?filter[name]=#{username}")
40
- self.new(parsed['data'].first)
41
- end
42
- end
43
- end
1
+ module Kitsu
2
+ class User
3
+ attr_accessor :data
4
+
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ def anime(**filters)
10
+ anime = anime_related.map do |parsed|
11
+ Kitsu::Anime.new(parsed)
12
+ end
13
+
14
+ anime.select do |a|
15
+ filters.all? do |key, value|
16
+ a.data['attributes'][key.to_s] == value
17
+ end
18
+ end
19
+ end
20
+
21
+ def anime_related
22
+ library_entries.map(&:related_anime).flatten
23
+ end
24
+
25
+ def library_entries
26
+ parsed = API.get(@data['relationships']['links']['related'])
27
+
28
+ library_entries = [parsed]
29
+ loop do
30
+ parsed = API.get(parsed['links']['next'])
31
+ library_entries << parsed
32
+ break unless parsed['links'].key? 'next'
33
+ end
34
+ library_entries.flatten.map do |parsed|
35
+ Kitsu::LibraryEntry.new(parsed)
36
+ end
37
+ end
38
+
39
+ def self.find(username)
40
+ parsed = API.get("users?filter[name]=#{username}")
41
+ self.new(parsed['data'].first)
42
+ end
43
+ end
44
+ end
@@ -1,16 +1,16 @@
1
- module Kitsu
2
- class UserLibrary
3
- def get_user_library_entries(user)
4
- url = user['relationships']['libraryEntries']['links']['related']
5
- parsed = API.get(url)
6
- parsed['data']
7
- end
8
-
9
- def get_anime_from_library_entries(library_entries)
10
- library_entries.map(&:related_anime_links).map do |url|
11
- parsed = API.get(url)
12
- Anime.new(parsed['data'])
13
- end
14
- end
15
- end
16
- end
1
+ module Kitsu
2
+ class UserLibrary
3
+ def get_user_library_entries(user)
4
+ url = user['relationships']['libraryEntries']['links']['related']
5
+ parsed = API.get(url)
6
+ parsed['data']
7
+ end
8
+
9
+ def get_anime_from_library_entries(library_entries)
10
+ library_entries.map(&:related_anime_links).map do |url|
11
+ parsed = API.get(url)
12
+ Anime.new(parsed['data'])
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/kitsu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Kitsu
2
- VERSION = '0.1.2'
3
- end
1
+ module Kitsu
2
+ VERSION = '0.1.3'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urothis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-24 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  version: '0'
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.6.13
164
+ rubygems_version: 2.7.3
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Kitsu API wrapper