Class: DBLRuby::User
- Inherits:
-
Object
- Object
- DBLRuby::User
- Defined in:
- lib/dblruby/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
-
#admin? ⇒ true, false
(also: #admin)
The admin status of the user.
-
#avatar ⇒ String
The avatar hash of the user's avatar.
-
#avatar_img ⇒ String
Get's the user's avatar as an img, ready to be used in image linking.
-
#banner ⇒ String
The banner image url of the user.
-
#bio ⇒ String
The bio of the user.
-
#certified? ⇒ true, false
(also: #certified)
The certified status of the user.
-
#color ⇒ String
(also: #colour)
The custom hex color of the user.
-
#defavatar ⇒ String
The cdn hash of the user's avatar if the user has none.
-
#discriminator ⇒ Integer
(also: #discrim, #tag)
The discriminator of the user.
-
#distinct ⇒ String
Returns the user's distinct, which is the Username and Discriminator.
-
#error ⇒ String?
Return the error if there is one, nil otherwise.
-
#error? ⇒ true, false
Return true if there is an error, false otherwise.
-
#github ⇒ String
The github username of the user.
-
#id ⇒ Integer
The id of the user.
-
#initialize(id, api) ⇒ User
constructor
Initialize the user.
-
#instagram ⇒ String
The instagram username of the user.
-
#mod? ⇒ true, false
(also: #mod)
The mod status of the user.
-
#reddit ⇒ String
The reddit username of the user.
-
#social ⇒ Array<String>
The social usernames of the user.
-
#social? ⇒ true, false
Does the user have any social links? True if so, false if not.
-
#supporter? ⇒ true, false
(also: #supporter)
The supporter status of the user.
-
#twitter ⇒ String
The twitter username of the user.
-
#username ⇒ String
The username of the user.
-
#webmod? ⇒ true, false
(also: #webmod)
The website moderator status of the user.
-
#youtube ⇒ String
The youtube channel id of the user.
Constructor Details
#initialize(id, api) ⇒ User
Initialize the user
6 7 8 9 10 11 12 |
# File 'lib/dblruby/user.rb', line 6 def initialize(id, api) url = "https://discordbots.org/api/users/#{id}" @data = JSON.parse(RestClient.get(url, Authorization: api)) rescue RestClient::NotFound raise DBLRuby::Errors::InvalidUser, 'The API returned a 404 error! Does that user exist?' end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: to_s
Returns data in raw json form.
15 16 17 |
# File 'lib/dblruby/user.rb', line 15 def data @data end |
Instance Method Details
#admin? ⇒ true, false Also known as: admin
The admin status of the user.
174 175 176 |
# File 'lib/dblruby/user.rb', line 174 def admin? @data['admin'] end |
#avatar ⇒ String
The avatar hash of the user's avatar.
66 67 68 |
# File 'lib/dblruby/user.rb', line 66 def avatar @data['avatar'] end |
#avatar_img ⇒ String
Get's the user's avatar as an img, ready to be used in image linking.
72 73 74 |
# File 'lib/dblruby/user.rb', line 72 def avatar_img "https://cdn.discordapp.com/avatars/#{id}/#{avatar}.webp?size=1024" end |
#banner ⇒ String
The banner image url of the user
84 85 86 |
# File 'lib/dblruby/user.rb', line 84 def @data['banner'] end |
#bio ⇒ String
The bio of the user.
78 79 80 |
# File 'lib/dblruby/user.rb', line 78 def bio @data['bio'] end |
#certified? ⇒ true, false Also known as: certified
The certified status of the user.
148 149 150 |
# File 'lib/dblruby/user.rb', line 148 def certified? @data['certifiedDev'] end |
#color ⇒ String Also known as: colour
The custom hex color of the user.
132 133 134 |
# File 'lib/dblruby/user.rb', line 132 def color @data['color'] end |
#defavatar ⇒ String
The cdn hash of the user's avatar if the user has none.
60 61 62 |
# File 'lib/dblruby/user.rb', line 60 def defavatar @data['defAvatar'] end |
#discriminator ⇒ Integer Also known as: discrim, tag
The discriminator of the user.
45 46 47 |
# File 'lib/dblruby/user.rb', line 45 def discriminator @data['discriminator'].delete('#') end |
#distinct ⇒ String
Returns the user's distinct, which is the Username and Discriminator.
54 55 56 |
# File 'lib/dblruby/user.rb', line 54 def distinct "#{username}\##{tag}" end |
#error ⇒ String?
Return the error if there is one, nil otherwise.
21 22 23 |
# File 'lib/dblruby/user.rb', line 21 def error @data['error'] end |
#error? ⇒ true, false
Return true if there is an error, false otherwise.
27 28 29 |
# File 'lib/dblruby/user.rb', line 27 def error? !@data['error'].nil? end |
#github ⇒ String
The github username of the user.
126 127 128 |
# File 'lib/dblruby/user.rb', line 126 def github @data['social']['github'] end |
#id ⇒ Integer
The id of the user.
33 34 35 |
# File 'lib/dblruby/user.rb', line 33 def id @data['id'].to_i end |
#instagram ⇒ String
The instagram username of the user.
120 121 122 |
# File 'lib/dblruby/user.rb', line 120 def instagram @data['social']['instagram'] end |
#mod? ⇒ true, false Also known as: mod
The mod status of the user.
158 159 160 |
# File 'lib/dblruby/user.rb', line 158 def mod? @data['mod'] end |
#reddit ⇒ String
The reddit username of the user.
108 109 110 |
# File 'lib/dblruby/user.rb', line 108 def reddit @data['social']['reddit'] end |
#social ⇒ Array<String>
The social usernames of the user.
90 91 92 |
# File 'lib/dblruby/user.rb', line 90 def @data['social'] end |
#social? ⇒ true, false
Does the user have any social links? True if so, false if not.
96 97 98 |
# File 'lib/dblruby/user.rb', line 96 def !@data['social'].nil? end |
#supporter? ⇒ true, false Also known as: supporter
The supporter status of the user.
140 141 142 |
# File 'lib/dblruby/user.rb', line 140 def supporter? @data['supporter'] end |
#twitter ⇒ String
The twitter username of the user.
114 115 116 |
# File 'lib/dblruby/user.rb', line 114 def twitter @data['social']['twitter'] end |
#username ⇒ String
The username of the user.
39 40 41 |
# File 'lib/dblruby/user.rb', line 39 def username @data['username'] end |
#webmod? ⇒ true, false Also known as: webmod
The website moderator status of the user.
166 167 168 |
# File 'lib/dblruby/user.rb', line 166 def webmod? @data['webMod'] end |
#youtube ⇒ String
The youtube channel id of the user.
102 103 104 |
# File 'lib/dblruby/user.rb', line 102 def youtube @data['social']['youtube'] end |