dblruby 1.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2aa21e5c1f30bbad1a967215c20de21d90dfbec95f09f036fec45761b522f5bf
4
- data.tar.gz: 1e951b5136cc05b88d5c476fc802b455cb566e1f66cd87e203e1ad8580632b11
3
+ metadata.gz: 1e6da53133ead002925bdd344bb9367f2f979dd4b2ab5f1232f2c6e2bd0b46d4
4
+ data.tar.gz: 340bf140b1aea90cf31dab26088c95235e444038940906645f028261ede5954b
5
5
  SHA512:
6
- metadata.gz: 803a3e6d36405413cb753efac90a7cd9ca9b51180534b15ec3f746cbf4448463273f73b2910fc2b1bf5e62524a3b2e683173e11b4ebedc10d1a44b009ad5796b
7
- data.tar.gz: 2becd6fac4539ecd073ad8135d5c8ae9988ee3c08ed39d7e54c7e2799936e1253aadbe46ad73e109159407cfc92729f00c45acdacd3e5329731a9edef771f858
6
+ metadata.gz: 45c19410d54c87abdf52b19d805533f4c64d39b1ef23f8090c838a1a986e02da771dd52757419023761bedf2eb0da644f30cd960a9f07a6954012e892defd025
7
+ data.tar.gz: fafde3a5a440c066f74bf52ff171a21dafcb8f9279d89172a7ab32aa057729f115fc870ca7b29c8da18873af4f45e3e8481cf4b99567074ec3a250ebf96979d4
@@ -13,14 +13,25 @@ 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
- Bot.new(id: id, api: @api)
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
@@ -33,14 +44,23 @@ 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
- User.new(id, api)
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
66
  alias_method :updateapikey, :api=
@@ -48,21 +68,27 @@ class DBLRuby
48
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
- # Define weekend
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
- Weekend.new
79
+ url = 'https://top.gg/api/weekend'
80
+ Weekend.new JSON.parse(RestClient.get(url))
59
81
  end
60
82
 
61
- # Skip the middleman, let's just see if it's the weekend!
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
62
86
  def weekend?
63
87
  weekend.weekend?
64
88
  end
65
89
 
90
+ # Start a search
91
+ # @return [Search] the new search object
66
92
  # @see Search#initialize
67
93
  def search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil)
68
94
  Search.new(search: search, limit: limit, offset: offset, sort: sort, fields: fields)
@@ -1,18 +1,9 @@
1
1
  # Find information about bots.
2
2
  class DBLRuby::Bot
3
3
  # Initialize the bot
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.
6
- def initialize(id: nil, data: nil, api: nil)
7
- if id.nil?
8
- @data = data
9
- else
10
- url = "https://discordbots.org/api/bots/#{id}"
11
- @data = JSON.parse(RestClient.get(url, Authorization: api))
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.
@@ -1,14 +1,9 @@
1
1
  # Find information about users.
2
2
  class DBLRuby::User
3
3
  # Initialize the user
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.
6
- def initialize(id, api)
7
- url = "https://discordbots.org/api/users/#{id}"
8
- @data = JSON.parse(RestClient.get(url, Authorization: api))
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.
@@ -86,7 +81,7 @@ class DBLRuby::User
86
81
  end
87
82
 
88
83
  # The social usernames of the user.
89
- # @return [Array<String>] the user's social links.
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
- !@data['social'].nil?
92
+ @data['social'] != {}
98
93
  end
99
94
 
100
95
  # The youtube channel id of the user.
@@ -1,9 +1,9 @@
1
1
  # Find information about the weekend.
2
2
  class DBLRuby::Weekend
3
3
  # Initialize the weekend
4
- def initialize
5
- url = 'https://discordbots.org/api/weekend'
6
- @data = JSON.parse(RestClient.get(url))
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.
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.1.3
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: 2019-04-22 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.1.0.rc1
41
- description: A Ruby library for the Discord Bot List (https://discordbots.org) API.
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: []
@@ -61,6 +61,7 @@ metadata:
61
61
  homepage_uri: http://github.com/Chew/DBLRuby
62
62
  source_code_uri: http://github.com/Chew/DBLRuby
63
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,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  - !ruby/object:Gem::Version
77
78
  version: '0'
78
79
  requirements: []
79
- rubygems_version: 3.0.2
80
+ rubygems_version: 3.0.6
80
81
  signing_key:
81
82
  specification_version: 4
82
- summary: Discord Bot List API for Ruby
83
+ summary: Top.gg / Discord Bot List API for Ruby
83
84
  test_files: []