dblruby 1.0.0 → 1.2.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 +5 -5
- data/lib/dblruby.rb +50 -13
- data/lib/dblruby/bot.rb +15 -24
- data/lib/dblruby/errors.rb +7 -4
- data/lib/dblruby/search.rb +1 -1
- data/lib/dblruby/stats.rb +5 -5
- data/lib/dblruby/user.rb +17 -22
- data/lib/dblruby/weekend.rb +5 -5
- data/lib/dblruby/widget.rb +119 -0
- metadata +14 -14
- data/lib/dblruby/api.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e6da53133ead002925bdd344bb9367f2f979dd4b2ab5f1232f2c6e2bd0b46d4
|
4
|
+
data.tar.gz: 340bf140b1aea90cf31dab26088c95235e444038940906645f028261ede5954b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c19410d54c87abdf52b19d805533f4c64d39b1ef23f8090c838a1a986e02da771dd52757419023761bedf2eb0da644f30cd960a9f07a6954012e892defd025
|
7
|
+
data.tar.gz: fafde3a5a440c066f74bf52ff171a21dafcb8f9279d89172a7ab32aa057729f115fc870ca7b29c8da18873af4f45e3e8481cf4b99567074ec3a250ebf96979d4
|
data/lib/dblruby.rb
CHANGED
@@ -13,17 +13,28 @@ class DBLRuby
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Initialize stats
|
16
|
+
# @return [Stats] the new stats object
|
16
17
|
def stats
|
17
18
|
Stats.new(@api, @id)
|
18
19
|
end
|
19
20
|
|
20
21
|
# Load a bot.
|
21
22
|
# @param id [Integer, String] Integer/String ID of the bot you're requesting.
|
23
|
+
# @raise [DBLRuby::Errors::InvalidBot] if a 404 error is returned.
|
24
|
+
# @return [Bot] the new Bot object
|
22
25
|
def bot(id)
|
23
|
-
|
26
|
+
url = "https://top.gg/api/bots/#{id}"
|
27
|
+
data = JSON.parse(RestClient.get(url, Authorization: api))
|
28
|
+
Bot.new(data)
|
29
|
+
rescue RestClient::Unauthorized
|
30
|
+
raise DBLRuby::Errors::InvalidAPIKey,
|
31
|
+
'The API returned a 401 error, I believe your token is invalid.'
|
32
|
+
rescue RestClient::NotFound
|
33
|
+
raise DBLRuby::Errors::InvalidBot,
|
34
|
+
'The API returned a 404 error! Is that bot listed?'
|
24
35
|
end
|
25
36
|
|
26
|
-
|
37
|
+
alias_method :loadbot, :bot
|
27
38
|
|
28
39
|
# Get all of the bot's stats as if you just called DBL.bot(id)
|
29
40
|
# @return [Bot] the bot as a bot.
|
@@ -33,43 +44,68 @@ class DBLRuby
|
|
33
44
|
|
34
45
|
# Load a user
|
35
46
|
# @param id [Integer, String] Integer/String ID of the user you're requesting.
|
47
|
+
# @raise [DBLRuby::Errors::InvalidUser] if a 404 error is returned.
|
48
|
+
# @return [User] the new user object
|
36
49
|
def user(id)
|
37
|
-
|
50
|
+
url = "https://top.gg/api/users/#{id}"
|
51
|
+
data = JSON.parse(RestClient.get(url, Authorization: api))
|
52
|
+
User.new(data)
|
53
|
+
rescue RestClient::Unauthorized
|
54
|
+
raise DBLRuby::Errors::InvalidAPIKey,
|
55
|
+
'The API returned a 401 error, I believe your token is invalid.'
|
56
|
+
rescue RestClient::NotFound
|
57
|
+
raise DBLRuby::Errors::InvalidBot,
|
58
|
+
'The API returned a 404 error! Is that bot listed?'
|
38
59
|
end
|
39
60
|
|
40
|
-
|
61
|
+
alias_method :loaduser, :user
|
41
62
|
|
42
63
|
# Change the API key
|
43
|
-
# @param apikey [String] API Key of the bot, taken from the DBL.
|
44
64
|
attr_writer :api
|
45
65
|
|
46
|
-
|
47
|
-
|
48
|
-
|
66
|
+
alias_method :updateapikey, :api=
|
67
|
+
alias_method :updateapi, :api=
|
68
|
+
alias_method :apikey=, :api=
|
49
69
|
|
50
70
|
# Change the bot ID
|
51
|
-
# @param id [Integer, String] Integer/String of the bot's id.
|
52
71
|
attr_writer :id
|
53
72
|
|
54
|
-
|
73
|
+
alias_method :updateid, :id=
|
55
74
|
|
56
|
-
#
|
75
|
+
# The Weekend endpoint only really tells us if it's a weekend
|
76
|
+
# @see [weekend?] for a simplier version.
|
77
|
+
# @return [Weekend] the new Weekend object
|
57
78
|
def weekend
|
58
|
-
|
79
|
+
url = 'https://top.gg/api/weekend'
|
80
|
+
Weekend.new JSON.parse(RestClient.get(url))
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns true or false depending on if it's the "weekend"
|
84
|
+
# Weekend counts as 2 votes instead of one.
|
85
|
+
# @return [true, false] whether it's the weekend or not
|
86
|
+
def weekend?
|
87
|
+
weekend.weekend?
|
59
88
|
end
|
60
89
|
|
90
|
+
# Start a search
|
91
|
+
# @return [Search] the new search object
|
61
92
|
# @see Search#initialize
|
62
93
|
def search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil)
|
63
94
|
Search.new(search: search, limit: limit, offset: offset, sort: sort, fields: fields)
|
64
95
|
end
|
65
96
|
|
97
|
+
# @see Widget#initialize
|
98
|
+
def widget(size: 'large', file_type: 'png', small_type: nil, topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil, avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, id: @id)
|
99
|
+
Widget.new(size: size, file_type: file_type, small_type: small_type, topcolor: topcolor, middlecolor: middlecolor, usernamecolor: usernamecolor, certifiedcolor: certifiedcolor, datacolor: datacolor, labelcolor: labelcolor, highlightcolor: highlightcolor, avatarbg: avatarbg, leftcolor: leftcolor, rightcolor: rightcolor, lefttextcolor: lefttextcolor, righttextcolor: righttextcolor, id: id)
|
100
|
+
end
|
101
|
+
|
66
102
|
# Get the ID from instantiation
|
67
103
|
attr_reader :id
|
68
104
|
|
69
105
|
# Get the API Key from instantiation
|
70
106
|
attr_reader :api
|
71
107
|
|
72
|
-
|
108
|
+
alias_method :apikey, :api
|
73
109
|
end
|
74
110
|
|
75
111
|
# Require files.
|
@@ -79,3 +115,4 @@ require 'dblruby/user'
|
|
79
115
|
require 'dblruby/search'
|
80
116
|
require 'dblruby/stats'
|
81
117
|
require 'dblruby/weekend'
|
118
|
+
require 'dblruby/widget'
|
data/lib/dblruby/bot.rb
CHANGED
@@ -1,24 +1,15 @@
|
|
1
1
|
# Find information about bots.
|
2
2
|
class DBLRuby::Bot
|
3
3
|
# Initialize the bot
|
4
|
-
# @param
|
5
|
-
|
6
|
-
|
7
|
-
if id.nil?
|
8
|
-
@data = data
|
9
|
-
else
|
10
|
-
url = "https://discordbots.org/api/bots/#{id}"
|
11
|
-
@data = JSON.parse(RestClient.get(url))
|
12
|
-
end
|
13
|
-
rescue RestClient::NotFound
|
14
|
-
raise DBLRuby::Errors::InvalidBot,
|
15
|
-
'The API returned a 404 error! Is that bot listed?'
|
4
|
+
# @param data [JSON] Bot object in JSON form.
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
16
7
|
end
|
17
8
|
|
18
9
|
# @return data in raw json form.
|
19
10
|
attr_reader :data
|
20
11
|
|
21
|
-
|
12
|
+
alias_method :to_s, :data
|
22
13
|
|
23
14
|
# Return the error if there is one, nil otherwise.
|
24
15
|
# @return [String, nil] the error.
|
@@ -110,8 +101,8 @@ class DBLRuby::Bot
|
|
110
101
|
@data['discriminator']
|
111
102
|
end
|
112
103
|
|
113
|
-
|
114
|
-
|
104
|
+
alias_method :discrim, :discriminator
|
105
|
+
alias_method :tag, :discriminator
|
115
106
|
|
116
107
|
# The username of the bot.
|
117
108
|
# @return [String] the bot's username.
|
@@ -156,8 +147,8 @@ class DBLRuby::Bot
|
|
156
147
|
@data['server_count'].to_i
|
157
148
|
end
|
158
149
|
|
159
|
-
|
160
|
-
|
150
|
+
alias_method :guild_count, :server_count
|
151
|
+
alias_method :server, :server_count
|
161
152
|
|
162
153
|
# Get the bot's "This Bot Powers the following Servers"
|
163
154
|
# @return [Array<String>] the bot's guilds.
|
@@ -165,7 +156,7 @@ class DBLRuby::Bot
|
|
165
156
|
@data['guilds']
|
166
157
|
end
|
167
158
|
|
168
|
-
|
159
|
+
alias_method :servers, :guilds
|
169
160
|
|
170
161
|
# Get the bot's shards.
|
171
162
|
# @return [Array<String>] the bot's shards.
|
@@ -179,7 +170,7 @@ class DBLRuby::Bot
|
|
179
170
|
@data['monthlyPoints'].to_i
|
180
171
|
end
|
181
172
|
|
182
|
-
|
173
|
+
alias_method :monthlyvotes, :monthlypoints
|
183
174
|
|
184
175
|
# The amount of upvotes the bot has.
|
185
176
|
# @return [Integer] the bot's total points/votes.
|
@@ -187,7 +178,7 @@ class DBLRuby::Bot
|
|
187
178
|
@data['points'].to_i
|
188
179
|
end
|
189
180
|
|
190
|
-
|
181
|
+
alias_method :votes, :points
|
191
182
|
|
192
183
|
# The certified status of the bot.
|
193
184
|
# @return [true, false] the bot's certified status.
|
@@ -195,9 +186,9 @@ class DBLRuby::Bot
|
|
195
186
|
@data['certifiedBot']
|
196
187
|
end
|
197
188
|
|
198
|
-
|
199
|
-
|
200
|
-
|
189
|
+
alias_method :certifiedbot, :certified?
|
190
|
+
alias_method :certified, :certified?
|
191
|
+
alias_method :certifiedbot?, :certified?
|
201
192
|
|
202
193
|
# The owners of the bot. First one in the array is the main owner.
|
203
194
|
# @return [Array<String>] the bot's owners in an array.
|
@@ -217,5 +208,5 @@ class DBLRuby::Bot
|
|
217
208
|
@data['donatebotguildid']
|
218
209
|
end
|
219
210
|
|
220
|
-
|
211
|
+
alias_method :donatebotserverid, :donatebotguildid
|
221
212
|
end
|
data/lib/dblruby/errors.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# Errors are cool.
|
2
2
|
module DBLRuby::Errors
|
3
|
-
#
|
3
|
+
# Raised if a 404 error is returned in #bot
|
4
4
|
class InvalidBot < RuntimeError; end
|
5
5
|
|
6
|
-
#
|
6
|
+
# Raised if a 404 error is returned in #user
|
7
7
|
class InvalidUser < RuntimeError; end
|
8
8
|
|
9
|
-
#
|
9
|
+
# Raised if a 401 unauthorized error is returned in stats.
|
10
10
|
class InvalidAPIKey < RuntimeError; end
|
11
11
|
|
12
|
-
#
|
12
|
+
# Raised if a 404 unknown error is returned in stats.
|
13
13
|
class InvalidID < RuntimeError; end
|
14
|
+
|
15
|
+
# Rasied if an invalid Widget parameter is specified
|
16
|
+
class InvalidWidget < RuntimeError; end
|
14
17
|
end
|
data/lib/dblruby/search.rb
CHANGED
data/lib/dblruby/stats.rb
CHANGED
@@ -12,19 +12,19 @@ class DBLRuby::Stats
|
|
12
12
|
# @raise [DBLRuby::Errors::InvalidID] if the DBL returns a 404 error.
|
13
13
|
def servercount
|
14
14
|
url = "https://discordbots.org/api/bots/#{@id}"
|
15
|
-
JSON.parse(RestClient.get(url))['server_count'].to_i
|
15
|
+
JSON.parse(RestClient.get(url, Authorization: @api))['server_count'].to_i
|
16
16
|
rescue RestClient::NotFound
|
17
17
|
raise DBLRuby::Errors::InvalidID,
|
18
18
|
'DBL Returned a 404 unknown error! Did you enter the correct ID?'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
alias_method :servers, :servercount
|
22
22
|
|
23
23
|
# Update the bot's server count.
|
24
|
-
# @param count [Integer
|
24
|
+
# @param count [Integer] Integer/String of bot server count.
|
25
25
|
# @param shard_id [Integer] ID of the shard
|
26
26
|
# @param shard_count [Integer] amount of shards the bot has.
|
27
|
-
# @raise [DBLRuby::Errors::InvalidAPIKey] if
|
27
|
+
# @raise [DBLRuby::Errors::InvalidAPIKey] if DBL returns a 401 error.
|
28
28
|
# @return The count of the servers.
|
29
29
|
def updateservercount(count, shard_id = nil, shard_count = nil)
|
30
30
|
url = "https://discordbots.org/api/bots/#{@id}/stats"
|
@@ -40,7 +40,7 @@ class DBLRuby::Stats
|
|
40
40
|
'There was an error posting stats to the DBL. Is your API key ok?'
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
alias_method :servers=, :updateservercount
|
44
44
|
|
45
45
|
# Check to see if a user really voted, via an ID.
|
46
46
|
# @param id [Integer, String] Integer/String ID of user you're requesting.
|
data/lib/dblruby/user.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
# Find information about users.
|
2
2
|
class DBLRuby::User
|
3
3
|
# Initialize the user
|
4
|
-
# @param
|
5
|
-
|
6
|
-
|
7
|
-
url = "https://discordbots.org/api/users/#{id}"
|
8
|
-
@data = JSON.parse(RestClient.get(url))
|
9
|
-
rescue RestClient::NotFound
|
10
|
-
raise DBLRuby::Errors::InvalidUser,
|
11
|
-
'The API returned a 404 error! Does that user exist?'
|
4
|
+
# @param data [JSON] User object in JSON form.
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
12
7
|
end
|
13
8
|
|
14
9
|
# @return data in raw json form.
|
15
10
|
attr_reader :data
|
16
11
|
|
17
|
-
|
12
|
+
alias_method :to_s, :data
|
18
13
|
|
19
14
|
# Return the error if there is one, nil otherwise.
|
20
15
|
# @return [String, nil] the error.
|
@@ -43,11 +38,11 @@ class DBLRuby::User
|
|
43
38
|
# The discriminator of the user.
|
44
39
|
# @return [Integer] the user's discriminator without the #.
|
45
40
|
def discriminator
|
46
|
-
@data['discriminator'].delete('#')
|
41
|
+
@data['discriminator'].delete('#')
|
47
42
|
end
|
48
43
|
|
49
|
-
|
50
|
-
|
44
|
+
alias_method :discrim, :discriminator
|
45
|
+
alias_method :tag, :discriminator
|
51
46
|
|
52
47
|
# Returns the user's distinct, which is the Username and Discriminator.
|
53
48
|
# @return [String] the user's username + discrim.
|
@@ -86,7 +81,7 @@ class DBLRuby::User
|
|
86
81
|
end
|
87
82
|
|
88
83
|
# The social usernames of the user.
|
89
|
-
# @return [
|
84
|
+
# @return [Hash<String, String>] the user's social links.
|
90
85
|
def social
|
91
86
|
@data['social']
|
92
87
|
end
|
@@ -94,7 +89,7 @@ class DBLRuby::User
|
|
94
89
|
# Does the user have any social links? True if so, false if not.
|
95
90
|
# @return [true, false] if the user has any social links.
|
96
91
|
def social?
|
97
|
-
|
92
|
+
@data['social'] != {}
|
98
93
|
end
|
99
94
|
|
100
95
|
# The youtube channel id of the user.
|
@@ -133,7 +128,7 @@ class DBLRuby::User
|
|
133
128
|
@data['color']
|
134
129
|
end
|
135
130
|
|
136
|
-
|
131
|
+
alias_method :colour, :color
|
137
132
|
|
138
133
|
# The supporter status of the user.
|
139
134
|
# @return [true, false] the user's supporter status.
|
@@ -141,7 +136,7 @@ class DBLRuby::User
|
|
141
136
|
@data['supporter']
|
142
137
|
end
|
143
138
|
|
144
|
-
|
139
|
+
alias_method :supporter, :supporter?
|
145
140
|
|
146
141
|
# The certified status of the user.
|
147
142
|
# @return [true, false] the user's certified status.
|
@@ -149,9 +144,9 @@ class DBLRuby::User
|
|
149
144
|
@data['certifiedDev']
|
150
145
|
end
|
151
146
|
|
152
|
-
|
153
|
-
|
154
|
-
|
147
|
+
alias_method :certified, :certified?
|
148
|
+
alias_method :certifieddev, :certified
|
149
|
+
alias_method :certifieddev?, :certified
|
155
150
|
|
156
151
|
# The mod status of the user.
|
157
152
|
# @return [true, false] the user's mod status.
|
@@ -159,7 +154,7 @@ class DBLRuby::User
|
|
159
154
|
@data['mod']
|
160
155
|
end
|
161
156
|
|
162
|
-
|
157
|
+
alias_method :mod, :mod?
|
163
158
|
|
164
159
|
# The website moderator status of the user.
|
165
160
|
# @return [true, false] the user's website mod status.
|
@@ -167,7 +162,7 @@ class DBLRuby::User
|
|
167
162
|
@data['webMod']
|
168
163
|
end
|
169
164
|
|
170
|
-
|
165
|
+
alias_method :webmod, :webmod?
|
171
166
|
|
172
167
|
# The admin status of the user.
|
173
168
|
# @return [true, false] the user's admin status.
|
@@ -175,5 +170,5 @@ class DBLRuby::User
|
|
175
170
|
@data['admin']
|
176
171
|
end
|
177
172
|
|
178
|
-
|
173
|
+
alias_method :admin, :admin?
|
179
174
|
end
|
data/lib/dblruby/weekend.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Find information about the weekend.
|
2
2
|
class DBLRuby::Weekend
|
3
3
|
# Initialize the weekend
|
4
|
-
|
5
|
-
|
6
|
-
@data =
|
4
|
+
# @param data [JSON] the weekend response in JSON form
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
7
|
end
|
8
8
|
|
9
9
|
# @return data in raw json form.
|
10
10
|
attr_reader :data
|
11
11
|
|
12
|
-
|
12
|
+
alias_method :to_s, :data
|
13
13
|
|
14
14
|
# Return the whether it's the weekend.
|
15
15
|
# @return [true, false] the weekend status.
|
@@ -17,5 +17,5 @@ class DBLRuby::Weekend
|
|
17
17
|
@data['is_weekend']
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
alias_method :isweekend, :weekend?
|
21
21
|
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Make a widget
|
2
|
+
class DBLRuby::Widget
|
3
|
+
BASE_URL = 'https://discordbots.org/api/widget/'.freeze
|
4
|
+
|
5
|
+
# Make a new widget
|
6
|
+
# @param size ['large', 'small'] The size of the widget.
|
7
|
+
# @param file_type ['png', 'svg'] The file type of the image
|
8
|
+
# @param small_type ['owner', 'status', 'upvotes', 'servers', 'lib'] The type of small widget.
|
9
|
+
# @param topcolor [Hexadecimal] The top color of the widget (Large)
|
10
|
+
# @param middlecolor [Hexadecimal] The middle color of the widget (Large)
|
11
|
+
# @param usernamecolor [Hexadecimal] The username color of the widget (Large)
|
12
|
+
# @param certifiedcolor [Hexadecimal] The certified color of the widget (Large)
|
13
|
+
# @param datacolor [Hexadecimal] The data color of the widget (Large)
|
14
|
+
# @param labelcolor [Hexadecimal] The label color of the widget (Large)
|
15
|
+
# @param highlightcolor [Hexadecimal] The highlight color of the widget (Large)
|
16
|
+
# @param avatarbg [Hexadecimal] The avatar background color of the widget (Small)
|
17
|
+
# @param leftcolor [Hexadecimal] The left color of the widget (Small)
|
18
|
+
# @param rightcolor [Hexadecimal] The right color of the widget (Small)
|
19
|
+
# @param lefttextcolor [Hexadecimal] The left text color of the widget (Small)
|
20
|
+
# @param righttextcolor [Hexadecimal] The right text color of the widget (Small)
|
21
|
+
# @param noavatar [true, false] Whether there should be an avatar (Small)
|
22
|
+
def initialize(size: 'large', file_type: 'png',
|
23
|
+
small_type: nil,
|
24
|
+
topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil,
|
25
|
+
avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, noavatar: nil,
|
26
|
+
id: nil)
|
27
|
+
@size = size
|
28
|
+
@file_type = file_type
|
29
|
+
@small_type = small_type
|
30
|
+
@topcolor = topcolor
|
31
|
+
@middlecolor = middlecolor
|
32
|
+
@usernamecolor = usernamecolor
|
33
|
+
@certifiedcolor = certifiedcolor
|
34
|
+
@datacolor = datacolor
|
35
|
+
@labelcolor = labelcolor
|
36
|
+
@highlightcolor = highlightcolor
|
37
|
+
@avatarbg = avatarbg
|
38
|
+
@leftcolor = leftcolor
|
39
|
+
@rightcolor = rightcolor
|
40
|
+
@lefttextcolor = lefttextcolor
|
41
|
+
@righttextcolor = righttextcolor
|
42
|
+
@noavatar = noavatar
|
43
|
+
@id = id
|
44
|
+
|
45
|
+
raise DBLRuby::Errors::InvalidWidget, 'Small size specified but no small type was provided' if @size == 'small' && @small_type.nil?
|
46
|
+
raise DBLRuby::Errors::InvalidWidget, 'Small parameter specified for large widget' if @size == 'large' && (!@avatarbg.nil? || !@leftcolor.nil? || !@rightcolor.nil? || !@lefttextcolor.nil? || !@righttextcolor.nil? || !@noavatar.nil?)
|
47
|
+
raise DBLRuby::Errors::InvalidWidget, 'Large parameter specified for small widget' if @size == 'small' && (!@topcolor.nil? || !@middlecolor.nil? || !@usernamecolor.nil? || !@certifiedcolor.nil? || !@datacolor.nil? || !@labelcolor.nil? || !@highlightcolor.nil?)
|
48
|
+
|
49
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? @size
|
50
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(@small_type)
|
51
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? @file_type
|
52
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' if !@noavatar.nil? && !%w[true false].include?(@noavatar)
|
53
|
+
end
|
54
|
+
|
55
|
+
def size=(size)
|
56
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? size
|
57
|
+
|
58
|
+
@size = size
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_type=(file_type)
|
62
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? file_type
|
63
|
+
|
64
|
+
@file_type = file_type
|
65
|
+
end
|
66
|
+
|
67
|
+
def small_type=(small_type)
|
68
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(small_type)
|
69
|
+
|
70
|
+
@small_type = small_type
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_writer :topcolor
|
74
|
+
attr_writer :middlecolor
|
75
|
+
attr_writer :usernamecolor
|
76
|
+
attr_writer :certifiedcolor
|
77
|
+
attr_writer :datacolor
|
78
|
+
attr_writer :labelcolor
|
79
|
+
attr_writer :highlightcolor
|
80
|
+
attr_writer :avatarbg
|
81
|
+
attr_writer :leftcolor
|
82
|
+
attr_writer :rightcolor
|
83
|
+
attr_writer :lefttextcolor
|
84
|
+
attr_writer :righttextcolor
|
85
|
+
|
86
|
+
def noavatar=(noavatar)
|
87
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' unless %w[true false].include? noavatar
|
88
|
+
|
89
|
+
@noavatar = noavatar
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [String] The URL, ready for linking.
|
93
|
+
def url
|
94
|
+
params = []
|
95
|
+
if @size == 'large'
|
96
|
+
params.push("topcolor=#{@topcolor}") unless @topcolor.nil?
|
97
|
+
params.push("middlecolor=#{@middlecolor}") unless @middlecolor.nil?
|
98
|
+
params.push("usernamecolor=#{@usernamecolor}") unless @usernamecolor.nil?
|
99
|
+
params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil?
|
100
|
+
params.push("datacolor=#{@datacolor}") unless @datacolor.nil?
|
101
|
+
params.push("labelcolor=#{@labelcolor}") unless @labelcolor.nil?
|
102
|
+
params.push("highlightcolor=#{@highlightcolor}") unless @highlightcolor.nil?
|
103
|
+
output = "#{BASE_URL}#{@id}.#{@file_type}"
|
104
|
+
elsif @size == 'small'
|
105
|
+
params.push("avatarbg=#{@avatarbg}") unless @avatarbg.nil?
|
106
|
+
params.push("leftcolor=#{@leftcolor}") unless @leftcolor.nil?
|
107
|
+
params.push("rightcolor=#{@rightcolor}") unless @rightcolor.nil?
|
108
|
+
params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil?
|
109
|
+
params.push("lefttextcolor=#{@lefttextcolor}") unless @lefttextcolor.nil?
|
110
|
+
params.push("righttextcolor=#{@labelcolor}") unless @righttextcolor.nil?
|
111
|
+
params.push("noavatar=#{@noavatar}") unless @noavatar.nil?
|
112
|
+
output = "#{BASE_URL}#{@small_type}/#{@id}.#{@file_type}"
|
113
|
+
end
|
114
|
+
output += "?#{params.join('&')}" unless params.length.zero?
|
115
|
+
output
|
116
|
+
end
|
117
|
+
|
118
|
+
alias_method :to_s, :url
|
119
|
+
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Chew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,29 +38,30 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.1.0.rc1
|
41
|
-
description: A Ruby library for the
|
41
|
+
description: A Ruby library for the Top.gg (https://top.gg) API.
|
42
42
|
email: chew@chew.pw
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
47
|
- lib/dblruby.rb
|
48
|
-
- lib/dblruby/api.rb
|
49
48
|
- lib/dblruby/bot.rb
|
50
49
|
- lib/dblruby/errors.rb
|
51
50
|
- lib/dblruby/search.rb
|
52
51
|
- lib/dblruby/stats.rb
|
53
52
|
- lib/dblruby/user.rb
|
54
53
|
- lib/dblruby/weekend.rb
|
55
|
-
|
54
|
+
- lib/dblruby/widget.rb
|
55
|
+
homepage: https://github.com/Chew/DBLRuby
|
56
56
|
licenses:
|
57
57
|
- MIT
|
58
58
|
metadata:
|
59
|
-
bug_tracker_uri: https://github.com/
|
60
|
-
changelog_uri: https://github.com/
|
61
|
-
homepage_uri: http://github.com/
|
62
|
-
source_code_uri: http://github.com/
|
63
|
-
wiki_uri: http://github.com/
|
59
|
+
bug_tracker_uri: https://github.com/Chew/DBLRuby/issues
|
60
|
+
changelog_uri: https://github.com/Chew/DBLRuby/releases
|
61
|
+
homepage_uri: http://github.com/Chew/DBLRuby
|
62
|
+
source_code_uri: http://github.com/Chew/DBLRuby
|
63
|
+
wiki_uri: http://github.com/Chew/DBLRuby/wiki
|
64
|
+
documentation_uri: https://rubydocs.chew.pro/docs/dblruby
|
64
65
|
post_install_message:
|
65
66
|
rdoc_options: []
|
66
67
|
require_paths:
|
@@ -76,9 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.6.14
|
80
|
+
rubygems_version: 3.0.6
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
|
-
summary: Discord Bot List API for Ruby
|
83
|
+
summary: Top.gg / Discord Bot List API for Ruby
|
84
84
|
test_files: []
|
data/lib/dblruby/api.rb
DELETED