dblruby 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb8d3b753f0486f2d09ced6e5d2432c9b32584f4
4
- data.tar.gz: 6dc1ecdaa199560d8b73925655eadd21971464a5
3
+ metadata.gz: 26976efdbb810637c0f47ae21edb5905ae183644
4
+ data.tar.gz: a3efa28a57d5b232f41b2e129c8cde8ead7d7c20
5
5
  SHA512:
6
- metadata.gz: d1b02c1db54e67035b893409743f8019575aff2354d956c7ebf5346c128826ae0d74182ccd1ff007bb90b3a68708e83093eb1431a7a64349b49a292163416ca5
7
- data.tar.gz: ea700ba043738911c3fd51a8718bec70420d3dbffe3dfeeaaf3c175d49070d311442332faac546fbf6f6b945e5b4d23558f0a2198b35f970f07b9ee841845a95
6
+ metadata.gz: 318b638e5f13794dd4558ead75598248b32786cbd64be498711505e4ee5eaef8c72b11803dc861c5e144176ccdc18d5ac2693ae379746d635be85b31cb47c640
7
+ data.tar.gz: 734a9d1f29f2ed8364f3648e75cc60d4fe82f2ea0dcf799a61a9bfbf547e4102ca26f1cf417b7d04f391f058774d8ca00e26084d1cbc21bf5ec9a2847dac3caa
@@ -10,45 +10,58 @@ class DBLRuby
10
10
  def initialize(apikey, id)
11
11
  @api = apikey
12
12
  @id = id
13
- makestats
14
13
  end
15
14
 
16
15
  # Initialize stats
17
- def makestats
18
- @stats = Stats.new(@api, @id)
16
+ def stats
17
+ Stats.new(@api, @id)
19
18
  end
20
19
 
21
20
  # Load a bot.
22
21
  # @param id [Integer, String] Integer/String ID of the bot you're requesting.
23
- def loadbot(id)
24
- @bot = Bot.new(id)
22
+ def bot(id)
23
+ Bot.new(id: id)
24
+ end
25
+
26
+ alias loadbot bot
27
+
28
+ # Get all of the bot's stats as if you just called DBL.bot(id)
29
+ # @return [Bot] the bot as a bot.
30
+ def self
31
+ bot(@id)
25
32
  end
26
33
 
27
34
  # Load a user
28
35
  # @param id [Integer, String] Integer/String ID of the user you're requesting.
29
- def loaduser(id)
30
- @user = User.new(id)
36
+ def user(id)
37
+ User.new(id)
31
38
  end
32
39
 
40
+ alias loaduser user
41
+
33
42
  # Change the API key
34
43
  # @param apikey [String] API Key of the bot, taken from the DBL.
35
- def updateapi(apikey)
36
- @api = apikey
37
- makestats
38
- end
44
+ attr_writer :api
39
45
 
40
- alias updateapikey updateapi
41
- alias api= updateapi
42
- alias apikey= updateapi
46
+ alias updateapikey api=
47
+ alias updateapi api=
48
+ alias apikey= api=
43
49
 
44
50
  # Change the bot ID
45
51
  # @param id [Integer, String] Integer/String of the bot's id.
46
- def updateid(id)
47
- @id = id
48
- makestats
52
+ attr_writer :id
53
+
54
+ alias updateid id=
55
+
56
+ # Define weekend
57
+ def weekend
58
+ Weekend.new
49
59
  end
50
60
 
51
- alias id= updateid
61
+ # @see Search#initialize
62
+ def search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil)
63
+ Search.new(search: search, limit: limit, offset: offset, sort: sort, fields: fields)
64
+ end
52
65
 
53
66
  # Get the ID from instantiation
54
67
  attr_reader :id
@@ -57,15 +70,12 @@ class DBLRuby
57
70
  attr_reader :api
58
71
 
59
72
  alias apikey api
60
-
61
- attr_reader :bot
62
- attr_reader :user
63
- attr_reader :stats
64
73
  end
65
74
 
66
75
  # Require files.
67
- require 'dblruby/api'
68
76
  require 'dblruby/bot'
69
77
  require 'dblruby/errors'
70
78
  require 'dblruby/user'
79
+ require 'dblruby/search'
71
80
  require 'dblruby/stats'
81
+ require 'dblruby/weekend'
@@ -3,9 +3,13 @@ class DBLRuby::Bot
3
3
  # Initialize the bot
4
4
  # @param id [Integer, String] Integer/String ID of bot you're requesting.
5
5
  # @raise [DBLRuby::Errors::InvalidBot] if the DBL returns a 404 error.
6
- def initialize(id)
7
- url = "https://discordbots.org/api/bots/#{id}"
8
- @data = JSON.parse(RestClient.get(url))
6
+ def initialize(id: nil, data: 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))
12
+ end
9
13
  rescue RestClient::NotFound
10
14
  raise DBLRuby::Errors::InvalidBot,
11
15
  'The API returned a 404 error! Is that bot listed?'
@@ -101,9 +105,9 @@ class DBLRuby::Bot
101
105
  end
102
106
 
103
107
  # The discriminator of the bot.
104
- # @return [Integer] the bot's discriminator without the #.
108
+ # @return [String] the bot's discriminator.
105
109
  def discriminator
106
- @data['discriminator'].delete('#').to_i
110
+ @data['discriminator']
107
111
  end
108
112
 
109
113
  alias discrim discriminator
@@ -187,13 +191,13 @@ class DBLRuby::Bot
187
191
 
188
192
  # The certified status of the bot.
189
193
  # @return [true, false] the bot's certified status.
190
- def certifiedbot
194
+ def certified?
191
195
  @data['certifiedBot']
192
196
  end
193
197
 
194
- alias certified? certifiedbot
195
- alias certified certifiedbot
196
- alias certifiedbot? certifiedbot
198
+ alias certifiedbot certified?
199
+ alias certified certified?
200
+ alias certifiedbot? certified?
197
201
 
198
202
  # The owners of the bot. First one in the array is the main owner.
199
203
  # @return [Array<String>] the bot's owners in an array.
@@ -207,17 +211,11 @@ class DBLRuby::Bot
207
211
  @data['tags']
208
212
  end
209
213
 
210
- # The vanity url of the bot.
211
- # @return [String] the bot's vanity url.
212
- def vanity
213
- @data['vanity']
214
+ # Get the bot's donate bot guild ID.
215
+ # @return [String] the bot's donate bot guild ID.
216
+ def donatebotguildid
217
+ @data['donatebotguildid']
214
218
  end
215
219
 
216
- # Get the bot's legacy status.
217
- # @return [true, false] the bot's legacy status.
218
- def legacy
219
- @data['legacy']
220
- end
221
-
222
- alias legacy? legacy
220
+ alias donatebotserverid donatebotguildid
223
221
  end
@@ -0,0 +1,92 @@
1
+ # A search for the bots
2
+ class DBLRuby::Search
3
+ # Start a new search
4
+ # @param limit [Integer] The amount of bots to return. Max. 500
5
+ # @param offset [Integer] Amount of bots to skip
6
+ # @param search [String] A search string in the format of field: value field2: value2
7
+ # @param sort [String] The field to sort by. Prefix with - to reverse the order
8
+ # @param fields [String] A comma separated list of fields to show.
9
+ def initialize(search: nil, limit: 50, offset: 0, sort: nil, fields: nil)
10
+ url = 'https://discordbots.org/api/bots'
11
+ @search = search
12
+ @limit = limit
13
+ @offset = offset
14
+ @sort = sort
15
+ @fields = fields
16
+ @data = JSON.parse(RestClient.get(url, params: { search: search,
17
+ limit: limit,
18
+ offset: offset,
19
+ sort: sort,
20
+ fields: fields }))
21
+ end
22
+
23
+ # @return data in raw json form.
24
+ attr_reader :data
25
+
26
+ alias to_s data
27
+
28
+ # @return [String] the search query
29
+ attr_reader :search
30
+
31
+ # @return [Integer] the limit query
32
+ attr_reader :limit
33
+
34
+ # @return [Integer] the offset query
35
+ attr_reader :offset
36
+
37
+ # @return [String] the sort query
38
+ attr_reader :sort
39
+
40
+ # @return [String] the fields query
41
+ attr_reader :fields
42
+
43
+ # The amount of results returned
44
+ # @return [String] The amount of bots
45
+ # @see #count
46
+ def size
47
+ @data['results'].length
48
+ end
49
+
50
+ # Gets all the bots
51
+ # @return [Array<Bot>] a list of the bots
52
+ def results
53
+ output = Array.new(size)
54
+ cur = 0
55
+ @data['results'].each do |e|
56
+ output[cur] = DBLRuby::Bot.new(data: e)
57
+ cur += 1
58
+ end
59
+ output
60
+ end
61
+
62
+ # Return only the first bot
63
+ # @return [Bot] the first bot.
64
+ def first
65
+ DBLRuby::Bot.new(data: @data['results'][0])
66
+ end
67
+
68
+ # Get the next page
69
+ # @return [Search] next page of results
70
+ def next
71
+ DBLRuby::Search.new(
72
+ search: search,
73
+ limit: limit,
74
+ offset: limit + offset,
75
+ sort: sort,
76
+ fields: fields
77
+ )
78
+ end
79
+
80
+ # Get the bot count in this result
81
+ # @return [Integer] total bots returned
82
+ # @see #size
83
+ def count
84
+ @data['count']
85
+ end
86
+
87
+ # Get the total possible amount of bots there are for this query
88
+ # @return [Integer] the total amount of bots
89
+ def total
90
+ @data['total']
91
+ end
92
+ end
@@ -0,0 +1,21 @@
1
+ # Find information about the weekend.
2
+ class DBLRuby::Weekend
3
+ # Initialize the weekend
4
+ def initialize
5
+ url = 'https://discordbots.org/api/weekend'
6
+ @data = JSON.parse(RestClient.get(url))
7
+ end
8
+
9
+ # @return data in raw json form.
10
+ attr_reader :data
11
+
12
+ alias to_s data
13
+
14
+ # Return the whether it's the weekend.
15
+ # @return [true, false] the weekend status.
16
+ def weekend?
17
+ @data['is_weekend']
18
+ end
19
+
20
+ alias isweekend weekend?
21
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dblruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.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-11-05 00:00:00.000000000 Z
11
+ date: 2018-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rest-client
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -34,8 +48,10 @@ files:
34
48
  - lib/dblruby/api.rb
35
49
  - lib/dblruby/bot.rb
36
50
  - lib/dblruby/errors.rb
51
+ - lib/dblruby/search.rb
37
52
  - lib/dblruby/stats.rb
38
53
  - lib/dblruby/user.rb
54
+ - lib/dblruby/weekend.rb
39
55
  homepage: http://github.com/Chewsterchew/DBLRuby
40
56
  licenses:
41
57
  - MIT