Class: DBLRuby::User

Inherits:
Object
  • Object
show all
Defined in:
lib/dblruby/user.rb

Overview

Find information about users.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, api) ⇒ User

Initialize the user

Parameters:

  • id (Integer, String)

    Integer/String ID of user you're requesting.

Raises:


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

#dataObject (readonly) Also known as: to_s

Returns data in raw json form.

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.

Returns:

  • (true, false)

    the user's admin status.


174
175
176
# File 'lib/dblruby/user.rb', line 174

def admin?
  @data['admin']
end

#avatarString

The avatar hash of the user's avatar.

Returns:

  • (String)

    the user's avatar hash.


66
67
68
# File 'lib/dblruby/user.rb', line 66

def avatar
  @data['avatar']
end

#avatar_imgString

Get's the user's avatar as an img, ready to be used in image linking.

Returns:

  • (String)

    the user's avatar link.


72
73
74
# File 'lib/dblruby/user.rb', line 72

def avatar_img
  "https://cdn.discordapp.com/avatars/#{id}/#{avatar}.webp?size=1024"
end

The banner image url of the user

Returns:

  • (String)

    the banner image url.


84
85
86
# File 'lib/dblruby/user.rb', line 84

def banner
  @data['banner']
end

#bioString

The bio of the user.

Returns:

  • (String)

    the user's bio.


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.

Returns:

  • (true, false)

    the user's certified status.


148
149
150
# File 'lib/dblruby/user.rb', line 148

def certified?
  @data['certifiedDev']
end

#colorString Also known as: colour

The custom hex color of the user.

Returns:

  • (String)

    the user's hex code for their page.


132
133
134
# File 'lib/dblruby/user.rb', line 132

def color
  @data['color']
end

#defavatarString

The cdn hash of the user's avatar if the user has none.

Returns:

  • (String)

    the user's defAvatar.


60
61
62
# File 'lib/dblruby/user.rb', line 60

def defavatar
  @data['defAvatar']
end

#discriminatorInteger Also known as: discrim, tag

The discriminator of the user.

Returns:

  • (Integer)

    the user's discriminator without the #.


45
46
47
# File 'lib/dblruby/user.rb', line 45

def discriminator
  @data['discriminator'].delete('#')
end

#distinctString

Returns the user's distinct, which is the Username and Discriminator.

Returns:

  • (String)

    the user's username + discrim.


54
55
56
# File 'lib/dblruby/user.rb', line 54

def distinct
  "#{username}\##{tag}"
end

#errorString?

Return the error if there is one, nil otherwise.

Returns:

  • (String, nil)

    the error.


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.

Returns:

  • (true, false)

    if there is an error.


27
28
29
# File 'lib/dblruby/user.rb', line 27

def error?
  !@data['error'].nil?
end

#githubString

The github username of the user.

Returns:

  • (String)

    the user's github link.


126
127
128
# File 'lib/dblruby/user.rb', line 126

def github
  @data['social']['github']
end

#idInteger

The id of the user.

Returns:

  • (Integer)

    User ID in integer form.


33
34
35
# File 'lib/dblruby/user.rb', line 33

def id
  @data['id'].to_i
end

#instagramString

The instagram username of the user.

Returns:

  • (String)

    the user's instagram link.


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.

Returns:

  • (true, false)

    the user's mod status.


158
159
160
# File 'lib/dblruby/user.rb', line 158

def mod?
  @data['mod']
end

#redditString

The reddit username of the user.

Returns:

  • (String)

    the user's reddit link.


108
109
110
# File 'lib/dblruby/user.rb', line 108

def reddit
  @data['social']['reddit']
end

#socialArray<String>

The social usernames of the user.

Returns:

  • (Array<String>)

    the user's social links.


90
91
92
# File 'lib/dblruby/user.rb', line 90

def social
  @data['social']
end

#social?true, false

Does the user have any social links? True if so, false if not.

Returns:

  • (true, false)

    if the user has any social links.


96
97
98
# File 'lib/dblruby/user.rb', line 96

def social?
  !@data['social'].nil?
end

#supporter?true, false Also known as: supporter

The supporter status of the user.

Returns:

  • (true, false)

    the user's supporter status.


140
141
142
# File 'lib/dblruby/user.rb', line 140

def supporter?
  @data['supporter']
end

#twitterString

The twitter username of the user.

Returns:

  • (String)

    the user's twitter link.


114
115
116
# File 'lib/dblruby/user.rb', line 114

def twitter
  @data['social']['twitter']
end

#usernameString

The username of the user.

Returns:

  • (String)

    the user's username.


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.

Returns:

  • (true, false)

    the user's website mod status.


166
167
168
# File 'lib/dblruby/user.rb', line 166

def webmod?
  @data['webMod']
end

#youtubeString

The youtube channel id of the user.

Returns:

  • (String)

    the user's youtube channel link.


102
103
104
# File 'lib/dblruby/user.rb', line 102

def youtube
  @data['social']['youtube']
end