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 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.
-
#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.
-
#slug ⇒ String
The slug of this user.
-
#staff? ⇒ Boolean
The user's staff status.
-
#upvotes ⇒ Integer
The amount of upvotes this user has.
-
#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.
93 94 95 |
# File 'lib/dbio/user.rb', line 93 def @user['banner'] end |
#birthday ⇒ Date?
Returns the birthdate of this user, if one is set.
78 79 80 |
# File 'lib/dbio/user.rb', line 78 def birthday Date.parse(@user['birthday']) end |
#created ⇒ Time
Returns The time this user was created.
46 47 48 |
# File 'lib/dbio/user.rb', line 46 def created Time.parse(@user['created_at']) end |
#description ⇒ String?
Returns the description for this user, if one is set.
51 52 53 |
# File 'lib/dbio/user.rb', line 51 def description @user['description'] end |
#discord_connections ⇒ Array<DiscordConnection>
This is the user's Discord connections as they appear on their Discord profile
109 110 111 |
# File 'lib/dbio/user.rb', line 109 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
122 123 124 |
# File 'lib/dbio/user.rb', line 122 def discord_profile DBio::DiscordProfile.new(@discord) end |
#email ⇒ String?
Returns the user's email, if one is set.
83 84 85 |
# File 'lib/dbio/user.rb', line 83 def email @user['email'] end |
#flags ⇒ Integer
The flags for this user. Not entirely sure what they mean, but they're there.
36 37 38 |
# File 'lib/dbio/user.rb', line 36 def flags @user['flags'] end |
#gender ⇒ String?
The API returns an integer, so this is converted to a String.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dbio/user.rb', line 62 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.
25 26 27 |
# File 'lib/dbio/user.rb', line 25 def id @user['user_id'].to_i end |
#location ⇒ String?
Returns the location for this user, if one is set.
56 57 58 |
# File 'lib/dbio/user.rb', line 56 def location @user['location'] end |
#occupation ⇒ String?
Returns the user's occupation, if one is set.
88 89 90 |
# File 'lib/dbio/user.rb', line 88 def occupation @user['occupation'] end |
#premium? ⇒ Boolean
Returns the user's premium status.
98 99 100 |
# File 'lib/dbio/user.rb', line 98 def premium? @user['premium'] 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.
103 104 105 |
# File 'lib/dbio/user.rb', line 103 def staff? @user['staff'] end |
#upvotes ⇒ Integer
Returns the amount of upvotes this user has.
30 31 32 |
# File 'lib/dbio/user.rb', line 30 def upvotes @user['upvotes'] end |
#user_connections ⇒ Array<UserConnection>
The user's Discord.Bio connections. Not as specific.
115 116 117 |
# File 'lib/dbio/user.rb', line 115 def user_connections @user_connections.map { |e, f| DBio::UserConnection.new({ "type": e, "name": f }) } end |
#verified? ⇒ boolean
Returns if this user is verified.
41 42 43 |
# File 'lib/dbio/user.rb', line 41 def verified? @user['verified'] == 1 end |