dblista 0.1.3 → 0.3.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: 51c3d13971d2263b0c97cf0e6f51d28ca72a870a67a660a6f63807e10f3caaad
4
- data.tar.gz: 3628e33de56b321182bd41a05ce771515395d76a3c2e8baf3da8828354c3d516
3
+ metadata.gz: a75838be15e70b98ad6b8f37c880a53539b82f8e0f11ff433ec7665efb9cb4f7
4
+ data.tar.gz: cf00504ac704fff20bb6eea3d4c585f7feb1337529aff5bf488e23e15496df18
5
5
  SHA512:
6
- metadata.gz: 1cbb274d9b3223729e6dcd67ddbb8017b7ab53f5fcce2404a7255fab2ed5bf9945968169865bd9d1e987f285ae78102721868957d7e992a37f35e2849051489e
7
- data.tar.gz: 59678c99464e688a1d00d85bbe3a47abf7c1a035cf1348adccba684b321e6feddcd16bcb7e478dcac67d9e6e89c3706dbae5313b277ea0373ebd93c8eb5086ba
6
+ metadata.gz: e8c280dae3019394510864fb8f8d8ac9f8b7fc59d0ab0278620fd159f64629768088f0654d4d060804a187ff7230cf07ef88819e313dcebd15e8ef70bf587146
7
+ data.tar.gz: 4de0995b3040d0ef57a8a6f8d3eb07b7e58d931f1a58ae5995944b1f121961bb52d0dbfbabc188b40d4baf076c12e25546dd09930e0c97dd33036dbf1a53ac98
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dblista (0.1.3)
4
+ dblista (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,8 @@ require_relative 'dblista/errors'
12
12
  require_relative 'dblista/list/bot'
13
13
  require_relative 'dblista/list/server'
14
14
  require_relative 'dblista/user/client'
15
+ require_relative 'dblista/helpers'
16
+ require_relative 'dblista/constants'
15
17
 
16
18
  # Main module
17
19
  module DBLista
@@ -36,7 +38,7 @@ module DBLista
36
38
  response = _https(uri).request(req)
37
39
  result = JSON.parse response.body
38
40
  raise DBLista::Error, result['error'].capitalize unless result['status'] == 'success'
39
- result
41
+ result['data']
40
42
  end
41
43
 
42
44
  # @!visibility private
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DBLista
4
+ # Tags
5
+ module Tags
6
+ # Bot tags
7
+ module Bot
8
+ MODERATION = :moderacja
9
+ TOOLS = :narzędzia
10
+ MUSIC = :muzyka
11
+ DASHBOARD = :panel
12
+ FUN = :rozrywka
13
+ LEVELS = :poziomy
14
+ GAMES = :gry
15
+ ROLEPLAY = :roleplay
16
+ ECONOMY = :ekonomia
17
+ ANIME = :anime
18
+ NSFW = :nsfw
19
+ OTHER = :inne
20
+ end
21
+ # Server tags
22
+ module Server
23
+ COMMUNITY = :community
24
+ PROGRAMMING = :programowanie
25
+ GAMES = :gry
26
+ YOUTUBE = :youtube
27
+ HOBBY = :hobby
28
+ ANIME = :anime
29
+ ROLEPLAY = :roleplay
30
+ OTHER = :inne
31
+ end
32
+ end
33
+ # Permissions
34
+ module Permissions
35
+ USER = 0
36
+ MODERATOR = 1
37
+ BIG_MODERATOR = 2
38
+ ADMINISTRATOR = 3
39
+ end
40
+ end
@@ -6,6 +6,8 @@ module DBLista::Errors
6
6
  ID_NEEDED = 'You need to enter ID'
7
7
  # Raised when provided page is not an integer
8
8
  PAGE_INTEGER = 'Page must be an integer'
9
+ # Raised when rank is not an integer
10
+ RANK_INTEGER = 'Rank must be an integer'
9
11
  # Raised when token is not provided
10
12
  TOKEN_NOT_PROVIDED = 'Token is not provided'
11
13
  # Raised when type symbol is invalid
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper methods
4
+ module DBLista::Helpers
5
+ # Crafts avatar url from user ID and avatar hash
6
+ #
7
+ # @param id [Integer] user ID
8
+ # @param hash [String] avatar hash
9
+ # @param size [Integer] avatar width (defaults to 2048)
10
+ # @return [Hash] raw data from DBLista
11
+ def self.get_avatar(id, hash, size = 2048)
12
+ "https://cdn.discordapp.com/avatars/#{id}/#{hash}?size=#{size}"
13
+ end
14
+ end
@@ -8,7 +8,7 @@ module DBLista
8
8
  #
9
9
  # @example Checking DBLista user information
10
10
  # info = DBLista::Information.user 123456789012345678
11
- # puts info['data']
11
+ # puts info
12
12
  module Information
13
13
  # Fetches DBLista bot information
14
14
  #
@@ -8,7 +8,7 @@ require 'cgi'
8
8
  #
9
9
  # @example Fetch top 25 bots
10
10
  # top = DBLista::List::Bot.top
11
- # puts top['data'].inspect
11
+ # puts top.inspect
12
12
  module DBLista::List
13
13
  # Bot lists
14
14
  module Bot
@@ -44,6 +44,22 @@ module DBLista::List
44
44
  DBLista._get('/bots/list/rejected')
45
45
  end
46
46
 
47
+ # Fetches all bots
48
+ #
49
+ # @return [Array] array of raw bot data from DBLista
50
+ def self.all
51
+ bots = []
52
+ i = 0
53
+ loop do
54
+ page = DBLista::List::Bot.top(i)
55
+ break if page.length.zero?
56
+
57
+ bots += page
58
+ i += 1
59
+ end
60
+ bots
61
+ end
62
+
47
63
  # Bot search
48
64
  #
49
65
  # @param query [String] query search
@@ -51,7 +67,7 @@ module DBLista::List
51
67
  def self.search(query)
52
68
  raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
53
69
 
54
- DBLista._get("/bots/search/#{CGI.escape query}")
70
+ DBLista._get("/bots/search/#{CGI.escape query.to_s}")
55
71
  end
56
72
  end
57
73
  end
@@ -23,6 +23,22 @@ module DBLista::List
23
23
  DBLista._get("/servers/list/premium/#{page}")
24
24
  end
25
25
 
26
+ # Fetches all servers
27
+ #
28
+ # @return [Array] array of raw server data from DBLista
29
+ def self.all
30
+ servers = []
31
+ i = 0
32
+ loop do
33
+ page = DBLista::List::Server.top(i)
34
+ break if page.length.zero?
35
+
36
+ servers += page
37
+ i += 1
38
+ end
39
+ servers
40
+ end
41
+
26
42
  # Server search
27
43
  #
28
44
  # @param query [String] search query
@@ -30,7 +46,7 @@ module DBLista::List
30
46
  def self.search(query)
31
47
  raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
32
48
 
33
- DBLista._get("/servers/search/#{CGI.escape query}")
49
+ DBLista._get("/servers/search/#{CGI.escape query.to_s}")
34
50
  end
35
51
  end
36
52
  end
@@ -2,43 +2,61 @@
2
2
 
3
3
  require 'json'
4
4
 
5
- # User client - actions
6
5
  module DBLista::User
6
+ # User client - actions
7
7
  module Actions
8
8
  # Adds bot/server to DBLista
9
9
  #
10
10
  # @param body [Hash] raw body to send
11
11
  # @param type [Symbol] type of entity (bot/server)
12
- # @return [Hash] raw data from DBLista
12
+ # @return [Boolean] true if operation succeded
13
13
  def add(body, type = 'bot')
14
14
  raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
15
- raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless ALLOWED_TYPES.include?(type)
15
+ raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
16
16
 
17
17
  DBLista._post("/#{type}s", body, @token)
18
+ true
18
19
  end
19
20
 
20
21
  # Edits bot/server in DBLista
21
22
  #
22
23
  # @param body [Hash] raw body to send
23
24
  # @param type [Symbol] type of entity (bot/server)
24
- # @return [Hash] raw data from DBLista
25
+ # @return [Boolean] true if operation succeded
25
26
  def edit(body, type = :bot)
26
27
  raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
27
28
  raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
28
29
 
29
30
  DBLista._put("/#{type}s", body, @token)
31
+ true
30
32
  end
31
33
 
32
34
  # Deletes bot/server from DBLista
33
35
  #
34
36
  # @param id [Integer] entity ID
35
37
  # @param type [Symbol] type of entity (bot/server)
36
- # @return [Hash] raw data from DBLista
38
+ # @return [Boolean] true if operation succeded
37
39
  def delete(id, type = :bot)
38
40
  DBLista._validate_id id
39
41
  raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
40
42
 
41
43
  DBLista._delete("/#{type}s/#{id}", nil, @token)
44
+ true
45
+ end
46
+
47
+ # Manages user (bans or adds premium)
48
+ # Available only for DBLista staff
49
+ #
50
+ # @param id [Integer] user ID
51
+ # @param banned [Boolean] user ban status
52
+ # @param premium [Integer] days for premium
53
+ # @return [Boolean] true if operation succeded
54
+ def manage_user(id, banned = false, premium = 0)
55
+ DBLista._post("/users/#{id}/manage", {
56
+ premium: premium,
57
+ ban: banned
58
+ }, @token)
59
+ true
42
60
  end
43
61
  end
44
62
  end
@@ -1,31 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # User client - boosting
5
3
  module DBLista::User
4
+ # User client - boosting
6
5
  module Boosting
7
6
  # Boosts selected bot/server
8
7
  #
9
8
  # @param id [Integer] entity ID
10
9
  # @param type [Symbol] type of entity (bot/server)
11
- # @return [Hash] raw data from DBLista
10
+ # @return [Boolean] true if operation succeded
12
11
  def boost(id, type = :bot)
13
12
  DBLista._validate_id id
14
- raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless ALLOWED_TYPES.include?(type)
13
+ raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
15
14
 
16
15
  DBLista._post("/#{type}s/#{id}/boost", nil, @token)
16
+ true
17
17
  end
18
18
 
19
19
  # Removes boost from a selected bot/server
20
20
  #
21
21
  # @param id [Integer] entity ID
22
22
  # @param type [Symbol] type of entity (bot/server)
23
- # @return [Hash] raw data from DBLista
23
+ # @return [Boolean] true if operation succeded
24
24
  def delete_boost(id, type = :bot)
25
25
  DBLista._validate_id id
26
26
  raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
27
27
 
28
28
  DBLista._delete("/#{type}s/#{id}/boost", nil, @token)
29
+ true
29
30
  end
30
31
  end
31
32
  end
@@ -4,6 +4,8 @@ require_relative './actions'
4
4
  require_relative './boosting'
5
5
  require_relative './rating'
6
6
  require_relative './voting'
7
+ require_relative './notifications'
8
+ require_relative './verification'
7
9
 
8
10
  # User module - client + client modules
9
11
  module DBLista::User
@@ -21,6 +23,8 @@ module DBLista::User
21
23
  include DBLista::User::Actions
22
24
  include DBLista::User::Boosting
23
25
  include DBLista::User::Rating
26
+ include DBLista::User::Notifications
27
+ include DBLista::User::Verification
24
28
 
25
29
  # Allowed entity types to use
26
30
  ALLOWED_TYPES = %i[bot server].freeze
@@ -32,14 +36,21 @@ module DBLista::User
32
36
 
33
37
  @token = token
34
38
 
35
- raise DBLista::Error, DBLista::Errors::INVALID_TOKEN unless me['status'] == 'success'
39
+ me
36
40
  end
37
41
 
38
- # Fetches information about user
42
+ # Fetches information about current user
39
43
  #
40
44
  # @return [Hash] raw data from DBLista
41
45
  def me
42
46
  DBLista._get('/users/me', @token)
43
47
  end
48
+
49
+ # Fetches current user guilds
50
+ #
51
+ # @return [Hash] raw data from DBLista
52
+ def guilds
53
+ DBLista._get('/users/me/guilds', @token)
54
+ end
44
55
  end
45
56
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DBLista::User
4
+ # User client - notifications
5
+ module Notifications
6
+ # Fetches user notifications
7
+ #
8
+ # @return [Hash] raw data from DBLista
9
+ def notifications
10
+ DBLista._get('/users/me/notifications/read', @token)
11
+ end
12
+
13
+ # Clears user notifications
14
+ #
15
+ # @return [Boolean] true if operation succeded
16
+ def clear_notifications
17
+ DBLista._get('/users/me/notifications/clear', @token)
18
+ true
19
+ end
20
+
21
+ # Sends notification to specified user
22
+ # Available only for DBLista staff
23
+ #
24
+ # @param rank [Integer] user ID
25
+ # @param details [String] details (content)
26
+ # @param url [String] url to redirect if clicked
27
+ # @return [Boolean] true if operation succeded
28
+ def send_notification(id, details, url = '#')
29
+ DBLista._validate_id id
30
+ DBLista._post("/users/#{id}/notifications", {
31
+ text: details,
32
+ url: url || '#'
33
+ }, @token)
34
+ true
35
+ end
36
+
37
+ # Sends notification to specified group (rank)
38
+ # Available only for DBLista staff
39
+ #
40
+ # @param rank [Integer] rank ID
41
+ # @param details [String] details (content)
42
+ # @param url [String] url to redirect if clicked
43
+ # @return [Boolean] true if operation succeded
44
+ def send_group_notification(rank, details, url = '#')
45
+ DBLista._post("/users/group/#{rank}/notifications", {
46
+ text: details,
47
+ url: url || '#'
48
+ }, @token)
49
+ true
50
+ end
51
+ end
52
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # User client - rating
4
3
  module DBLista::User
4
+ # User client - rating
5
5
  module Rating
6
6
  # Sends rate for a selected bot/server
7
7
  #
@@ -9,15 +9,16 @@ module DBLista::User
9
9
  # @param rating [Integer] rating from 0 to 5
10
10
  # @param details [String] details (description)
11
11
  # @param type [Symbol] type of entity (bot/server)
12
- # @return [Hash] raw data from DBLista
12
+ # @return [Boolean] true if operation succeded
13
13
  def rate(id, rating, details, type = :bot)
14
14
  DBLista._validate_id id
15
- raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless ALLOWED_TYPES.include?(type)
15
+ raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
16
16
 
17
17
  DBLista._post("/#{type}s/#{id}/rate", {
18
18
  rating: rating,
19
19
  details: details
20
20
  }, @token)
21
+ true
21
22
  end
22
23
 
23
24
  # Removes rate for a selected bot/server
@@ -25,12 +26,13 @@ module DBLista::User
25
26
  # @param id [Integer] entity ID
26
27
  # @param target_id [Integer] target user to remove rate from (for owners only)
27
28
  # @param type [Symbol] type of entity (bot/server)
28
- # @return [Hash] raw data from DBLista
29
+ # @return [Boolean] true if operation succeded
29
30
  def delete_rate(id, target_id = nil, type = :bot)
30
31
  DBLista._validate_id id
31
32
  raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
32
33
 
33
34
  DBLista._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
35
+ true
34
36
  end
35
37
  end
36
38
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+
5
+ module DBLista::User
6
+ # User client - verification (only for staff)
7
+ module Verification
8
+ # Approves specified bot
9
+ #
10
+ # @param id [Integer] bot ID
11
+ # @param reason [String] reason for approving
12
+ # @return [Boolean] true if operation succeded
13
+ def approve(id, reason = 'Brak powodu')
14
+ DBLista._validate_id id
15
+
16
+ DBLista._post("/bots/#{id}/approve?reason=#{CGI.escape reason}", nil, @token)
17
+ true
18
+ end
19
+
20
+ # Rejects specified bot
21
+ #
22
+ # @param id [Integer] bot ID
23
+ # @param reason [String] reason for rejecting
24
+ # @return [Boolean] true if operation succeded
25
+ def reject(id, reason = 'Brak powodu')
26
+ DBLista._validate_id id
27
+
28
+ DBLista._post("/bots/#{id}/reject?reason=#{CGI.escape reason}", nil, @token)
29
+ true
30
+ end
31
+
32
+ # Sets specified bot verification status to pending
33
+ #
34
+ # @param id [Integer] bot ID
35
+ # @return [Boolean] true if operation succeded
36
+ def set_pending(id)
37
+ DBLista._validate_id id
38
+
39
+ DBLista._post("/bots/#{id}/set-pending", nil, @token)
40
+ true
41
+ end
42
+ end
43
+ end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # User client - voting
4
3
  module DBLista::User
4
+ # User client - voting
5
5
  module Voting
6
6
  # Votes for a selected bot/server
7
7
  #
8
8
  # @param id [Integer] entity ID
9
9
  # @param type [Symbol] type of entity (bot/server)
10
- # @return [Hash] raw data from DBLista
10
+ # @return [Boolean] true if operation succeded
11
11
  def vote(id, type = :bot)
12
12
  DBLista._validate_id id
13
13
  raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
14
14
 
15
15
  DBLista._post("/#{type}s/#{id}/vote", nil, @token)
16
+ true
16
17
  end
17
18
  end
18
19
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DBLista
4
4
  # Wrapper version
5
- VERSION = '0.1.3'
5
+ VERSION = '0.3.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dblista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - deepivin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-04 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,7 +70,9 @@ files:
70
70
  - dblista.gemspec
71
71
  - example/info.rb
72
72
  - lib/dblista.rb
73
+ - lib/dblista/constants.rb
73
74
  - lib/dblista/errors.rb
75
+ - lib/dblista/helpers.rb
74
76
  - lib/dblista/info.rb
75
77
  - lib/dblista/list/bot.rb
76
78
  - lib/dblista/list/server.rb
@@ -78,7 +80,9 @@ files:
78
80
  - lib/dblista/user/actions.rb
79
81
  - lib/dblista/user/boosting.rb
80
82
  - lib/dblista/user/client.rb
83
+ - lib/dblista/user/notifications.rb
81
84
  - lib/dblista/user/rating.rb
85
+ - lib/dblista/user/verification.rb
82
86
  - lib/dblista/user/voting.rb
83
87
  - lib/dblista/version.rb
84
88
  homepage: https://github.com/marek12306/dblista-wrapper-ruby