dblruby 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dblruby.rb +20 -0
- data/lib/dblruby/bot.rb +5 -0
- data/lib/dblruby/errors.rb +9 -0
- data/lib/dblruby/stats.rb +10 -0
- data/lib/dblruby/user.rb +3 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4680057787917a041e0979551c47c6e4cdc9f10
|
4
|
+
data.tar.gz: 56b41a0ad44a2b4ec64f59db28ab4bdfbb5331ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9821d6aae9167946d150889deb2a540caed370976dd26fff9381374d7dc35e78828c05b63baf1864e8690ed109562ad2a6369163ea7eb301b04de57e0f12958
|
7
|
+
data.tar.gz: 5fa58dd63c36bcde3b661c485dd7d78af563f81baac35e3b66bc9643fe75e583c485fe5b52b2bbdfa810924312dd9b008998976a778995522260f27c591d4df8
|
data/lib/dblruby.rb
CHANGED
@@ -30,6 +30,26 @@ class DBLRuby
|
|
30
30
|
@user = User.new(id)
|
31
31
|
end
|
32
32
|
|
33
|
+
# Change the API key
|
34
|
+
# @param apikey [String] API Key of the bot, taken from the DBL.
|
35
|
+
def updateapi(apikey)
|
36
|
+
@api = apikey
|
37
|
+
makestats
|
38
|
+
end
|
39
|
+
|
40
|
+
alias updateapikey updateapi
|
41
|
+
alias api= updateapi
|
42
|
+
alias apikey= updateapi
|
43
|
+
|
44
|
+
# Change the bot ID
|
45
|
+
# @param id [Integer, String] Integer/String of the bot's id.
|
46
|
+
def updateid(id)
|
47
|
+
@id = id
|
48
|
+
makestats
|
49
|
+
end
|
50
|
+
|
51
|
+
alias id= updateid
|
52
|
+
|
33
53
|
# Get the ID from instantiation
|
34
54
|
attr_reader :id
|
35
55
|
|
data/lib/dblruby/bot.rb
CHANGED
@@ -5,11 +5,16 @@ class DBLRuby::Bot
|
|
5
5
|
def initialize(id)
|
6
6
|
url = "https://discordbots.org/api/bots/#{id}"
|
7
7
|
@data = JSON.parse(RestClient.get(url))
|
8
|
+
rescue RestClient::NotFound
|
9
|
+
raise DBLRuby::Errors::InvalidBot,
|
10
|
+
'The API returned a 404 error! Is that bot listed?'
|
8
11
|
end
|
9
12
|
|
10
13
|
# @return data in raw json form.
|
11
14
|
attr_reader :data
|
12
15
|
|
16
|
+
alias to_s data
|
17
|
+
|
13
18
|
# Get the bot's invite link.
|
14
19
|
# @return [String] the bot's invite link.
|
15
20
|
def invite
|
data/lib/dblruby/errors.rb
CHANGED
@@ -2,4 +2,13 @@
|
|
2
2
|
module DBLRuby::Errors
|
3
3
|
# Ran if No Data is returned.
|
4
4
|
class NoData < RuntimeError; end
|
5
|
+
|
6
|
+
# Ran if a 404 error is returned in #loadbot
|
7
|
+
class InvalidBot < RuntimeError; end
|
8
|
+
|
9
|
+
# Ran if a 404 error is returned in #loaduser
|
10
|
+
class InvalidUser < RuntimeError; end
|
11
|
+
|
12
|
+
# Ran if a 401 unauthorized error is returned in stats.
|
13
|
+
class InvalidAPIKey < RuntimeError; end
|
5
14
|
end
|
data/lib/dblruby/stats.rb
CHANGED
@@ -14,6 +14,8 @@ class DBLRuby::Stats
|
|
14
14
|
JSON.parse(RestClient.get(url))['server_count'].to_i
|
15
15
|
end
|
16
16
|
|
17
|
+
alias servers servercount
|
18
|
+
|
17
19
|
# Update the bot's server count.
|
18
20
|
# @param id [Integer, String] Integer/String ID of bot server count.
|
19
21
|
def updateservercount(count)
|
@@ -21,8 +23,13 @@ class DBLRuby::Stats
|
|
21
23
|
json = '{"server_count":' + count.to_s + '}'
|
22
24
|
RestClient.post(url, json, :Authorization => @api, :'Content-Type' => :json)
|
23
25
|
"Successfully set the server count to #{count}"
|
26
|
+
rescue RestClient::Unauthorized
|
27
|
+
raise DBLRuby::Errors::InvalidAPIKey,
|
28
|
+
'There was an error posting stats to the DBL. Is your API key ok?'
|
24
29
|
end
|
25
30
|
|
31
|
+
alias servers= updateservercount
|
32
|
+
|
26
33
|
# Check to see if a user really voted, via an ID.
|
27
34
|
# @param id [Integer, String] Integer/String ID of user you're requesting.
|
28
35
|
# @return [true, false] if the user voted or not.
|
@@ -33,5 +40,8 @@ class DBLRuby::Stats
|
|
33
40
|
:'Content-Type' => :json)
|
34
41
|
o = JSON.parse(r)['voted'].to_i
|
35
42
|
!o.zero?
|
43
|
+
rescue RestClient::Unauthorized
|
44
|
+
raise DBLRuby::Errors::InvalidAPIKey,
|
45
|
+
'There was an error posting stats to the DBL. Is your API key ok?'
|
36
46
|
end
|
37
47
|
end
|
data/lib/dblruby/user.rb
CHANGED
@@ -5,6 +5,9 @@ class DBLRuby::User
|
|
5
5
|
def initialize(id)
|
6
6
|
url = "https://discordbots.org/api/users/#{id}"
|
7
7
|
@data = JSON.parse(RestClient.get(url))
|
8
|
+
rescue RestClient::NotFound
|
9
|
+
raise DBLRuby::Errors::InvalidUser,
|
10
|
+
'The API returned a 404 error! Does that user exist?'
|
8
11
|
end
|
9
12
|
|
10
13
|
# @return data in raw json form.
|
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.1.0.rc1
|
27
|
-
description: A
|
27
|
+
description: A Ruby library for the Discord Bot List (https://discordbots.org) API.
|
28
28
|
email: chew@chew.pw
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -47,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: 2.2.4
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
@@ -58,5 +58,5 @@ rubyforge_project:
|
|
58
58
|
rubygems_version: 2.6.8
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
|
-
summary:
|
61
|
+
summary: Discord Bot List API for Ruby
|
62
62
|
test_files: []
|