wanikani 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wanikani.rb +3 -73
- data/lib/wanikani/client.rb +109 -0
- data/lib/wanikani/critical_items.rb +10 -10
- data/lib/wanikani/level.rb +47 -17
- data/lib/wanikani/recent_unlocks.rb +14 -21
- data/lib/wanikani/srs.rb +13 -13
- data/lib/wanikani/study_queue.rb +14 -14
- data/lib/wanikani/user.rb +22 -17
- data/lib/wanikani/version.rb +1 -1
- metadata +7 -5
- data/lib/wanikani/exceptions.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8206559d936c9724dbff8cc1c351d5e20864fae
|
4
|
+
data.tar.gz: 7ea4d78d466a1ec67e1990d89689a6a25a3e2b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4290df649685629cdf96047fd9563eedaad293e11b0bbd411d176d56a13db789edfa737bb40100e20d4fd572481ed884c12df164faab4502da705d09f05e8cd
|
7
|
+
data.tar.gz: f24cab27971276e4ad939e4b6d1af4e16283fa46ff98b661bc44bbdd7acb99b8d853d488c24cb7982c9ac5270fa53bb545cef5d7966c93a8517837ff2d1cbeef
|
data/lib/wanikani.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require '
|
3
|
-
require 'faraday_middleware'
|
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
|
-
require 'wanikani/exceptions'
|
2
|
+
require 'wanikani/client'
|
12
3
|
|
13
4
|
Encoding.default_external = Encoding::UTF_8
|
14
5
|
Encoding.default_internal = Encoding::UTF_8
|
@@ -18,67 +9,6 @@ module Wanikani
|
|
18
9
|
DEFAULT_API_VERSION = "v1.4"
|
19
10
|
VALID_API_VERSIONS = %w(v1 v1.1 v1.2 v1.3 v1.4)
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.api_key
|
26
|
-
@api_key
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.api_version=(api_version)
|
30
|
-
raise ArgumentError, "API version should be one of the following: #{VALID_API_VERSIONS.join(', ')}." unless VALID_API_VERSIONS.include?(api_version) || api_version.nil?
|
31
|
-
@api_version = api_version
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.api_version
|
35
|
-
@api_version ||= DEFAULT_API_VERSION
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.api_response(resource, optional_arg = nil)
|
39
|
-
raise ArgumentError, "You must define a resource to query Wanikani" if resource.nil? || resource.empty?
|
40
|
-
raise ArgumentError, "You must set your Wanikani API key before querying the API" if Wanikani.api_key.nil? || Wanikani.api_key.empty?
|
41
|
-
|
42
|
-
begin
|
43
|
-
res = client.get("/api/#{Wanikani.api_version}/user/#{Wanikani.api_key}/#{resource}/#{optional_arg}")
|
44
|
-
|
45
|
-
if !res.success? || res.body.has_key?("error")
|
46
|
-
self.raise_exception(res)
|
47
|
-
else
|
48
|
-
return res.body
|
49
|
-
end
|
50
|
-
rescue => error
|
51
|
-
raise Exception, "There was an error: #{error.message}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.valid_api_key?(api_key = nil)
|
56
|
-
api_key ||= Wanikani.api_key
|
57
|
-
return false if api_key.nil? || api_key.empty?
|
58
|
-
|
59
|
-
res = client.get("/api/#{Wanikani.api_version}/user/#{api_key}/user-information")
|
60
|
-
|
61
|
-
return false if !res.success? || res.body.has_key?("error")
|
62
|
-
return true
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def self.client
|
68
|
-
Faraday.new(url: Wanikani::API_ENDPOINT) do |conn|
|
69
|
-
conn.response :json, :content_type => /\bjson$/
|
70
|
-
conn.adapter Faraday.default_adapter
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.raise_exception(response)
|
75
|
-
raise Wanikani::InvalidKey, "The API key used for this request is invalid." and return if response.status == 401
|
76
|
-
|
77
|
-
message = if response.body.is_a?(Hash) and response.body.has_key?("error")
|
78
|
-
response.body["error"]["message"]
|
79
|
-
else
|
80
|
-
"Status code: #{response.status}"
|
81
|
-
end
|
82
|
-
raise Wanikani::Exception, "There was an error fetching the data from Wanikani (#{message})"
|
83
|
-
end
|
12
|
+
class InvalidKey < Exception; end
|
13
|
+
class Exception < Exception; end
|
84
14
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
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
|
+
module Wanikani
|
13
|
+
class Client
|
14
|
+
include Wanikani::User
|
15
|
+
include Wanikani::StudyQueue
|
16
|
+
include Wanikani::Level
|
17
|
+
include Wanikani::SRS
|
18
|
+
include Wanikani::RecentUnlocks
|
19
|
+
include Wanikani::CriticalItems
|
20
|
+
|
21
|
+
attr_accessor :api_key, :api_version
|
22
|
+
|
23
|
+
# Initialize a client which will be used to communicate with WaniKani.
|
24
|
+
#
|
25
|
+
# @param options [Hash] the API key (required) and API version (optional)
|
26
|
+
# used to communicate with the WaniKani API.
|
27
|
+
# @return [Wanikani::Client] an instance of Wanikani::Client.
|
28
|
+
def initialize(options = {})
|
29
|
+
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 version should be one of the following: #{Wanikani::VALID_API_VERSIONS.join(', ')}." unless Wanikani::VALID_API_VERSIONS.include?(options[:api_version]) || options[:api_version].nil?
|
31
|
+
|
32
|
+
@api_key = options[:api_key]
|
33
|
+
@api_version = options[:api_version] ||= Wanikani::DEFAULT_API_VERSION
|
34
|
+
end
|
35
|
+
|
36
|
+
# Verifies if the client's API key is valid by checking WaniKani's API.
|
37
|
+
#
|
38
|
+
# @param api_key [String] the API key to validate in WaniKani.
|
39
|
+
# @return [Boolean] whether the API key is valid.
|
40
|
+
def valid_api_key?(api_key = nil)
|
41
|
+
api_key ||= @api_key
|
42
|
+
return false if api_key.empty?
|
43
|
+
|
44
|
+
res = client.get("/api/#{@api_version}/user/#{api_key}/user-information")
|
45
|
+
|
46
|
+
return false if !res.success? || res.body.has_key?("error")
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
|
50
|
+
# Verifies if the specified API key is valid by checking WaniKani's API.
|
51
|
+
#
|
52
|
+
# @param api_key [String] the API key to validate in WaniKani.
|
53
|
+
# @return [Boolean] whether the API key is valid.
|
54
|
+
def self.valid_api_key?(api_key = nil)
|
55
|
+
raise ArgumentError, "You must specify a WaniKani API key before querying the API." if api_key.nil? || api_key.empty?
|
56
|
+
|
57
|
+
@client = Wanikani::Client.new(api_key: api_key)
|
58
|
+
return @client.valid_api_key?
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# Sets up the HTTP client for communicating with the WaniKani API.
|
64
|
+
#
|
65
|
+
# @return [Faraday::Connection] the HTTP client to communicate with the
|
66
|
+
# WaniKani API.
|
67
|
+
def client
|
68
|
+
Faraday.new(url: Wanikani::API_ENDPOINT) do |conn|
|
69
|
+
conn.response :json, :content_type => /\bjson$/
|
70
|
+
conn.adapter Faraday.default_adapter
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Contacts the WaniKani API and returns the data specified.
|
75
|
+
#
|
76
|
+
# @param resource [String] the resource to access.
|
77
|
+
# @param optional_arg [String] optional arguments for the specified resource.
|
78
|
+
# @return [Hash] the parsed API response.
|
79
|
+
def api_response(resource, optional_arg = nil)
|
80
|
+
raise ArgumentError, "You must define a resource to query WaniKani" if resource.nil? || resource.empty?
|
81
|
+
|
82
|
+
begin
|
83
|
+
res = client.get("/api/#{@api_version}/user/#{@api_key}/#{resource}/#{optional_arg}")
|
84
|
+
|
85
|
+
if !res.success? || res.body.has_key?("error")
|
86
|
+
raise_exception(res)
|
87
|
+
else
|
88
|
+
return res.body
|
89
|
+
end
|
90
|
+
rescue => error
|
91
|
+
raise Exception, "There was an error: #{error.message}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Handles exceptions according to the API response.
|
96
|
+
#
|
97
|
+
# @param response [Hash] the parsed API response from WaniKani's API.
|
98
|
+
def raise_exception(response)
|
99
|
+
raise Wanikani::InvalidKey, "The API key used for this request is invalid." and return if response.status == 401
|
100
|
+
|
101
|
+
message = if response.body.is_a?(Hash) and response.body.has_key?("error")
|
102
|
+
response.body["error"]["message"]
|
103
|
+
else
|
104
|
+
"Status code: #{response.status}"
|
105
|
+
end
|
106
|
+
raise Wanikani::Exception, "There was an error fetching the data from WaniKani (#{message})"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module CriticalItems
|
4
4
|
# Gets the user's current items under 'Critical Items'.
|
5
5
|
#
|
6
|
-
# @param [Integer]
|
7
|
-
# @return [Array]
|
8
|
-
def
|
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
9
|
raise ArgumentError, "Percentage must be an Integer between 0 and 100" if !percentage.between?(0, 100)
|
10
|
-
|
11
|
-
return
|
10
|
+
response = api_response("critical-items", percentage)
|
11
|
+
return response["requested_information"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# Gets the full response of the Critical Items List API call.
|
15
15
|
#
|
16
|
-
# @param [Integer]
|
17
|
-
# @return [Hash]
|
18
|
-
def
|
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
19
|
raise ArgumentError, "Percentage must be an Integer between 0 and 100" if !percentage.between?(0, 100)
|
20
|
-
return
|
20
|
+
return api_response("critical-items", percentage)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/wanikani/level.rb
CHANGED
@@ -1,37 +1,67 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module Level
|
4
4
|
# Gets the user's current level progression (radicals and Kanji).
|
5
5
|
#
|
6
|
-
# @return [Hash]
|
7
|
-
def
|
8
|
-
|
9
|
-
current_level = { "current_level" =>
|
10
|
-
return
|
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)
|
11
38
|
end
|
12
39
|
|
13
40
|
# Gets the full response of the Level Progression API call.
|
14
41
|
#
|
15
|
-
# @return [Hash]
|
16
|
-
def
|
17
|
-
return
|
42
|
+
# @return [Hash] full response from the Level Progression API call.
|
43
|
+
def full_level_progression_response
|
44
|
+
return api_response("level-progression")
|
18
45
|
end
|
19
46
|
|
20
47
|
private
|
21
48
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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)
|
26
56
|
levels = levels.join(',') if levels.is_a?(Array)
|
27
|
-
|
57
|
+
response = api_response(type, levels)
|
28
58
|
|
29
59
|
# The vocabulary API call without specifying levels returns a Hash instead
|
30
60
|
# of an Array, so this is a hacky way of dealing with it.
|
31
|
-
if
|
32
|
-
return
|
61
|
+
if response["requested_information"].is_a?(Hash)
|
62
|
+
return response["requested_information"]["general"]
|
33
63
|
else
|
34
|
-
return
|
64
|
+
return response["requested_information"]
|
35
65
|
end
|
36
66
|
end
|
37
67
|
end
|
@@ -1,32 +1,25 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module RecentUnlocks
|
4
4
|
# Gets the recent unlocked items (radicals, Kanji and vocabulary).
|
5
5
|
#
|
6
|
-
# @param [
|
7
|
-
# @return [Array]
|
8
|
-
def
|
9
|
-
|
10
|
-
|
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
|
11
15
|
end
|
12
16
|
|
13
17
|
# Gets the full response of the Recents Unlocks List API call.
|
14
18
|
#
|
15
|
-
# @param [Integer] limit the total number of items returned.
|
16
|
-
# @return [Hash]
|
17
|
-
def
|
18
|
-
return
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def self.method_missing(name, *args)
|
24
|
-
super unless [:radicals, :vocabulary, :kanji].include?(name)
|
25
|
-
|
26
|
-
limit = args.shift || 10
|
27
|
-
type = name == :radicals ? name.to_s.chop! : name.to_s
|
28
|
-
unlock_list = self.list(limit)
|
29
|
-
return unlock_list.select { |unlock| unlock["type"] == type }
|
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])
|
30
23
|
end
|
31
24
|
end
|
32
25
|
end
|
data/lib/wanikani/srs.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module SRS
|
4
4
|
ITEM_TYPES = %w(apprentice guru master enlighten burned all)
|
5
5
|
|
6
6
|
# Gets the counts for each SRS level and item types.
|
7
7
|
#
|
8
|
-
# @param [String]
|
9
|
-
# @return [Hash]
|
10
|
-
def
|
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
11
|
raise ArgumentError, "Please use a valid SRS type (or none for all types)" if !ITEM_TYPES.include?(item_type)
|
12
12
|
|
13
|
-
|
14
|
-
srs_distribution =
|
13
|
+
response = api_response("srs-distribution")
|
14
|
+
srs_distribution = response["requested_information"]
|
15
15
|
|
16
16
|
return srs_distribution if item_type == "all"
|
17
17
|
return srs_distribution[item_type]
|
@@ -19,14 +19,14 @@ module Wanikani
|
|
19
19
|
|
20
20
|
# Gets all items for a specific SRS level.
|
21
21
|
#
|
22
|
-
# @param [String]
|
23
|
-
# @return [Array]
|
24
|
-
def
|
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
25
|
raise ArgumentError, "Please use a valid SRS type." if !ITEM_TYPES.include?(item_type) || item_type == "all"
|
26
26
|
|
27
27
|
items_by_type = []
|
28
28
|
%w(radicals kanji vocabulary).each do |type|
|
29
|
-
items =
|
29
|
+
items = send("#{type}_list")
|
30
30
|
items.reject! { |item| item["user_specific"].nil? || item["user_specific"]["srs"] != item_type }.map! do |item|
|
31
31
|
item.merge!("type" => (type == 'radicals' ? 'radical' : type))
|
32
32
|
end
|
@@ -38,9 +38,9 @@ module Wanikani
|
|
38
38
|
|
39
39
|
# Gets the full response of the SRS Distribution API call.
|
40
40
|
#
|
41
|
-
# @return [Hash]
|
42
|
-
def
|
43
|
-
return
|
41
|
+
# @return [Hash] full response from the SRS Distribution API call.
|
42
|
+
def full_srs_distribution_response
|
43
|
+
return api_response("srs-distribution")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/wanikani/study_queue.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module StudyQueue
|
4
4
|
# Get the number of lessons and reviews that are currently in the user's queue.
|
5
5
|
#
|
6
|
-
# @return [Hash]
|
7
|
-
def
|
8
|
-
|
9
|
-
return
|
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
10
|
end
|
11
11
|
|
12
12
|
# Check if there are lessons available.
|
13
13
|
#
|
14
|
-
# @return [Boolean]
|
15
|
-
def
|
16
|
-
return !
|
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
17
|
end
|
18
18
|
|
19
19
|
# Check if there are reviews available.
|
20
20
|
#
|
21
|
-
# @return [Boolean]
|
22
|
-
def
|
23
|
-
return !
|
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
24
|
end
|
25
25
|
|
26
26
|
# Gets the full response of the Study Queue API call.
|
27
27
|
#
|
28
|
-
# @return [Hash]
|
29
|
-
def
|
30
|
-
return
|
28
|
+
# @return [Hash] full response from the Study Queue API call.
|
29
|
+
def full_study_queue_response
|
30
|
+
return api_response("study-queue")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/wanikani/user.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module Wanikani
|
3
|
-
|
3
|
+
module User
|
4
4
|
# Gets the user information from WaniKani.
|
5
5
|
#
|
6
|
-
# @return [Hash]
|
7
|
-
def
|
8
|
-
|
9
|
-
return
|
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
10
|
end
|
11
11
|
|
12
12
|
# Checks if the user is currently in vacation mode.
|
13
13
|
#
|
14
14
|
# @return [Boolean] true if vacation_date contains a timestamp, false if
|
15
15
|
# vacation_date is null.
|
16
|
-
def
|
17
|
-
|
18
|
-
vacation_date =
|
16
|
+
def on_vacation?
|
17
|
+
response = api_response("user-information")
|
18
|
+
vacation_date = response["user_information"]["vacation_date"]
|
19
19
|
return !vacation_date.nil?
|
20
20
|
end
|
21
21
|
|
22
22
|
# Returns the Gravatar image URL using the Gravatar hash from the user's information.
|
23
23
|
#
|
24
|
-
# @param options [Hash]
|
25
|
-
# @return [String]
|
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
26
|
# the user information contains no Gravatar hash.
|
27
|
-
def
|
27
|
+
def gravatar_url(options = {})
|
28
28
|
raise ArgumentError, "The size parameter must be an integer" if options[:size] && !options[:size].is_a?(Integer)
|
29
|
-
|
30
|
-
hash =
|
29
|
+
response = api_response("user-information")
|
30
|
+
hash = response["user_information"]["gravatar"]
|
31
31
|
|
32
32
|
return nil if hash.nil?
|
33
33
|
return build_gravatar_url(hash, options)
|
@@ -35,14 +35,19 @@ module Wanikani
|
|
35
35
|
|
36
36
|
# Gets the full response of the User Information API call.
|
37
37
|
#
|
38
|
-
# @return [Hash]
|
39
|
-
def
|
40
|
-
return
|
38
|
+
# @return [Hash] full response from the User Information API call.
|
39
|
+
def full_user_response
|
40
|
+
return api_response("user-information")
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
|
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 = {})
|
46
51
|
params = "d=mm" # Use 'Mystery Man' image if no image found.
|
47
52
|
params += "&size=#{options[:size]}" if options[:size]
|
48
53
|
|
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: 2.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: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -73,8 +73,8 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- lib/wanikani.rb
|
76
|
+
- lib/wanikani/client.rb
|
76
77
|
- lib/wanikani/critical_items.rb
|
77
|
-
- lib/wanikani/exceptions.rb
|
78
78
|
- lib/wanikani/level.rb
|
79
79
|
- lib/wanikani/recent_unlocks.rb
|
80
80
|
- lib/wanikani/srs.rb
|
@@ -85,7 +85,9 @@ homepage: https://github.com/dennmart/wanikani-gem
|
|
85
85
|
licenses:
|
86
86
|
- MIT
|
87
87
|
metadata: {}
|
88
|
-
post_install_message:
|
88
|
+
post_install_message: |2
|
89
|
+
Version 2.0 of the wanikani gem introduces many breaking changes.
|
90
|
+
Please view the README for more information: https://github.com/dennmart/wanikani-gem
|
89
91
|
rdoc_options: []
|
90
92
|
require_paths:
|
91
93
|
- lib
|
@@ -101,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version: '0'
|
102
104
|
requirements: []
|
103
105
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.6.
|
106
|
+
rubygems_version: 2.6.13
|
105
107
|
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: Add Japanese Kanji learning goodness to your Ruby projects!
|
data/lib/wanikani/exceptions.rb
DELETED