Class: Wanikani::User

Inherits:
Object
  • Object
show all
Defined in:
lib/wanikani/user.rb

Class Method Summary collapse

Class Method Details

.full_responseHash

Gets the full response of the User Information API call.

Returns:

  • (Hash)

    Full response from the User Information API call.



39
40
41
# File 'lib/wanikani/user.rb', line 39

def self.full_response
  return Wanikani.api_response("user-information")
end

.gravatar_url(options = {}) ⇒ String

Returns the Gravatar image URL using the Gravatar hash from the user’s information.

Parameters:

  • options (Hash) (defaults to: {})

    Optional settings for the gravatar URL.

Returns:

  • (String)

    The Gravatar URL, with the optional size parameter, nil if the user information contains no Gravatar hash.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/wanikani/user.rb', line 27

def self.gravatar_url(options = {})
  raise ArgumentError, "The size parameter must be an integer" if options[:size] && !options[:size].is_a?(Integer)
  api_response = Wanikani.api_response("user-information")
  hash = api_response["user_information"]["gravatar"]

  return nil if hash.nil?
  return build_gravatar_url(hash, options)
end

.informationHash

Gets the user information from WaniKani.

Returns:

  • (Hash)

    The user information for the WaniKani account by from the API key.



7
8
9
10
# File 'lib/wanikani/user.rb', line 7

def self.information
  api_response = Wanikani.api_response("user-information")
  return api_response["user_information"]
end

.on_vacation?Boolean

Checks if the user is currently in vacation mode.

Returns:

  • (Boolean)

    true if vacation_date contains a timestamp, false if vacation_date is null.



16
17
18
19
20
# File 'lib/wanikani/user.rb', line 16

def self.on_vacation?
  api_response = Wanikani.api_response("user-information")
  vacation_date = api_response["user_information"]["vacation_date"]
  return !vacation_date.nil?
end