dblista 0.1.2 → 0.2.1

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: 4ba88619d64539697aa11e51f60ecbf292729ae2d6d8c2ae3291caea28b40dc2
4
- data.tar.gz: dcdcd9f0bb7482b30d0d388ea6cda59fad862267341e6b28e8e10bd558a0e3c2
3
+ metadata.gz: 520e714dd6b6d24600b0d43a3366996c9571c35d2ec87f25a3ffd1d68c61663a
4
+ data.tar.gz: 761385a770d6631b08d6a06d34956019376990a3257d8b7280f57b92f69adb16
5
5
  SHA512:
6
- metadata.gz: 65e48135e27d24539322178ed7f7f27c437e7a54a2f22cf004780f9babad45b2baa96972f75f4c88e433e05f20be390453a1a6fdeb7b752da42d9e2b4929cb16
7
- data.tar.gz: a3d951c2872d596ce2867b905df9d2e513d1c776ca89011c6b1b624a006dd590b66d370e413bc7213828fa317a0291d872f0a6767dec23a2621f61087c0fb12e
6
+ metadata.gz: 299e471f6a12be703653c813f061f7b6f2101a1ee2854dec20c089776f3805141939cc4382a3be281514a9d43526d1ca1e20d8333dc28aeabbe472167864f959
7
+ data.tar.gz: 47188ad512356e1459b1728bd5e3373d09a9e64f60d3ed287c46c7a0338bd04031c49380c4b35b7a085ca47a5a6f3cc3ca4efef9de8c6194b4265f5955b783a1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dblista (0.1.2)
4
+ dblista (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,7 @@ 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'
15
16
 
16
17
  # Main module
17
18
  module DBLista
@@ -34,7 +35,9 @@ module DBLista
34
35
  req['Content-Type'] = 'application/json'
35
36
  req['Authorization'] = token if token
36
37
  response = _https(uri).request(req)
37
- JSON.parse response.body
38
+ result = JSON.parse response.body
39
+ raise DBLista::Error, result['error'].capitalize unless result['status'] == 'success'
40
+ result['data']
38
41
  end
39
42
 
40
43
  # @!visibility private
@@ -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
@@ -2,8 +2,8 @@
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
  #
@@ -12,7 +12,7 @@ module DBLista::User
12
12
  # @return [Hash] raw data from DBLista
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
18
  end
@@ -40,5 +40,19 @@ module DBLista::User
40
40
 
41
41
  DBLista._delete("/#{type}s/#{id}", nil, @token)
42
42
  end
43
+
44
+ # Manages user (bans or adds premium)
45
+ # Available only for DBLista staff
46
+ #
47
+ # @param id [Integer] user ID
48
+ # @param banned [Boolean] user ban status
49
+ # @param premium [Integer] days for premium
50
+ # @return [Hash] raw data from DBLista
51
+ def manage_user(id, banned = false, premium = 0)
52
+ DBLista._post("/users/#{id}/manage", {
53
+ premium: premium,
54
+ ban: banned
55
+ }, @token)
56
+ end
43
57
  end
44
58
  end
@@ -1,8 +1,7 @@
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
  #
@@ -11,7 +10,7 @@ module DBLista::User
11
10
  # @return [Hash] raw data from DBLista
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)
17
16
  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,49 @@
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 [Hash] raw data from DBLista
16
+ def clear_notifications
17
+ DBLista._get('/users/me/notifications/clear', @token)
18
+ end
19
+
20
+ # Sends notification to specified user
21
+ # Available only for DBLista staff
22
+ #
23
+ # @param rank [Integer] user ID
24
+ # @param details [String] details (content)
25
+ # @param url [String] url to redirect if clicked
26
+ # @return [Hash] raw data from DBLista
27
+ def send_notification(id, details, url = '#')
28
+ DBLista._validate_id id
29
+ DBLista._post("/users/#{id}/notifications", {
30
+ text: details,
31
+ url: url || '#'
32
+ }, @token)
33
+ end
34
+
35
+ # Sends notification to specified group (rank)
36
+ # Available only for DBLista staff
37
+ #
38
+ # @param rank [Integer] rank ID
39
+ # @param details [String] details (content)
40
+ # @param url [String] url to redirect if clicked
41
+ # @return [Hash] raw data from DBLista
42
+ def send_group_notification(rank, details, url = '#')
43
+ DBLista._post("/users/group/#{rank}/notifications", {
44
+ text: details,
45
+ url: url || '#'
46
+ }, @token)
47
+ end
48
+ end
49
+ 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
  #
@@ -12,7 +12,7 @@ module DBLista::User
12
12
  # @return [Hash] raw data from DBLista
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,
@@ -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,7 +1,7 @@
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
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DBLista
4
4
  # Wrapper version
5
- VERSION = '0.1.2'
5
+ VERSION = '0.2.1'
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.2
4
+ version: 0.2.1
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
@@ -71,6 +71,7 @@ files:
71
71
  - example/info.rb
72
72
  - lib/dblista.rb
73
73
  - lib/dblista/errors.rb
74
+ - lib/dblista/helpers.rb
74
75
  - lib/dblista/info.rb
75
76
  - lib/dblista/list/bot.rb
76
77
  - lib/dblista/list/server.rb
@@ -78,7 +79,9 @@ files:
78
79
  - lib/dblista/user/actions.rb
79
80
  - lib/dblista/user/boosting.rb
80
81
  - lib/dblista/user/client.rb
82
+ - lib/dblista/user/notifications.rb
81
83
  - lib/dblista/user/rating.rb
84
+ - lib/dblista/user/verification.rb
82
85
  - lib/dblista/user/voting.rb
83
86
  - lib/dblista/version.rb
84
87
  homepage: https://github.com/marek12306/dblista-wrapper-ruby