Class: DBio::User
- Inherits:
-
Object
- Object
- DBio::User
- Defined in:
- lib/dbio/user.rb
Overview
Find information about users.
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #to_s)
readonly
Data in raw json form.
Instance Method Summary collapse
-
#banner_url ⇒ String?
The user's banner, if one is set.
-
#birthday ⇒ Date?
The birthdate of this user, if one is set.
-
#created ⇒ Time
The time this user was created.
-
#description ⇒ String?
The description for this user, if one is set.
-
#discord_connections ⇒ Array<DiscordConnection>
This is the user's Discord connections as they appear on their Discord profile.
-
#discord_profile ⇒ Object
The user's Discord profile information, not overly specific either.
-
#email ⇒ String?
The user's email, if one is set.
-
#flags ⇒ Integer
The oauth flags for this user.
-
#gender ⇒ String?
The API returns an integer, so this is converted to a String.
-
#id ⇒ Integer
The id of the user.
-
#initialize(data) ⇒ User
constructor
Initialize the user.
-
#likes ⇒ Integer
(also: #upvotes)
The amount of likes this user has.
-
#location ⇒ String?
The location for this user, if one is set.
-
#occupation ⇒ String?
The user's occupation, if one is set.
-
#premium? ⇒ Boolean
The user's premium status.
-
#profile_url ⇒ String
The link to this user's profile.
-
#slug ⇒ String
The slug of this user.
-
#staff? ⇒ Boolean
The user's staff status.
-
#user_connections ⇒ Array<UserConnection>
The user's Discord.Bio connections.
-
#verified? ⇒ boolean
If this user is verified.
Constructor Details
#initialize(data) ⇒ User
Initialize the user
4 5 6 7 8 9 |
# File 'lib/dbio/user.rb', line 4 def initialize(data) @user = data['user']['details'] @discord = data['discord'] @discord_connections = data['user']['discordConnections'] @user_connections = data['user']['user_connections'] end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: to_s
Returns data in raw json form.
12 13 14 |
# File 'lib/dbio/user.rb', line 12 def data @data end |
Instance Method Details
#banner_url ⇒ String?
Returns the user's banner, if one is set.
105 106 107 |
# File 'lib/dbio/user.rb', line 105 def @user['banner'] end |
#birthday ⇒ Date?
Returns the birthdate of this user, if one is set.
90 91 92 |
# File 'lib/dbio/user.rb', line 90 def birthday Date.parse(@user['birthday']) end |
#created ⇒ Time
Returns The time this user was created.
58 59 60 |
# File 'lib/dbio/user.rb', line 58 def created Time.parse(@user['created_at']) end |
#description ⇒ String?
Returns the description for this user, if one is set.
63 64 65 |
# File 'lib/dbio/user.rb', line 63 def description @user['description'] end |
#discord_connections ⇒ Array<DiscordConnection>
This is the user's Discord connections as they appear on their Discord profile
121 122 123 |
# File 'lib/dbio/user.rb', line 121 def discord_connections @discord_connections.map{ |e| DBio::DiscordConnection.new(e) } end |
#discord_profile ⇒ Object
The user's Discord profile information, not overly specific either. I instead recommend just getting it though your Discord Library with the ID
134 135 136 |
# File 'lib/dbio/user.rb', line 134 def discord_profile DBio::DiscordProfile.new(@discord) end |
#email ⇒ String?
Returns the user's email, if one is set.
95 96 97 |
# File 'lib/dbio/user.rb', line 95 def email @user['email'] end |
#flags ⇒ Integer
The oauth flags for this user. Not useful on their own.
48 49 50 |
# File 'lib/dbio/user.rb', line 48 def flags @user['flags'] end |
#gender ⇒ String?
The API returns an integer, so this is converted to a String.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dbio/user.rb', line 74 def gender case @user['gender'] when 0 "Male" when 1 "Female" when 2 "Non-Binary" when nil "Undisclosed" else nil end end |
#id ⇒ Integer
The id of the user.
31 32 33 |
# File 'lib/dbio/user.rb', line 31 def id @user['user_id'].to_i end |
#likes ⇒ Integer Also known as: upvotes
Returns the amount of likes this user has.
36 37 38 |
# File 'lib/dbio/user.rb', line 36 def likes @user['likes'] end |
#location ⇒ String?
Returns the location for this user, if one is set.
68 69 70 |
# File 'lib/dbio/user.rb', line 68 def location @user['location'] end |
#occupation ⇒ String?
Returns the user's occupation, if one is set.
100 101 102 |
# File 'lib/dbio/user.rb', line 100 def occupation @user['occupation'] end |
#premium? ⇒ Boolean
Returns the user's premium status.
110 111 112 |
# File 'lib/dbio/user.rb', line 110 def premium? @user['premium'] end |
#profile_url ⇒ String
The link to this user's profile
25 26 27 |
# File 'lib/dbio/user.rb', line 25 def profile_url "https://dsc.bio/#{profile_url}" end |
#slug ⇒ String
The slug of this user. Use: dsc.bio/slug
19 20 21 |
# File 'lib/dbio/user.rb', line 19 def slug @user['slug'] end |
#staff? ⇒ Boolean
Returns the user's staff status.
115 116 117 |
# File 'lib/dbio/user.rb', line 115 def staff? @user['staff'] end |
#user_connections ⇒ Array<UserConnection>
The user's Discord.Bio connections. Not as specific.
127 128 129 |
# File 'lib/dbio/user.rb', line 127 def user_connections @user_connections.map { |e, f| DBio::UserConnection.new({ "type": e, "name": f }) } end |
#verified? ⇒ boolean
Returns if this user is verified.
53 54 55 |
# File 'lib/dbio/user.rb', line 53 def verified? @user['verified'] == 1 end |