Class: YiffSpace::Auth::UserInfo
- Inherits:
-
Object
- Object
- YiffSpace::Auth::UserInfo
- Defined in:
- lib/yiffspace/auth/user_info.rb,
lib/yiffspace/auth/user_info/anonymous.rb
Defined Under Namespace
Classes: Anonymous
Instance Attribute Summary collapse
-
#discord ⇒ Object
readonly
Returns the value of attribute discord.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #avatar(type = nil) ⇒ Object
- #avatar_url(type = nil) ⇒ Object
- #banner(type = nil) ⇒ Object
- #banner_url(type = nil) ⇒ Object
- #blank? ⇒ Boolean
- #display_name ⇒ Object
-
#initialize(id:, user:, discord:) ⇒ UserInfo
constructor
A new instance of UserInfo.
-
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything.
- #serializable_hash(_options = {}) ⇒ Object
- #to_session ⇒ Object
Constructor Details
#initialize(id:, user:, discord:) ⇒ UserInfo
Returns a new instance of UserInfo.
11 12 13 14 15 16 17 18 |
# File 'lib/yiffspace/auth/user_info.rb', line 11 def initialize(id:, user:, discord:) raise(ArgumentError, "no id provided") if id.blank? raise(ArgumentError, "no user provided") if user.blank? @id = id @user = user @discord = DiscordInfo.from_json(discord) end |
Instance Attribute Details
#discord ⇒ Object (readonly)
Returns the value of attribute discord.
6 7 8 |
# File 'lib/yiffspace/auth/user_info.rb', line 6 def discord @discord end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/yiffspace/auth/user_info.rb', line 6 def id @id end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/yiffspace/auth/user_info.rb', line 6 def user @user end |
Class Method Details
.from_json(data) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/yiffspace/auth/user_info.rb', line 67 def self.from_json(data) raise(ArgumentError, "invalid data") if data.blank? data = JSON.parse(data) if data.is_a?(String) data = ::YiffSpace::Utils::OpenHash.from(data) new( id: data.id, discord: data.discord, user: data.user, ) end |
.from_session(data) ⇒ Object
80 81 82 83 84 |
# File 'lib/yiffspace/auth/user_info.rb', line 80 def self.from_session(data) return nil if data.blank? from_json(data) end |
Instance Method Details
#anonymous? ⇒ Boolean
20 21 22 |
# File 'lib/yiffspace/auth/user_info.rb', line 20 def anonymous? false end |
#avatar(type = nil) ⇒ Object
33 34 35 |
# File 'lib/yiffspace/auth/user_info.rb', line 33 def avatar(type = nil) type.present? ? Images::Avatar.get_for(id, type) : Images::Avatar.default_for(id) end |
#avatar_url(type = nil) ⇒ Object
37 38 39 |
# File 'lib/yiffspace/auth/user_info.rb', line 37 def avatar_url(type = nil) avatar(type).url end |
#banner(type = nil) ⇒ Object
41 42 43 |
# File 'lib/yiffspace/auth/user_info.rb', line 41 def (type = nil) type.present? ? Images::Banner.get_for(id, type) : Images::Banner.default_for(id) end |
#banner_url(type = nil) ⇒ Object
45 46 47 |
# File 'lib/yiffspace/auth/user_info.rb', line 45 def (type = nil) (type).url end |
#blank? ⇒ Boolean
29 30 31 |
# File 'lib/yiffspace/auth/user_info.rb', line 29 def blank? false end |
#display_name ⇒ Object
51 52 53 |
# File 'lib/yiffspace/auth/user_info.rb', line 51 def display_name discord.global_name end |
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything
25 26 27 |
# File 'lib/yiffspace/auth/user_info.rb', line 25 def present? true end |
#serializable_hash(_options = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/yiffspace/auth/user_info.rb', line 55 def serializable_hash( = {}) { "id" => id, "discord" => discord.serializable_hash, "user" => user.as_json, } end |
#to_session ⇒ Object
63 64 65 |
# File 'lib/yiffspace/auth/user_info.rb', line 63 def to_session serializable_hash.without("discord").merge(discord: discord.to_session) end |