kitsu 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1e30c3e8145b06d9089b6639911541b0f84412f
4
+ data.tar.gz: 84c39544672f9ac3e7a3118fb4e2324c23969956
5
+ SHA512:
6
+ metadata.gz: 8ed4450c5089bcdacf6947aa0fb1aae491f569c1f24a2eea34ae4ec7428945b7d67d98eb918a2ca69d753020d147ac01922e0494089936b8772791c2826ddb0e
7
+ data.tar.gz: ccd477a7a91b4604eacd68562344e7a801b348fa440badf7d570051da8c8302fbae1e85ae845c475792f4a8ee257ae64f122f7ee5ff1e90a90e006e5a8e6b405
@@ -0,0 +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.
@@ -0,0 +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).
@@ -0,0 +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__)
@@ -0,0 +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
@@ -0,0 +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'
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,16 @@
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
+ puts "getting more related anime"
11
+
12
+ API.get(d['relationships']['anime']['links']['related'])
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,43 @@
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
@@ -0,0 +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
@@ -0,0 +1,3 @@
1
+ module Kitsu
2
+ VERSION = '0.1.1'
3
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitsu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Urothis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: twitter_cldr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: twitter_cldr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Kitsu API wrapper
126
+ email:
127
+ - natecaple@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - LICENSE.txt
133
+ - README.md
134
+ - bin/console
135
+ - bin/setup
136
+ - lib/kitsu.rb
137
+ - lib/kitsu/anime.rb
138
+ - lib/kitsu/api.rb
139
+ - lib/kitsu/library_entry.rb
140
+ - lib/kitsu/producer.rb
141
+ - lib/kitsu/user.rb
142
+ - lib/kitsu/user_library.rb
143
+ - lib/kitsu/version.rb
144
+ homepage: https://www.github.com/urothis/kitsu
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.6.13
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Kitsu API wrapper
168
+ test_files: []