wanikani 2.0.0 → 3.0.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.
- checksums.yaml +5 -5
- data/lib/wanikani.rb +29 -3
- data/lib/wanikani/client.rb +36 -31
- data/lib/wanikani/configuration.rb +16 -0
- data/lib/wanikani/models/assignment.rb +24 -0
- data/lib/wanikani/models/level_progression.rb +25 -0
- data/lib/wanikani/models/reset.rb +20 -0
- data/lib/wanikani/models/review.rb +24 -0
- data/lib/wanikani/models/review_statistic.rb +24 -0
- data/lib/wanikani/models/shared.rb +20 -0
- data/lib/wanikani/models/spaced_repetition_system.rb +25 -0
- data/lib/wanikani/models/study_material.rb +24 -0
- data/lib/wanikani/models/subject.rb +24 -0
- data/lib/wanikani/models/summary.rb +10 -0
- data/lib/wanikani/models/user.rb +10 -0
- data/lib/wanikani/models/voice_actor.rb +24 -0
- data/lib/wanikani/response.rb +34 -0
- data/lib/wanikani/version.rb +1 -1
- metadata +19 -12
- data/lib/wanikani/critical_items.rb +0 -23
- data/lib/wanikani/level.rb +0 -68
- data/lib/wanikani/recent_unlocks.rb +0 -25
- data/lib/wanikani/srs.rb +0 -46
- data/lib/wanikani/study_queue.rb +0 -33
- data/lib/wanikani/user.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a313e7eca6981bd4ba6baf4f2dd0360a5e013bfde51a1bfc8d7f77184afee9ff
|
4
|
+
data.tar.gz: 2e13e29b6b19234142639720afa85578c7f036ba64e958c16102fbcde9c10990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bdbca8d53bed166a13720ba58e14564788d6a3c5e868d7e3469209940ac904c88b576514a860ac8926357f069523ed1da87ff86dff405de64f50684d29a080f
|
7
|
+
data.tar.gz: 1dceaa8c18c3eeb7cdf4e92fdb5b629b40ddd78627b648c8d8f9585fe6786ed109e26904483fbf9ec0781fabd10bd4f419a2fac39609610456aeaf9890db0185
|
data/lib/wanikani.rb
CHANGED
@@ -1,14 +1,40 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'wanikani/client'
|
3
|
+
require 'wanikani/response'
|
4
|
+
require 'wanikani/configuration'
|
5
|
+
require 'wanikani/models/shared'
|
6
|
+
require 'wanikani/models/assignment'
|
7
|
+
require 'wanikani/models/level_progression'
|
8
|
+
require 'wanikani/models/reset'
|
9
|
+
require 'wanikani/models/review'
|
10
|
+
require 'wanikani/models/review_statistic'
|
11
|
+
require 'wanikani/models/spaced_repetition_system'
|
12
|
+
require 'wanikani/models/study_material'
|
13
|
+
require 'wanikani/models/subject'
|
14
|
+
require 'wanikani/models/summary'
|
15
|
+
require 'wanikani/models/user'
|
16
|
+
require 'wanikani/models/voice_actor'
|
3
17
|
|
4
18
|
Encoding.default_external = Encoding::UTF_8
|
5
19
|
Encoding.default_internal = Encoding::UTF_8
|
6
20
|
|
7
21
|
module Wanikani
|
8
|
-
|
9
|
-
|
10
|
-
VALID_API_VERSIONS = %w(v1 v1.1 v1.2 v1.3 v1.4)
|
22
|
+
DEFAULT_API_REVISION = '20170710'
|
23
|
+
VALID_API_REVISIONS = %w(20170710)
|
11
24
|
|
12
25
|
class InvalidKey < Exception; end
|
13
26
|
class Exception < Exception; end
|
27
|
+
|
28
|
+
DEFAULT_CONFIG = {
|
29
|
+
api_revision: DEFAULT_API_REVISION
|
30
|
+
}
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
yield @config ||= Wanikani::Configuration.new(DEFAULT_CONFIG)
|
34
|
+
end
|
35
|
+
|
36
|
+
# global settings
|
37
|
+
def self.config
|
38
|
+
@config ||= Wanikani::Configuration.new(DEFAULT_CONFIG)
|
39
|
+
end
|
14
40
|
end
|
data/lib/wanikani/client.rb
CHANGED
@@ -2,23 +2,11 @@
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'faraday_middleware'
|
4
4
|
|
5
|
-
require 'wanikani/user'
|
6
|
-
require 'wanikani/study_queue'
|
7
|
-
require 'wanikani/level'
|
8
|
-
require 'wanikani/srs'
|
9
|
-
require 'wanikani/recent_unlocks'
|
10
|
-
require 'wanikani/critical_items'
|
11
|
-
|
12
5
|
module Wanikani
|
13
6
|
class Client
|
14
|
-
|
15
|
-
include Wanikani::StudyQueue
|
16
|
-
include Wanikani::Level
|
17
|
-
include Wanikani::SRS
|
18
|
-
include Wanikani::RecentUnlocks
|
19
|
-
include Wanikani::CriticalItems
|
7
|
+
API_ENDPOINT = "https://api.wanikani.com"
|
20
8
|
|
21
|
-
attr_accessor :api_key, :
|
9
|
+
attr_accessor :api_key, :api_revision
|
22
10
|
|
23
11
|
# Initialize a client which will be used to communicate with WaniKani.
|
24
12
|
#
|
@@ -27,10 +15,11 @@ module Wanikani
|
|
27
15
|
# @return [Wanikani::Client] an instance of Wanikani::Client.
|
28
16
|
def initialize(options = {})
|
29
17
|
raise ArgumentError, "You must specify a WaniKani API key before querying the API." if options[:api_key].nil? || options[:api_key].empty?
|
30
|
-
raise ArgumentError, "API
|
18
|
+
raise ArgumentError, "API revision should be one of the following: #{Wanikani::VALID_API_REVISIONS.join(', ')}." unless Wanikani::VALID_API_REVISIONS.include?(options[:api_revision]) || options[:api_revision].nil?
|
31
19
|
|
32
20
|
@api_key = options[:api_key]
|
33
|
-
@
|
21
|
+
@api_revision = options[:api_revision] ||= Wanikani::DEFAULT_API_REVISION
|
22
|
+
|
34
23
|
end
|
35
24
|
|
36
25
|
# Verifies if the client's API key is valid by checking WaniKani's API.
|
@@ -41,7 +30,7 @@ module Wanikani
|
|
41
30
|
api_key ||= @api_key
|
42
31
|
return false if api_key.empty?
|
43
32
|
|
44
|
-
res = client.get("/
|
33
|
+
res = client.get("/v2/user/")
|
45
34
|
|
46
35
|
return false if !res.success? || res.body.has_key?("error")
|
47
36
|
return true
|
@@ -58,29 +47,23 @@ module Wanikani
|
|
58
47
|
return @client.valid_api_key?
|
59
48
|
end
|
60
49
|
|
61
|
-
|
62
|
-
|
63
|
-
# Sets up the HTTP client for communicating with the WaniKani API.
|
50
|
+
# API endpoint at WaniKani
|
64
51
|
#
|
65
|
-
# @return [
|
66
|
-
|
67
|
-
|
68
|
-
Faraday.new(url: Wanikani::API_ENDPOINT) do |conn|
|
69
|
-
conn.response :json, :content_type => /\bjson$/
|
70
|
-
conn.adapter Faraday.default_adapter
|
71
|
-
end
|
52
|
+
# @return [String] URL of endpoint
|
53
|
+
def api_endpoint
|
54
|
+
API_ENDPOINT
|
72
55
|
end
|
73
56
|
|
74
57
|
# Contacts the WaniKani API and returns the data specified.
|
75
58
|
#
|
76
59
|
# @param resource [String] the resource to access.
|
77
|
-
# @param
|
60
|
+
# @param parameters [Hash] optional arguments for the specified resource.
|
78
61
|
# @return [Hash] the parsed API response.
|
79
|
-
def
|
62
|
+
def get(resource, parameters = nil)
|
80
63
|
raise ArgumentError, "You must define a resource to query WaniKani" if resource.nil? || resource.empty?
|
81
64
|
|
82
65
|
begin
|
83
|
-
res = client.get("/
|
66
|
+
res = client.get("/v2/#{resource}", parameters)
|
84
67
|
|
85
68
|
if !res.success? || res.body.has_key?("error")
|
86
69
|
raise_exception(res)
|
@@ -92,6 +75,28 @@ module Wanikani
|
|
92
75
|
end
|
93
76
|
end
|
94
77
|
|
78
|
+
private
|
79
|
+
|
80
|
+
# Sets up the HTTP client for communicating with the WaniKani API.
|
81
|
+
#
|
82
|
+
# @return [Faraday::Connection] the HTTP client to communicate with the
|
83
|
+
# WaniKani API.
|
84
|
+
def client
|
85
|
+
Faraday.new(url: api_endpoint, :headers => headers) do |conn|
|
86
|
+
conn.response :json, :content_type => /\bjson$/
|
87
|
+
conn.adapter Faraday.default_adapter
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def headers
|
92
|
+
{
|
93
|
+
'Content-Type' => 'application/json',
|
94
|
+
'Wanikani-Revision' => api_revision,
|
95
|
+
'Authorization' => "Bearer #{api_key}"
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
|
95
100
|
# Handles exceptions according to the API response.
|
96
101
|
#
|
97
102
|
# @param response [Hash] the parsed API response from WaniKani's API.
|
@@ -99,7 +104,7 @@ module Wanikani
|
|
99
104
|
raise Wanikani::InvalidKey, "The API key used for this request is invalid." and return if response.status == 401
|
100
105
|
|
101
106
|
message = if response.body.is_a?(Hash) and response.body.has_key?("error")
|
102
|
-
response.body["error"]
|
107
|
+
response.body["error"]
|
103
108
|
else
|
104
109
|
"Status code: #{response.status}"
|
105
110
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Wanikani
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_revision, :api_key
|
4
|
+
|
5
|
+
def initialize(configuration)
|
6
|
+
@api_revision = configuration.fetch(:api_revision)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
{
|
11
|
+
api_revision: api_revision,
|
12
|
+
api_key: api_key
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module Assignment
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[available_after available_before burned hidden ids immediately_available_for_lessons immediately_available_for_review in_review levels passed srs_stages started subject_ids subject_types unlocked updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.permitted_params
|
9
|
+
PERMITTED_PARAMS
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_all
|
13
|
+
find_by
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by(parameters = {})
|
17
|
+
respond(client.get('assignments', filter(parameters)))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find(id)
|
21
|
+
respond(client.get("assignments/#{id}"))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module LevelProgression
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('level_progressions',
|
14
|
+
filter(parameters)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(id)
|
18
|
+
respond(client.get("level_progressions/#{id}"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.permitted_params
|
22
|
+
PERMITTED_PARAMS
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module Reset
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids assignment_ids subject_ids updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_by(parameters = {})
|
9
|
+
respond(client.get('resets', parameters))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find(id)
|
13
|
+
respond(client.get("resets/#{id}"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.permitted_params
|
17
|
+
PERMITTED_PARAMS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module Review
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids assignment_ids subject_ids updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('reviews', parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
respond(client.get("reviews/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permitted_params
|
21
|
+
PERMITTED_PARAMS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module ReviewStatistic
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids hidden percentages_greater_than percentages_less_than subject_ids subject_types updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('review_statistics', parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
respond(client.get("review_statistics/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permitted_params
|
21
|
+
PERMITTED_PARAMS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module Shared
|
4
|
+
def respond(json)
|
5
|
+
Response.new(json)
|
6
|
+
end
|
7
|
+
|
8
|
+
def permitted_params
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
def filter(parameters)
|
13
|
+
parameters.keep_if { |key, value| permitted_params.include?(key.to_s) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client ||= ::Wanikani::Client.new(::Wanikani.config.to_hash)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module SpacedRepetitionSystem
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids updated_after].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('spaced_repetition_systems',
|
14
|
+
filter(parameters)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(id)
|
18
|
+
respond(client.get("spaced_repetition_systems/#{id}"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.permitted_params
|
22
|
+
PERMITTED_PARAMS
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module StudyMaterial
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids hidden subject_ids subject_types updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('study_materials', parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
respond(client.get("study_materials/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permitted_params
|
21
|
+
PERMITTED_PARAMS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module Subject
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids types slugs levels hidden updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('subjects', parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
respond(client.get("subjects/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permitted_params
|
21
|
+
PERMITTED_PARAMS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
module VoiceActor
|
4
|
+
extend Wanikani::Shared
|
5
|
+
|
6
|
+
PERMITTED_PARAMS = %w[ids updated_after page_after_id page_before_id].freeze
|
7
|
+
|
8
|
+
def self.find_all
|
9
|
+
find_by
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by(parameters = {})
|
13
|
+
respond(client.get('voice_actors', parameters))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(id)
|
17
|
+
respond(client.get("voice_actors/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permitted_params
|
21
|
+
PERMITTED_PARAMS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wanikani
|
3
|
+
class Response
|
4
|
+
attr_reader :response_data
|
5
|
+
|
6
|
+
def initialize(response_data)
|
7
|
+
@response_data = response_data
|
8
|
+
end
|
9
|
+
|
10
|
+
def data
|
11
|
+
response_data['data']
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
response_data['id']
|
16
|
+
end
|
17
|
+
|
18
|
+
def object
|
19
|
+
response_data['object']
|
20
|
+
end
|
21
|
+
|
22
|
+
def data_updated_at
|
23
|
+
response_data['data_updated_at']
|
24
|
+
end
|
25
|
+
|
26
|
+
def per_page
|
27
|
+
response_data['pages']['per_page']
|
28
|
+
end
|
29
|
+
|
30
|
+
def total_count
|
31
|
+
response_data['total_count']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/wanikani/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wanikani
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Martinez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -74,19 +74,27 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- lib/wanikani.rb
|
76
76
|
- lib/wanikani/client.rb
|
77
|
-
- lib/wanikani/
|
78
|
-
- lib/wanikani/
|
79
|
-
- lib/wanikani/
|
80
|
-
- lib/wanikani/
|
81
|
-
- lib/wanikani/
|
82
|
-
- lib/wanikani/
|
77
|
+
- lib/wanikani/configuration.rb
|
78
|
+
- lib/wanikani/models/assignment.rb
|
79
|
+
- lib/wanikani/models/level_progression.rb
|
80
|
+
- lib/wanikani/models/reset.rb
|
81
|
+
- lib/wanikani/models/review.rb
|
82
|
+
- lib/wanikani/models/review_statistic.rb
|
83
|
+
- lib/wanikani/models/shared.rb
|
84
|
+
- lib/wanikani/models/spaced_repetition_system.rb
|
85
|
+
- lib/wanikani/models/study_material.rb
|
86
|
+
- lib/wanikani/models/subject.rb
|
87
|
+
- lib/wanikani/models/summary.rb
|
88
|
+
- lib/wanikani/models/user.rb
|
89
|
+
- lib/wanikani/models/voice_actor.rb
|
90
|
+
- lib/wanikani/response.rb
|
83
91
|
- lib/wanikani/version.rb
|
84
92
|
homepage: https://github.com/dennmart/wanikani-gem
|
85
93
|
licenses:
|
86
94
|
- MIT
|
87
95
|
metadata: {}
|
88
96
|
post_install_message: |2
|
89
|
-
Version
|
97
|
+
Version 3.0 of the wanikani gem introduces many breaking changes in support of Wanikani API 2.0.
|
90
98
|
Please view the README for more information: https://github.com/dennmart/wanikani-gem
|
91
99
|
rdoc_options: []
|
92
100
|
require_paths:
|
@@ -95,15 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
103
|
requirements:
|
96
104
|
- - ">="
|
97
105
|
- !ruby/object:Gem::Version
|
98
|
-
version: '2.
|
106
|
+
version: '2.5'
|
99
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
108
|
requirements:
|
101
109
|
- - ">="
|
102
110
|
- !ruby/object:Gem::Version
|
103
111
|
version: '0'
|
104
112
|
requirements: []
|
105
|
-
|
106
|
-
rubygems_version: 2.6.13
|
113
|
+
rubygems_version: 3.1.2
|
107
114
|
signing_key:
|
108
115
|
specification_version: 4
|
109
116
|
summary: Add Japanese Kanji learning goodness to your Ruby projects!
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module CriticalItems
|
4
|
-
# Gets the user's current items under 'Critical Items'.
|
5
|
-
#
|
6
|
-
# @param percentage [Integer] the maximum percentage of correctness.
|
7
|
-
# @return [Array<Hash>] critical items and their related information.
|
8
|
-
def critical_items(percentage = 75)
|
9
|
-
raise ArgumentError, "Percentage must be an Integer between 0 and 100" if !percentage.between?(0, 100)
|
10
|
-
response = api_response("critical-items", percentage)
|
11
|
-
return response["requested_information"]
|
12
|
-
end
|
13
|
-
|
14
|
-
# Gets the full response of the Critical Items List API call.
|
15
|
-
#
|
16
|
-
# @param percentage [Integer] the maximum percentage of correctness.
|
17
|
-
# @return [Hash] full response from the Critical Items List API call.
|
18
|
-
def full_critical_items_response(percentage = 75)
|
19
|
-
raise ArgumentError, "Percentage must be an Integer between 0 and 100" if !percentage.between?(0, 100)
|
20
|
-
return api_response("critical-items", percentage)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/wanikani/level.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module Level
|
4
|
-
# Gets the user's current level progression (radicals and Kanji).
|
5
|
-
#
|
6
|
-
# @return [Hash] progress and total of radicals and Kanji for the user's current level.
|
7
|
-
def level_progression
|
8
|
-
response = api_response("level-progression")
|
9
|
-
current_level = { "current_level" => response["user_information"]["level"] }
|
10
|
-
return response["requested_information"].merge(current_level)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Gets the user's full list of radicals and stats.
|
14
|
-
#
|
15
|
-
# @param levels [Integer, Array<Integer>] a specific level or array of
|
16
|
-
# levels to fetch items for.
|
17
|
-
# @return [Hash] radicals with the user's stats.
|
18
|
-
def radicals_list(levels = nil)
|
19
|
-
return level_items_list("radicals", levels)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Gets the user's full list of kanji and stats.
|
23
|
-
#
|
24
|
-
# @param levels [Integer, Array<Integer>] a specific level or array of
|
25
|
-
# levels to fetch items for.
|
26
|
-
# @return [Hash] kanji with the user's stats.
|
27
|
-
def kanji_list(levels = nil)
|
28
|
-
return level_items_list("kanji", levels)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Gets the user's full list of vocabulary and stats.
|
32
|
-
#
|
33
|
-
# @param levels [Integer, Array<Integer>] a specific level or array of
|
34
|
-
# levels to fetch items for.
|
35
|
-
# @return [Hash] vocabulary with the user's stats.
|
36
|
-
def vocabulary_list(levels = nil)
|
37
|
-
return level_items_list("vocabulary", levels)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Gets the full response of the Level Progression API call.
|
41
|
-
#
|
42
|
-
# @return [Hash] full response from the Level Progression API call.
|
43
|
-
def full_level_progression_response
|
44
|
-
return api_response("level-progression")
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# Fetches the specified item type list from WaniKani's API
|
50
|
-
#
|
51
|
-
# @param type [String] The type of item to fetch.
|
52
|
-
# @param levels [Integer, Array<Integer>] a specific level or array of
|
53
|
-
# levels to fetch items for.
|
54
|
-
# @return [Hash] list of items of the specified type and levels.
|
55
|
-
def level_items_list(type, levels)
|
56
|
-
levels = levels.join(',') if levels.is_a?(Array)
|
57
|
-
response = api_response(type, levels)
|
58
|
-
|
59
|
-
# The vocabulary API call without specifying levels returns a Hash instead
|
60
|
-
# of an Array, so this is a hacky way of dealing with it.
|
61
|
-
if response["requested_information"].is_a?(Hash)
|
62
|
-
return response["requested_information"]["general"]
|
63
|
-
else
|
64
|
-
return response["requested_information"]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module RecentUnlocks
|
4
|
-
# Gets the recent unlocked items (radicals, Kanji and vocabulary).
|
5
|
-
#
|
6
|
-
# @param options [Hash] the options to limit the number and type of items.
|
7
|
-
# @return [Array<Hash>] hashes of unlocked items and related information.
|
8
|
-
def recent_unlocks(options = {})
|
9
|
-
response = api_response("recent-unlocks", options[:limit])
|
10
|
-
if options[:type]
|
11
|
-
return response["requested_information"].select { |unlock| unlock["type"] == options[:type] }
|
12
|
-
else
|
13
|
-
return response["requested_information"]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Gets the full response of the Recents Unlocks List API call.
|
18
|
-
#
|
19
|
-
# @param options [Integer] limit the total number of items returned.
|
20
|
-
# @return [Hash] full response from the Recent Unlocks List API call.
|
21
|
-
def full_recent_unlocks_response(options = {})
|
22
|
-
return api_response("recent-unlocks", options[:limit])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/wanikani/srs.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module SRS
|
4
|
-
ITEM_TYPES = %w(apprentice guru master enlighten burned all)
|
5
|
-
|
6
|
-
# Gets the counts for each SRS level and item types.
|
7
|
-
#
|
8
|
-
# @param item_type [String] the SRS level that will be returned.
|
9
|
-
# @return [Hash] the SRS information for each level for the user.
|
10
|
-
def srs_distribution(item_type = "all")
|
11
|
-
raise ArgumentError, "Please use a valid SRS type (or none for all types)" if !ITEM_TYPES.include?(item_type)
|
12
|
-
|
13
|
-
response = api_response("srs-distribution")
|
14
|
-
srs_distribution = response["requested_information"]
|
15
|
-
|
16
|
-
return srs_distribution if item_type == "all"
|
17
|
-
return srs_distribution[item_type]
|
18
|
-
end
|
19
|
-
|
20
|
-
# Gets all items for a specific SRS level.
|
21
|
-
#
|
22
|
-
# @param item_type [String] the SRS level for the items returned.
|
23
|
-
# @return [Array<Hash>] all the items matching the specified SRS for each level for the user.
|
24
|
-
def srs_items_by_type(item_type)
|
25
|
-
raise ArgumentError, "Please use a valid SRS type." if !ITEM_TYPES.include?(item_type) || item_type == "all"
|
26
|
-
|
27
|
-
items_by_type = []
|
28
|
-
%w(radicals kanji vocabulary).each do |type|
|
29
|
-
items = send("#{type}_list")
|
30
|
-
items.reject! { |item| item["user_specific"].nil? || item["user_specific"]["srs"] != item_type }.map! do |item|
|
31
|
-
item.merge!("type" => (type == 'radicals' ? 'radical' : type))
|
32
|
-
end
|
33
|
-
items_by_type << items
|
34
|
-
end
|
35
|
-
|
36
|
-
items_by_type.flatten
|
37
|
-
end
|
38
|
-
|
39
|
-
# Gets the full response of the SRS Distribution API call.
|
40
|
-
#
|
41
|
-
# @return [Hash] full response from the SRS Distribution API call.
|
42
|
-
def full_srs_distribution_response
|
43
|
-
return api_response("srs-distribution")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/lib/wanikani/study_queue.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module StudyQueue
|
4
|
-
# Get the number of lessons and reviews that are currently in the user's queue.
|
5
|
-
#
|
6
|
-
# @return [Hash] the number of lessons and reviews pending, along with upcoming review information.
|
7
|
-
def study_queue
|
8
|
-
response = api_response("study-queue")
|
9
|
-
return response["requested_information"]
|
10
|
-
end
|
11
|
-
|
12
|
-
# Check if there are lessons available.
|
13
|
-
#
|
14
|
-
# @return [Boolean] true if there's at least one lesson available, or false if there are none.
|
15
|
-
def lessons_available?
|
16
|
-
return !study_queue["lessons_available"].zero?
|
17
|
-
end
|
18
|
-
|
19
|
-
# Check if there are reviews available.
|
20
|
-
#
|
21
|
-
# @return [Boolean] true if there's at least one review available, or false if there are none.
|
22
|
-
def reviews_available?
|
23
|
-
return !study_queue["reviews_available"].zero?
|
24
|
-
end
|
25
|
-
|
26
|
-
# Gets the full response of the Study Queue API call.
|
27
|
-
#
|
28
|
-
# @return [Hash] full response from the Study Queue API call.
|
29
|
-
def full_study_queue_response
|
30
|
-
return api_response("study-queue")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/wanikani/user.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module Wanikani
|
3
|
-
module User
|
4
|
-
# Gets the user information from WaniKani.
|
5
|
-
#
|
6
|
-
# @return [Hash] the user information for the WaniKani account by from the API key.
|
7
|
-
def user_information
|
8
|
-
response = api_response("user-information")
|
9
|
-
return response["user_information"]
|
10
|
-
end
|
11
|
-
|
12
|
-
# Checks if the user is currently in vacation mode.
|
13
|
-
#
|
14
|
-
# @return [Boolean] true if vacation_date contains a timestamp, false if
|
15
|
-
# vacation_date is null.
|
16
|
-
def on_vacation?
|
17
|
-
response = api_response("user-information")
|
18
|
-
vacation_date = response["user_information"]["vacation_date"]
|
19
|
-
return !vacation_date.nil?
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns the Gravatar image URL using the Gravatar hash from the user's information.
|
23
|
-
#
|
24
|
-
# @param options [Hash] optional settings for the gravatar URL.
|
25
|
-
# @return [String, nil] the Gravatar URL, with the optional size parameter, nil if
|
26
|
-
# the user information contains no Gravatar hash.
|
27
|
-
def gravatar_url(options = {})
|
28
|
-
raise ArgumentError, "The size parameter must be an integer" if options[:size] && !options[:size].is_a?(Integer)
|
29
|
-
response = api_response("user-information")
|
30
|
-
hash = response["user_information"]["gravatar"]
|
31
|
-
|
32
|
-
return nil if hash.nil?
|
33
|
-
return build_gravatar_url(hash, options)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Gets the full response of the User Information API call.
|
37
|
-
#
|
38
|
-
# @return [Hash] full response from the User Information API call.
|
39
|
-
def full_user_response
|
40
|
-
return api_response("user-information")
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
# Builds the URL for displaying the Gravatar URL with different params.
|
46
|
-
#
|
47
|
-
# @param hash [String] the Gravatar hash for the user's image.
|
48
|
-
# @param options [Hash] optional params for building the Gravatar URL.
|
49
|
-
# @return [String] the Gravatar URL according to the specified params.
|
50
|
-
def build_gravatar_url(hash, options = {})
|
51
|
-
params = "d=mm" # Use 'Mystery Man' image if no image found.
|
52
|
-
params += "&size=#{options[:size]}" if options[:size]
|
53
|
-
|
54
|
-
return "https://secure.gravatar.com/avatar/#{hash}?#{params}" if options[:secure]
|
55
|
-
return "http://www.gravatar.com/avatar/#{hash}?#{params}"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|