dblruby 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4680057787917a041e0979551c47c6e4cdc9f10
4
- data.tar.gz: 56b41a0ad44a2b4ec64f59db28ab4bdfbb5331ef
3
+ metadata.gz: 1c5808b684b56bac44e6b9c2ba59ba492c5c9531
4
+ data.tar.gz: c8d0caa840944b53f48f8302d8367d0a954ba4a9
5
5
  SHA512:
6
- metadata.gz: f9821d6aae9167946d150889deb2a540caed370976dd26fff9381374d7dc35e78828c05b63baf1864e8690ed109562ad2a6369163ea7eb301b04de57e0f12958
7
- data.tar.gz: 5fa58dd63c36bcde3b661c485dd7d78af563f81baac35e3b66bc9643fe75e583c485fe5b52b2bbdfa810924312dd9b008998976a778995522260f27c591d4df8
6
+ metadata.gz: b1a9eb06b3ef8f0ac6b49c4161824802af97ba57a15904d10e386631747ec87c596e1f92159c88c73c8d97732bac9251cde336431e0e40fb10bd0b6094a2252b
7
+ data.tar.gz: eff5eb66093b8e7d96b6db2082b3451b86235aff42c1b5fcadd9ec3dec76a91185bb8daafa194ec109267e049506d04117724bf58e18db06631e67b77aeac46d
@@ -2,6 +2,7 @@
2
2
  class DBLRuby::Bot
3
3
  # Initialize the bot
4
4
  # @param id [Integer, String] Integer/String ID of bot you're requesting.
5
+ # @raise [DBLRuby::Errors::InvalidBot] if the DBL returns a 404 error.
5
6
  def initialize(id)
6
7
  url = "https://discordbots.org/api/bots/#{id}"
7
8
  @data = JSON.parse(RestClient.get(url))
@@ -15,43 +16,55 @@ class DBLRuby::Bot
15
16
 
16
17
  alias to_s data
17
18
 
18
- # Get the bot's invite link.
19
+ # Return the error if there is one, nil otherwise.
20
+ # @return [String, nil] the error.
21
+ def error
22
+ @data['error']
23
+ end
24
+
25
+ # Return true if there is an error, false otherwise.
26
+ # @return [true, false] if there is an error.
27
+ def error?
28
+ !@data['error'].nil?
29
+ end
30
+
31
+ # The custom bot invite url of the bot.
19
32
  # @return [String] the bot's invite link.
20
33
  def invite
21
34
  @data['invite']
22
35
  end
23
36
 
24
- # Get the bot's GitHub Repo link.
37
+ # The link to the github repo of the bot.
25
38
  # @return [String] the bot's GitHub Repo link.
26
39
  def github
27
40
  @data['github']
28
41
  end
29
42
 
30
- # Get the bot's website link.
43
+ # The website url of the bot.
31
44
  # @return [String] the bot's website link.
32
45
  def website
33
46
  @data['website']
34
47
  end
35
48
 
36
- # Get the bot's Long Description.
49
+ # The long description of the bot. Can contain HTML and/or Markdown.
37
50
  # @return [String] the bot's Long Description.
38
51
  def longdesc
39
52
  @data['longdesc']
40
53
  end
41
54
 
42
- # Get the bot's Short Description.
55
+ # The short description of the bot.
43
56
  # @return [String] the bot's Short Description.
44
57
  def shortdesc
45
58
  @data['shortdesc']
46
59
  end
47
60
 
48
- # Get the bot's prefix.
61
+ # The prefix of the bot.
49
62
  # @return [String] the bot's prefix.
50
63
  def prefix
51
64
  @data['prefix']
52
65
  end
53
66
 
54
- # Get the bot's library.
67
+ # The library of the bot.
55
68
  # @return [String] the bot's library.
56
69
  def lib
57
70
  @data['lib']
@@ -63,7 +76,13 @@ class DBLRuby::Bot
63
76
  @data['clientid'].to_i
64
77
  end
65
78
 
66
- # Get the bot's avatar.
79
+ # The cdn hash of the bot's avatar if the bot has none.
80
+ # @return [String] the bot's defAvatar.
81
+ def defavatar
82
+ @data['defAvatar']
83
+ end
84
+
85
+ # The avatar hash of the bot's avatar.
67
86
  # @return [String] the bot's avatar.
68
87
  def avatar
69
88
  @data['avatar']
@@ -75,13 +94,13 @@ class DBLRuby::Bot
75
94
  "https://cdn.discordapp.com/avatars/#{id}/#{avatar}.webp?size=1024"
76
95
  end
77
96
 
78
- # Get the bot's ID.
97
+ # The id of the bot.
79
98
  # @return [Integer] the bot's id.
80
99
  def id
81
100
  @data['id'].to_i
82
101
  end
83
102
 
84
- # Get the bot's discriminator.
103
+ # The discriminator of the bot.
85
104
  # @return [Integer] the bot's discriminator without the #.
86
105
  def discriminator
87
106
  @data['discriminator'].delete('#').to_i
@@ -90,7 +109,7 @@ class DBLRuby::Bot
90
109
  alias discrim discriminator
91
110
  alias tag discriminator
92
111
 
93
- # Get the bot's username.
112
+ # The username of the bot.
94
113
  # @return [String] the bot's username.
95
114
  def username
96
115
  @data['username']
@@ -102,19 +121,26 @@ class DBLRuby::Bot
102
121
  "#{username}\##{tag}"
103
122
  end
104
123
 
105
- # Get the bot's creation date (on the list).
106
- # @return [String] the bot's date.
124
+ # The date when the bot was approved.
125
+ # @return [Date] the bot's approval date.
107
126
  def date
108
- @data['date']
127
+ Date.parse(@data['date'])
109
128
  end
110
129
 
111
- # Get the bot's support server invite code.
130
+ # The time when the bot was approved.
131
+ # This is compatiable with embed.timestamp, unlike #date
132
+ # @return [Time] the bot's approval time.
133
+ def time
134
+ Time.parse(@data['date'])
135
+ end
136
+
137
+ # The support server invite code of the bot.
112
138
  # @return [String] the bot's support server code.
113
139
  def support
114
140
  @data['support']
115
141
  end
116
142
 
117
- # Get the bot's support server link, ready for clicking.
143
+ # The bot's support server link, ready for clicking.
118
144
  # @return [String] the bot's support server link.
119
145
  def support_link
120
146
  "https://discord.gg/#{support}"
@@ -143,7 +169,7 @@ class DBLRuby::Bot
143
169
  @data['shards']
144
170
  end
145
171
 
146
- # Get the bot's monthly votes.
172
+ # The amount of upvotes the bot has this month.
147
173
  # @return [Integer] the bot's monthly points/votes.
148
174
  def monthlypoints
149
175
  @data['monthlyPoints'].to_i
@@ -151,7 +177,7 @@ class DBLRuby::Bot
151
177
 
152
178
  alias monthlyvotes monthlypoints
153
179
 
154
- # Get the bot's total votes.
180
+ # The amount of upvotes the bot has.
155
181
  # @return [Integer] the bot's total points/votes.
156
182
  def points
157
183
  @data['points'].to_i
@@ -159,7 +185,7 @@ class DBLRuby::Bot
159
185
 
160
186
  alias votes points
161
187
 
162
- # Get the bot's certified status.
188
+ # The certified status of the bot.
163
189
  # @return [true, false] the bot's certified status.
164
190
  def certifiedbot
165
191
  @data['certifiedBot']
@@ -169,18 +195,24 @@ class DBLRuby::Bot
169
195
  alias certified certifiedbot
170
196
  alias certifiedbot? certifiedbot
171
197
 
172
- # Get the bot's owners.
198
+ # The owners of the bot. First one in the array is the main owner.
173
199
  # @return [Array<String>] the bot's owners in an array.
174
200
  def owners
175
201
  @data['owners']
176
202
  end
177
203
 
178
- # Get the bot's sorting tags.
204
+ # The tags of the bot.
179
205
  # @return [Array<String>] the bot's tags in an array.
180
206
  def tags
181
207
  @data['tags']
182
208
  end
183
209
 
210
+ # The vanity url of the bot.
211
+ # @return [String] the bot's vanity url.
212
+ def vanity
213
+ @data['vanity']
214
+ end
215
+
184
216
  # Get the bot's legacy status.
185
217
  # @return [true, false] the bot's legacy status.
186
218
  def legacy
@@ -188,9 +220,4 @@ class DBLRuby::Bot
188
220
  end
189
221
 
190
222
  alias legacy? legacy
191
-
192
- # Debug method to force a bot error.
193
- def fail
194
- raise DBLRuby::Errors::NoData, 'The API didn\'t return anything!'
195
- end
196
223
  end
@@ -1,8 +1,5 @@
1
1
  # Errors are cool.
2
2
  module DBLRuby::Errors
3
- # Ran if No Data is returned.
4
- class NoData < RuntimeError; end
5
-
6
3
  # Ran if a 404 error is returned in #loadbot
7
4
  class InvalidBot < RuntimeError; end
8
5
 
@@ -11,4 +8,7 @@ module DBLRuby::Errors
11
8
 
12
9
  # Ran if a 401 unauthorized error is returned in stats.
13
10
  class InvalidAPIKey < RuntimeError; end
11
+
12
+ # Ran if a 404 unknown error is returned in stats.
13
+ class InvalidID < RuntimeError; end
14
14
  end
@@ -9,15 +9,20 @@ class DBLRuby::Stats
9
9
 
10
10
  # Get the bot's server count, returns an int.
11
11
  # @return [Integer] amount of servers the bot is on.
12
+ # @raise [DBLRuby::Errors::InvalidID] if the DBL returns a 404 error.
12
13
  def servercount
13
14
  url = "https://discordbots.org/api/bots/#{@id}"
14
15
  JSON.parse(RestClient.get(url))['server_count'].to_i
16
+ rescue RestClient::NotFound
17
+ raise DBLRuby::Errors::InvalidID,
18
+ 'DBL Returned a 404 unknown error! Did you enter the correct ID?'
15
19
  end
16
20
 
17
21
  alias servers servercount
18
22
 
19
23
  # Update the bot's server count.
20
24
  # @param id [Integer, String] Integer/String ID of bot server count.
25
+ # @raise [DBLRuby::Errors::InvalidAPIKey] if the DBL returns a 401 error.
21
26
  def updateservercount(count)
22
27
  url = "https://discordbots.org/api/bots/#{@id}/stats"
23
28
  json = '{"server_count":' + count.to_s + '}'
@@ -33,6 +38,7 @@ class DBLRuby::Stats
33
38
  # Check to see if a user really voted, via an ID.
34
39
  # @param id [Integer, String] Integer/String ID of user you're requesting.
35
40
  # @return [true, false] if the user voted or not.
41
+ # @raise [DBLRuby::Errors::InvalidAPIKey] if the DBL returns a 401 error.
36
42
  def verifyvote(id)
37
43
  r = RestClient.get('https://discordbots.org/api/bots/check',
38
44
  params: { userId: id },
@@ -2,6 +2,7 @@
2
2
  class DBLRuby::User
3
3
  # Initialize the user
4
4
  # @param id [Integer, String] Integer/String ID of user you're requesting.
5
+ # @raise [DBLRuby::Errors::InvalidUser] if the DBL returns a 404 error.
5
6
  def initialize(id)
6
7
  url = "https://discordbots.org/api/users/#{id}"
7
8
  @data = JSON.parse(RestClient.get(url))
@@ -15,19 +16,31 @@ class DBLRuby::User
15
16
 
16
17
  alias to_s data
17
18
 
18
- # Get the user's ID.
19
+ # Return the error if there is one, nil otherwise.
20
+ # @return [String, nil] the error.
21
+ def error
22
+ @data['error']
23
+ end
24
+
25
+ # Return true if there is an error, false otherwise.
26
+ # @return [true, false] if there is an error.
27
+ def error?
28
+ !@data['error'].nil?
29
+ end
30
+
31
+ # The id of the user.
19
32
  # @return [Integer] User ID in integer form.
20
33
  def id
21
34
  @data['id'].to_i
22
35
  end
23
36
 
24
- # Get the user's username.
37
+ # The username of the user.
25
38
  # @return [String] the user's username.
26
39
  def username
27
40
  @data['username']
28
41
  end
29
42
 
30
- # Get the user's discriminator.
43
+ # The discriminator of the user.
31
44
  # @return [Integer] the user's discriminator without the #.
32
45
  def discriminator
33
46
  @data['discriminator'].delete('#').to_i
@@ -42,7 +55,13 @@ class DBLRuby::User
42
55
  "#{username}\##{tag}"
43
56
  end
44
57
 
45
- # Get the user's avatar.
58
+ # The cdn hash of the user's avatar if the user has none.
59
+ # @return [String] the user's defAvatar.
60
+ def defavatar
61
+ @data['defAvatar']
62
+ end
63
+
64
+ # The avatar hash of the user's avatar.
46
65
  # @return [String] the user's avatar hash.
47
66
  def avatar
48
67
  @data['avatar']
@@ -54,13 +73,19 @@ class DBLRuby::User
54
73
  "https://cdn.discordapp.com/avatars/#{id}/#{avatar}.webp?size=1024"
55
74
  end
56
75
 
57
- # Get the user's bio.
76
+ # The bio of the user.
58
77
  # @return [String] the user's bio.
59
78
  def bio
60
79
  @data['bio']
61
80
  end
62
81
 
63
- # Get a list of social links for the user
82
+ # The banner image url of the user
83
+ # @return [String] the banner image url.
84
+ def banner
85
+ @data['banner']
86
+ end
87
+
88
+ # The social usernames of the user.
64
89
  # @return [Array<String>] the user's social links.
65
90
  def social
66
91
  @data['social']
@@ -72,37 +97,37 @@ class DBLRuby::User
72
97
  !@data['social'].nil?
73
98
  end
74
99
 
75
- # Get the user's YouTube channel link.
100
+ # The youtube channel id of the user.
76
101
  # @return [String] the user's youtube channel link.
77
102
  def youtube
78
103
  @data['social']['youtube']
79
104
  end
80
105
 
81
- # Get the user's Reddit link.
106
+ # The reddit username of the user.
82
107
  # @return [String] the user's reddit link.
83
108
  def reddit
84
109
  @data['social']['reddit']
85
110
  end
86
111
 
87
- # Get the user's Twitter link.
112
+ # The twitter username of the user.
88
113
  # @return [String] the user's twitter link.
89
114
  def twitter
90
115
  @data['social']['twitter']
91
116
  end
92
117
 
93
- # Get the user's Instagram link.
118
+ # The instagram username of the user.
94
119
  # @return [String] the user's instagram link.
95
120
  def instagram
96
121
  @data['social']['instagram']
97
122
  end
98
123
 
99
- # Get the user's Github link.
124
+ # The github username of the user.
100
125
  # @return [String] the user's github link.
101
126
  def github
102
127
  @data['social']['github']
103
128
  end
104
129
 
105
- # Get the user's Hex Colour.
130
+ # The custom hex color of the user.
106
131
  # @return [String] the user's hex code for their page.
107
132
  def color
108
133
  @data['color']
@@ -110,7 +135,7 @@ class DBLRuby::User
110
135
 
111
136
  alias colour color
112
137
 
113
- # Get the user's supporter status.
138
+ # The supporter status of the user.
114
139
  # @return [true, false] the user's supporter status.
115
140
  def supporter?
116
141
  @data['supporter']
@@ -118,7 +143,7 @@ class DBLRuby::User
118
143
 
119
144
  alias supporter supporter?
120
145
 
121
- # Get the user's certified developer status.
146
+ # The certified status of the user.
122
147
  # @return [true, false] the user's certified status.
123
148
  def certified?
124
149
  @data['lib']
@@ -128,7 +153,7 @@ class DBLRuby::User
128
153
  alias certifieddev certified
129
154
  alias certifieddev? certified
130
155
 
131
- # Get the user's mod status.
156
+ # The mod status of the user.
132
157
  # @return [true, false] the user's mod status.
133
158
  def mod?
134
159
  @data['mod']
@@ -136,7 +161,7 @@ class DBLRuby::User
136
161
 
137
162
  alias mod mod?
138
163
 
139
- # Get the user's website moderator status.
164
+ # The website moderator status of the user.
140
165
  # @return [true, false] the user's website mod status.
141
166
  def webmod?
142
167
  @data['webMod']
@@ -144,16 +169,11 @@ class DBLRuby::User
144
169
 
145
170
  alias webmod webmod?
146
171
 
147
- # Get the user's admin status.
172
+ # The admin status of the user.
148
173
  # @return [true, false] the user's admin status.
149
174
  def admin?
150
175
  @data['admin']
151
176
  end
152
177
 
153
178
  alias admin admin?
154
-
155
- # Debug method to force a bot error.
156
- def fail
157
- raise DBLRuby::Errors::NoData, 'The API didn\'t return anything!'
158
- end
159
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dblruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chewsterchew
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,7 +38,12 @@ files:
38
38
  homepage: http://github.com/Chewsterchew/DBLRuby
39
39
  licenses:
40
40
  - MIT
41
- metadata: {}
41
+ metadata:
42
+ bug_tracker_uri: https://github.com/Chewsterchew/DBLRuby/issues
43
+ changelog_uri: https://github.com/Chewsterchew/DBLRuby/releases
44
+ homepage_uri: http://github.com/Chewsterchew/DBLRuby
45
+ source_code_uri: http://github.com/Chewsterchew/DBLRuby
46
+ wiki_uri: http://github.com/Chewsterchew/DBLRuby/wiki
42
47
  post_install_message:
43
48
  rdoc_options: []
44
49
  require_paths:
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
60
  version: '0'
56
61
  requirements: []
57
62
  rubyforge_project:
58
- rubygems_version: 2.6.8
63
+ rubygems_version: 2.6.13
59
64
  signing_key:
60
65
  specification_version: 4
61
66
  summary: Discord Bot List API for Ruby