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
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#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:, client_id:) ⇒ 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:, client_id:) ⇒ UserInfo
Returns a new instance of UserInfo.
12 13 14 15 16 17 18 19 20 |
# File 'lib/yiffspace/auth/user_info.rb', line 12 def initialize(id:, user:, discord:, client_id:) 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) @client_id = client_id end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/yiffspace/auth/user_info.rb', line 6 def client_id @client_id end |
#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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/yiffspace/auth/user_info.rb', line 69 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) user_data = ::YiffSpace::Utils::OpenHash.from(data.user) new( id: data.id, discord: data.discord, user: ::YiffSpace::Auth.unserialize_user(user_data), client_id: user_data.client_id, ) end |
.from_session(data) ⇒ Object
84 85 86 87 88 |
# File 'lib/yiffspace/auth/user_info.rb', line 84 def self.from_session(data) return nil if data.blank? from_json(data) end |
Instance Method Details
#anonymous? ⇒ Boolean
22 23 24 |
# File 'lib/yiffspace/auth/user_info.rb', line 22 def anonymous? false end |
#avatar(type = nil) ⇒ Object
35 36 37 |
# File 'lib/yiffspace/auth/user_info.rb', line 35 def avatar(type = nil) type.present? ? Images::Avatar.get_for(id, type) : Images::Avatar.default_for(id) end |
#avatar_url(type = nil) ⇒ Object
39 40 41 |
# File 'lib/yiffspace/auth/user_info.rb', line 39 def avatar_url(type = nil) avatar(type).url end |
#banner(type = nil) ⇒ Object
43 44 45 |
# File 'lib/yiffspace/auth/user_info.rb', line 43 def (type = nil) type.present? ? Images::Banner.get_for(id, type) : Images::Banner.default_for(id) end |
#banner_url(type = nil) ⇒ Object
47 48 49 |
# File 'lib/yiffspace/auth/user_info.rb', line 47 def (type = nil) (type).url end |
#blank? ⇒ Boolean
31 32 33 |
# File 'lib/yiffspace/auth/user_info.rb', line 31 def blank? false end |
#display_name ⇒ Object
53 54 55 |
# File 'lib/yiffspace/auth/user_info.rb', line 53 def display_name discord.global_name end |
#present? ⇒ Boolean
this feels wrong, but it hopefully shouldn’t break anything
27 28 29 |
# File 'lib/yiffspace/auth/user_info.rb', line 27 def present? true end |
#serializable_hash(_options = {}) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/yiffspace/auth/user_info.rb', line 57 def serializable_hash( = {}) { "id" => id, "discord" => discord.serializable_hash, "user" => ::YiffSpace::Auth.serialize_user(user, client_id: client_id), } end |
#to_session ⇒ Object
65 66 67 |
# File 'lib/yiffspace/auth/user_info.rb', line 65 def to_session serializable_hash.without("discord").merge(discord: discord.to_session) end |