dblista 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/bin/console +0 -0
- data/dblista.gemspec +1 -1
- data/examples/auto_stats.rb +1 -1
- data/examples/bot_add.rb +3 -3
- data/examples/full_bot_name_list.rb +1 -1
- data/examples/notifications.rb +1 -1
- data/examples/tag_search.rb +1 -1
- data/examples/user_avatar.rb +2 -2
- data/lib/dblista.rb +11 -11
- data/lib/dblista/constants.rb +1 -1
- data/lib/dblista/errors.rb +1 -1
- data/lib/dblista/helpers.rb +2 -2
- data/lib/dblista/info.rb +18 -18
- data/lib/dblista/list/bot.rb +25 -25
- data/lib/dblista/list/server.rb +18 -18
- data/lib/dblista/stats.rb +7 -7
- data/lib/dblista/user/actions.rb +21 -21
- data/lib/dblista/user/boosting.rb +7 -7
- data/lib/dblista/user/client.rb +18 -18
- data/lib/dblista/user/info.rb +5 -5
- data/lib/dblista/user/notifications.rb +9 -9
- data/lib/dblista/user/rating.rb +15 -15
- data/lib/dblista/user/verification.rb +7 -7
- data/lib/dblista/user/voting.rb +4 -4
- data/lib/dblista/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fc43df32a990398b6458027722e311e3a953ff86b8a74c1fcd7b22b56d2e9e
|
4
|
+
data.tar.gz: '08742f7663b94d42380230a24970308a08b2ffd5ea568d7ce206a7b38f37358b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3cfacb8fde02926253748c70a464d8adf34173f183865c94065b913168b37a2fe78714b129d6aafa9d7322bf2721b52316c17261be00f1859cd8ff105780c8b
|
7
|
+
data.tar.gz: 9097d31284237736b01860e4607af78c4bf60f0accff073f2b8a34dc4e260ba3d260a631ed4179f44f0e3f65dc946ae62dff899e64c996af8160ef8299cc5a1a
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
UWAGA: Gem ten nie jest już rozwijany. Nie odpowiadam za żadne błędy wywołane tym gemem.
|
2
|
+
-------------------------------------
|
1
3
|
# DList (kiedyś DBLista) Ruby wrapper [![Gem Version](https://badge.fury.io/rb/dblista.svg)](https://badge.fury.io/rb/dblista)
|
2
4
|
|
3
5
|
[Dokumentacja](https://www.rubydoc.info/github/marek12306/dblista-wrapper-ruby)
|
@@ -33,13 +35,13 @@ Automatyczne statystyki:
|
|
33
35
|
|
34
36
|
```ruby
|
35
37
|
bot = Discordrb::Bot.new token: 'TOKEN'
|
36
|
-
dbl =
|
38
|
+
dbl = DList::Stats.new 'DLIST_TOKEN', bot
|
37
39
|
```
|
38
40
|
|
39
41
|
Pobieranie topki botów:
|
40
42
|
|
41
43
|
```ruby
|
42
|
-
top =
|
44
|
+
top = DList::List::Bot.top
|
43
45
|
puts top
|
44
46
|
```
|
45
47
|
|
data/bin/console
CHANGED
File without changes
|
data/dblista.gemspec
CHANGED
data/examples/auto_stats.rb
CHANGED
data/examples/bot_add.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'dblista'
|
2
2
|
|
3
|
-
client =
|
3
|
+
client = DList::User::Client.new('TOKEN')
|
4
4
|
|
5
5
|
client.add({
|
6
6
|
id: 'id',
|
7
7
|
info: {
|
8
8
|
library: 'NiceBot',
|
9
9
|
tags: [
|
10
|
-
|
11
|
-
|
10
|
+
DList::Tags::Bot::FUN,
|
11
|
+
DList::Tags::Bot::TOOLS
|
12
12
|
],
|
13
13
|
prefix: '!',
|
14
14
|
fullDescription: 'long description',
|
data/examples/notifications.rb
CHANGED
data/examples/tag_search.rb
CHANGED
data/examples/user_avatar.rb
CHANGED
data/lib/dblista.rb
CHANGED
@@ -17,8 +17,8 @@ require_relative 'dblista/helpers'
|
|
17
17
|
require_relative 'dblista/constants'
|
18
18
|
|
19
19
|
# Main module
|
20
|
-
module
|
21
|
-
#
|
20
|
+
module DList
|
21
|
+
# DList error class
|
22
22
|
class Error < StandardError; end
|
23
23
|
# API path prefix
|
24
24
|
API_PATH = 'https://api.dlist.top/v1'
|
@@ -43,55 +43,55 @@ module DBLista
|
|
43
43
|
req['Authorization'] = token if token
|
44
44
|
response = _https(uri).request(req)
|
45
45
|
result = JSON.parse response.body
|
46
|
-
raise
|
46
|
+
raise DList::Error, result['error'].capitalize unless result['status'] == 'success'
|
47
47
|
|
48
48
|
result['data']
|
49
49
|
end
|
50
50
|
|
51
51
|
# @!visibility private
|
52
52
|
def self._get(path, token = nil)
|
53
|
-
uri = URI("#{
|
53
|
+
uri = URI("#{DList::API_PATH}#{path}")
|
54
54
|
req = Net::HTTP::Get.new(uri)
|
55
55
|
_handle_request(req, uri, token, nil)
|
56
56
|
end
|
57
57
|
|
58
58
|
# @!visibility private
|
59
59
|
def self._post(path, data = nil, token = nil)
|
60
|
-
uri = URI("#{
|
60
|
+
uri = URI("#{DList::API_PATH}#{path}")
|
61
61
|
req = Net::HTTP::Post.new(uri)
|
62
62
|
_handle_request(req, uri, token, data)
|
63
63
|
end
|
64
64
|
|
65
65
|
# @!visibility private
|
66
66
|
def self._delete(path, data = nil, token = nil)
|
67
|
-
uri = URI("#{
|
67
|
+
uri = URI("#{DList::API_PATH}#{path}")
|
68
68
|
req = Net::HTTP::Delete.new(uri)
|
69
69
|
_handle_request(req, uri, token, data)
|
70
70
|
end
|
71
71
|
|
72
72
|
# @!visibility private
|
73
73
|
def self._put(path, data = nil, token = nil)
|
74
|
-
uri = URI("#{
|
74
|
+
uri = URI("#{DList::API_PATH}#{path}")
|
75
75
|
req = Net::HTTP::Put.new(uri)
|
76
76
|
_handle_request(req, uri, token, data)
|
77
77
|
end
|
78
78
|
|
79
79
|
# @!visibility private
|
80
80
|
def self._validate_id(id)
|
81
|
-
raise
|
81
|
+
raise DList::Error, DList::Errors::ID_NEEDED unless DList::IS_NUMBER.match?(id.to_s)
|
82
82
|
end
|
83
83
|
|
84
84
|
# @!visibility private
|
85
85
|
def self._page_integer(input)
|
86
|
-
raise
|
86
|
+
raise DList::Error, DList::Errors::PAGE_INTEGER unless input.is_a?(Integer)
|
87
87
|
end
|
88
88
|
|
89
89
|
# @!visibility private
|
90
90
|
def self._limit_integer(input)
|
91
|
-
raise
|
91
|
+
raise DList::Error, DList::Errors::LIMIT_INTEGER unless input.is_a?(Integer)
|
92
92
|
end
|
93
93
|
|
94
94
|
def self._cache(name)
|
95
|
-
|
95
|
+
DList::Cache.get(name.to_sym, lifetime: DList::CACHE_LIFETIME) { yield }
|
96
96
|
end
|
97
97
|
end
|
data/lib/dblista/constants.rb
CHANGED
data/lib/dblista/errors.rb
CHANGED
data/lib/dblista/helpers.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Helper methods
|
4
|
-
module
|
4
|
+
module DList::Helpers
|
5
5
|
# Crafts avatar url from user ID and avatar hash
|
6
6
|
#
|
7
7
|
# @param id [Integer] user ID
|
8
8
|
# @param hash [String] avatar hash
|
9
9
|
# @param size [Integer] avatar width (defaults to 2048)
|
10
|
-
# @return [Hash] raw data from
|
10
|
+
# @return [Hash] raw data from DList
|
11
11
|
def self.get_avatar(id, hash, size = 2048)
|
12
12
|
"https://cdn.discordapp.com/avatars/#{id}/#{hash}?size=#{size}"
|
13
13
|
end
|
data/lib/dblista/info.rb
CHANGED
@@ -3,43 +3,43 @@
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
module
|
6
|
+
module DList
|
7
7
|
# Bot/server/user detailed information
|
8
8
|
#
|
9
|
-
# @example Checking
|
10
|
-
# info =
|
9
|
+
# @example Checking DList user information
|
10
|
+
# info = DList::Information.user 123456789012345678
|
11
11
|
# puts info
|
12
12
|
module Information
|
13
|
-
# Fetches
|
13
|
+
# Fetches DList bot information
|
14
14
|
#
|
15
15
|
# @param id [Integer] bot ID
|
16
|
-
# @return [Hash] raw data from
|
16
|
+
# @return [Hash] raw data from DList
|
17
17
|
def self.bot(id)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
DList._validate_id id
|
19
|
+
DList._cache(id.to_s.to_sym) do
|
20
|
+
DList._get("/bots/#{id}")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
# Fetches
|
24
|
+
# Fetches DList server information
|
25
25
|
#
|
26
26
|
# @param id [Integer] server ID
|
27
|
-
# @return [Hash] raw data from
|
27
|
+
# @return [Hash] raw data from DList
|
28
28
|
def self.server(id)
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
DList._validate_id id
|
30
|
+
DList._cache(id.to_s.to_sym) do
|
31
|
+
DList._get("/servers/#{id}")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
# Fetches
|
35
|
+
# Fetches DList user information
|
36
36
|
#
|
37
37
|
# @param id [Integer] user ID
|
38
|
-
# @return [Hash] raw data from
|
38
|
+
# @return [Hash] raw data from DList
|
39
39
|
def self.user(id)
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
DList._validate_id id
|
41
|
+
DList._cache(id.to_s.to_sym) do
|
42
|
+
DList._get("/users/#{id}")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/dblista/list/bot.rb
CHANGED
@@ -7,21 +7,21 @@ require 'cgi'
|
|
7
7
|
# Lists
|
8
8
|
#
|
9
9
|
# @example Fetch top 25 bots
|
10
|
-
# top =
|
10
|
+
# top = DList::List::Bot.top
|
11
11
|
# puts top
|
12
|
-
module
|
12
|
+
module DList::List
|
13
13
|
# Bot lists
|
14
14
|
module Bot
|
15
15
|
# Fetches top bots
|
16
16
|
#
|
17
17
|
# @param page [Integer] page
|
18
18
|
# @param limit [Integer] limit of bots per page
|
19
|
-
# @return [Hash] raw data from
|
19
|
+
# @return [Hash] raw data from DList
|
20
20
|
def self.top(page = 0, limit = 10)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
DList._page_integer page
|
22
|
+
DList._limit_integer limit
|
23
|
+
DList._cache("botstop#{page}-#{limit}") do
|
24
|
+
DList._get("/bots/list/top/#{page}?limit=#{limit}")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,51 +29,51 @@ module DBLista::List
|
|
29
29
|
#
|
30
30
|
# @param page [Integer] page
|
31
31
|
# @param limit [Integer] limit of bots per page
|
32
|
-
# @return [Hash] raw data from
|
32
|
+
# @return [Hash] raw data from DList
|
33
33
|
def self.premium(page = 0, limit = 10)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
DList._page_integer page
|
35
|
+
DList._limit_integer limit
|
36
|
+
DList._cache("botspremium#{page}-#{limit}") do
|
37
|
+
DList._get("/bots/list/premium/#{page}?limit=#{limit}")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
# Fetches unverified bots
|
42
42
|
#
|
43
|
-
# @return [Hash] raw data from
|
43
|
+
# @return [Hash] raw data from DList
|
44
44
|
def self.unverified
|
45
|
-
|
46
|
-
|
45
|
+
DList._cache(:botsunverified) do
|
46
|
+
DList._get('/bots/list/unverified')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
# Fetches rejected bots
|
51
51
|
#
|
52
|
-
# @return [Hash] raw data from
|
52
|
+
# @return [Hash] raw data from DList
|
53
53
|
def self.rejected
|
54
|
-
|
55
|
-
|
54
|
+
DList._cache(:botsrejected) do
|
55
|
+
DList._get('/bots/list/rejected')
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
# Fetches all bots
|
60
60
|
#
|
61
|
-
# @return [Array] array of raw bot data from
|
61
|
+
# @return [Array] array of raw bot data from DList
|
62
62
|
def self.all
|
63
|
-
|
64
|
-
|
63
|
+
DList._cache(:botsall) do
|
64
|
+
DList._get('/bots/list/top/0?limit=1000000')
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
# Bot search
|
69
69
|
#
|
70
70
|
# @param query [String] query search
|
71
|
-
# @return [Hash] raw data from
|
71
|
+
# @return [Hash] raw data from DList
|
72
72
|
def self.search(query)
|
73
|
-
raise
|
73
|
+
raise DList::Error, DList::Errors::QUERY_NOT_PROVIDED unless query
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
DList._cache("botsearch#{query}") do
|
76
|
+
DList._get("/bots/search/#{CGI.escape query.to_s}")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/lib/dblista/list/server.rb
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'cgi'
|
4
4
|
|
5
|
-
module
|
5
|
+
module DList::List
|
6
6
|
# Server lists
|
7
7
|
module Server
|
8
8
|
# Fetches top servers
|
9
9
|
#
|
10
10
|
# @param page [Integer] page
|
11
11
|
# @param limit [Integer] limit of servers per page
|
12
|
-
# @return [Hash] raw data from
|
12
|
+
# @return [Hash] raw data from DList
|
13
13
|
def self.top(page = 0, limit = 10)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
DList._page_integer page
|
15
|
+
DList._limit_integer limit
|
16
|
+
DList._cache("serverstop#{page}-#{limit}") do
|
17
|
+
DList._get("/servers/list/top/#{page}?limit=#{limit}")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,33 +22,33 @@ module DBLista::List
|
|
22
22
|
#
|
23
23
|
# @param page [Integer] page
|
24
24
|
# @param limit [Integer] limit of servers per page
|
25
|
-
# @return [Hash] raw data from
|
25
|
+
# @return [Hash] raw data from DList
|
26
26
|
def self.premium(page = 0, limit = 10)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
DList._page_integer page
|
28
|
+
DList._limit_integer limit
|
29
|
+
DList._cache("serverspremium#{page}-#{limit}") do
|
30
|
+
DList._get("/servers/list/premium/#{page}?limit=#{limit}")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
# Fetches all servers
|
35
35
|
#
|
36
|
-
# @return [Array] array of raw server data from
|
36
|
+
# @return [Array] array of raw server data from DList
|
37
37
|
def self.all
|
38
|
-
|
39
|
-
|
38
|
+
DList._cache(:serversall) do
|
39
|
+
DList._get('/servers/list/top/0?limit=1000000')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
# Server search
|
44
44
|
#
|
45
45
|
# @param query [String] search query
|
46
|
-
# @return [Hash] raw data from
|
46
|
+
# @return [Hash] raw data from DList
|
47
47
|
def self.search(query)
|
48
|
-
raise
|
48
|
+
raise DList::Error, DList::Errors::QUERY_NOT_PROVIDED unless query
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
DList._cache("serversearch#{query}") do
|
51
|
+
DList._get("/servers/search/#{CGI.escape query.to_s}")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/dblista/stats.rb
CHANGED
@@ -3,19 +3,19 @@
|
|
3
3
|
require 'net/https'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
module
|
6
|
+
module DList
|
7
7
|
# Class for updating bot statistics
|
8
8
|
#
|
9
|
-
# @example Hook bot stats to
|
9
|
+
# @example Hook bot stats to DList
|
10
10
|
# bot = Discordrb::Bot.new token: 'TOKEN'
|
11
|
-
# dbl =
|
11
|
+
# dbl = DList::Stats.new 'DList_TOKEN', bot
|
12
12
|
class Stats
|
13
13
|
attr_accessor :token
|
14
14
|
|
15
|
-
# @param token [String]
|
15
|
+
# @param token [String] DList bot token
|
16
16
|
# @param bot [Discordrb::Bot] discordrb bot for auto-sending statistics
|
17
17
|
def initialize(token, bot = nil)
|
18
|
-
raise
|
18
|
+
raise DList::Error, DList::Errors::TOKEN_NOT_PROVIDED unless token
|
19
19
|
|
20
20
|
@token = token
|
21
21
|
if bot&.connected?
|
@@ -38,13 +38,13 @@ module DBLista
|
|
38
38
|
@thread
|
39
39
|
end
|
40
40
|
|
41
|
-
# Sends statistics to
|
41
|
+
# Sends statistics to DList
|
42
42
|
#
|
43
43
|
# @param members [Integer] member count
|
44
44
|
# @param servers [Integer] server count
|
45
45
|
# @return [Boolean] true if operation succeded
|
46
46
|
def update_stats(members, servers)
|
47
|
-
|
47
|
+
DList._post('/bots/stats', {
|
48
48
|
'servers' => servers,
|
49
49
|
'members' => members
|
50
50
|
}, @token)
|
data/lib/dblista/user/actions.rb
CHANGED
@@ -2,57 +2,57 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
module
|
5
|
+
module DList::User
|
6
6
|
# User client - actions
|
7
7
|
module Actions
|
8
|
-
# Adds bot/server to
|
8
|
+
# Adds bot/server to DList
|
9
9
|
#
|
10
10
|
# @param body [Hash] raw body to send
|
11
11
|
# @param type [Symbol] type of entity (bot/server)
|
12
12
|
# @return [Boolean] true if operation succeded
|
13
13
|
def add(body, type = 'bot')
|
14
|
-
raise
|
15
|
-
raise
|
14
|
+
raise DList::Error, DList::Errors::BODY_HASH unless body.is_a?(Hash)
|
15
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
16
16
|
|
17
|
-
|
17
|
+
DList._post("/#{type}s", body, @token)
|
18
18
|
true
|
19
19
|
end
|
20
20
|
|
21
|
-
# Edits bot/server in
|
21
|
+
# Edits bot/server in DList
|
22
22
|
#
|
23
23
|
# @param body [Hash] raw body to send
|
24
24
|
# @param type [Symbol] type of entity (bot/server)
|
25
25
|
# @return [Boolean] true if operation succeded
|
26
26
|
def edit(body, type = :bot)
|
27
|
-
raise
|
28
|
-
raise
|
27
|
+
raise DList::Error, DList::Errors::BODY_HASH unless body.is_a?(Hash)
|
28
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
29
29
|
|
30
|
-
|
30
|
+
DList._put("/#{type}s", body, @token)
|
31
31
|
true
|
32
32
|
end
|
33
33
|
|
34
|
-
# Deletes bot/server from
|
34
|
+
# Deletes bot/server from DList
|
35
35
|
#
|
36
36
|
# @param id [Integer] entity ID
|
37
37
|
# @param type [Symbol] type of entity (bot/server)
|
38
38
|
# @return [Boolean] true if operation succeded
|
39
39
|
def delete(id, type = :bot)
|
40
|
-
|
41
|
-
raise
|
40
|
+
DList._validate_id id
|
41
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
42
42
|
|
43
|
-
|
43
|
+
DList._delete("/#{type}s/#{id}", nil, @token)
|
44
44
|
true
|
45
45
|
end
|
46
46
|
|
47
47
|
# Manages user (bans or adds premium)
|
48
|
-
# Available only for
|
48
|
+
# Available only for DList staff
|
49
49
|
#
|
50
50
|
# @param id [Integer] user ID
|
51
51
|
# @param banned [Boolean] user ban status
|
52
52
|
# @param premium [Integer] days for premium
|
53
53
|
# @return [Boolean] true if operation succeded
|
54
54
|
def manage_user(id, banned = false, premium = 0)
|
55
|
-
|
55
|
+
DList._post("/users/#{id}/manage", {
|
56
56
|
premium: premium,
|
57
57
|
ban: banned
|
58
58
|
}, @token)
|
@@ -62,19 +62,19 @@ module DBLista::User
|
|
62
62
|
# Generates token for bot
|
63
63
|
#
|
64
64
|
# @param id [Integer] bot ID
|
65
|
-
# @return [Hash] raw data from
|
65
|
+
# @return [Hash] raw data from DList
|
66
66
|
def generate_token(id)
|
67
|
-
|
68
|
-
|
67
|
+
DList._validate_id id
|
68
|
+
DList._get("/bots/stats/#{id}?token=#{@token}")
|
69
69
|
end
|
70
70
|
|
71
71
|
# Resets token for bot
|
72
72
|
#
|
73
73
|
# @param id [Integer] bot ID
|
74
|
-
# @return [Hash] raw data from
|
74
|
+
# @return [Hash] raw data from DList
|
75
75
|
def reset_token(id)
|
76
|
-
|
77
|
-
|
76
|
+
DList._validate_id id
|
77
|
+
DList._post("/bots/stats/#{id}/reset", nil, @token)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module DList::User
|
4
4
|
# User client - boosting
|
5
5
|
module Boosting
|
6
6
|
# Boosts selected bot/server
|
@@ -9,10 +9,10 @@ module DBLista::User
|
|
9
9
|
# @param type [Symbol] type of entity (bot/server)
|
10
10
|
# @return [Boolean] true if operation succeded
|
11
11
|
def boost(id, type = :bot)
|
12
|
-
|
13
|
-
raise
|
12
|
+
DList._validate_id id
|
13
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
14
14
|
|
15
|
-
|
15
|
+
DList._post("/#{type}s/#{id}/boost", nil, @token)
|
16
16
|
true
|
17
17
|
end
|
18
18
|
|
@@ -22,10 +22,10 @@ module DBLista::User
|
|
22
22
|
# @param type [Symbol] type of entity (bot/server)
|
23
23
|
# @return [Boolean] true if operation succeded
|
24
24
|
def delete_boost(id, type = :bot)
|
25
|
-
|
26
|
-
raise
|
25
|
+
DList._validate_id id
|
26
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
27
27
|
|
28
|
-
|
28
|
+
DList._delete("/#{type}s/#{id}/boost", nil, @token)
|
29
29
|
true
|
30
30
|
end
|
31
31
|
end
|
data/lib/dblista/user/client.rb
CHANGED
@@ -11,24 +11,24 @@ require_relative './verification'
|
|
11
11
|
require_relative './info'
|
12
12
|
|
13
13
|
# User module - client + client modules
|
14
|
-
module
|
15
|
-
#
|
14
|
+
module DList::User
|
15
|
+
# DList user client
|
16
16
|
#
|
17
17
|
# @example Server voting
|
18
|
-
# client =
|
18
|
+
# client = DList::User::Client.new "USER_TOKEN"
|
19
19
|
# client.vote(123456789012345678, :server)
|
20
20
|
#
|
21
21
|
# @example Bot rating
|
22
|
-
# client =
|
22
|
+
# client = DList::User::Client.new "USER_TOKEN"
|
23
23
|
# client.rate(123456789012345678, 5, 'Nice bot')
|
24
24
|
class Client
|
25
|
-
include
|
26
|
-
include
|
27
|
-
include
|
28
|
-
include
|
29
|
-
include
|
30
|
-
include
|
31
|
-
include
|
25
|
+
include DList::User::Voting
|
26
|
+
include DList::User::Actions
|
27
|
+
include DList::User::Boosting
|
28
|
+
include DList::User::Rating
|
29
|
+
include DList::User::Notifications
|
30
|
+
include DList::User::Verification
|
31
|
+
include DList::User::Information
|
32
32
|
|
33
33
|
# Allowed entity types to use
|
34
34
|
ALLOWED_TYPES = %i[bot server].freeze
|
@@ -36,7 +36,7 @@ module DBLista::User
|
|
36
36
|
attr_accessor :token
|
37
37
|
|
38
38
|
def initialize(token)
|
39
|
-
raise
|
39
|
+
raise DList::Error, DList::Errors::TOKEN_NOT_PROVIDED unless token
|
40
40
|
|
41
41
|
@token = token
|
42
42
|
@cache = Zache.new
|
@@ -46,19 +46,19 @@ module DBLista::User
|
|
46
46
|
|
47
47
|
# Fetches information about current user
|
48
48
|
#
|
49
|
-
# @return [Hash] raw data from
|
49
|
+
# @return [Hash] raw data from DList
|
50
50
|
def me
|
51
|
-
@cache.get(:guilds, lifetime:
|
52
|
-
|
51
|
+
@cache.get(:guilds, lifetime: DList::CACHE_LIFETIME) do
|
52
|
+
DList._get('/users/me', @token)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
# Fetches current user guilds
|
57
57
|
#
|
58
|
-
# @return [Hash] raw data from
|
58
|
+
# @return [Hash] raw data from DList
|
59
59
|
def joined_guilds
|
60
|
-
@cache.get(:guilds, lifetime:
|
61
|
-
|
60
|
+
@cache.get(:guilds, lifetime: DList::CACHE_LIFETIME) do
|
61
|
+
DList._get('/users/me/guilds', @token)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/dblista/user/info.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module DList::User
|
4
4
|
# User client - information
|
5
5
|
module Information
|
6
6
|
# Fetches your servers
|
7
7
|
#
|
8
|
-
# @return [Hash] raw data from
|
8
|
+
# @return [Hash] raw data from DList
|
9
9
|
def servers
|
10
|
-
|
10
|
+
DList._get('/servers/user/me', @token)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Fetches your bots
|
14
14
|
#
|
15
|
-
# @return [Hash] raw data from
|
15
|
+
# @return [Hash] raw data from DList
|
16
16
|
def bots
|
17
|
-
|
17
|
+
DList._get('/bots/user/me', @token)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,33 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module DList::User
|
4
4
|
# User client - notifications
|
5
5
|
module Notifications
|
6
6
|
# Fetches user notifications
|
7
7
|
#
|
8
|
-
# @return [Hash] raw data from
|
8
|
+
# @return [Hash] raw data from DList
|
9
9
|
def notifications
|
10
|
-
|
10
|
+
DList._get('/users/me/notifications/read', @token)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Clears user notifications
|
14
14
|
#
|
15
15
|
# @return [Boolean] true if operation succeded
|
16
16
|
def clear_notifications
|
17
|
-
|
17
|
+
DList._get('/users/me/notifications/clear', @token)
|
18
18
|
true
|
19
19
|
end
|
20
20
|
|
21
21
|
# Sends notification to specified user
|
22
|
-
# Available only for
|
22
|
+
# Available only for DList staff
|
23
23
|
#
|
24
24
|
# @param rank [Integer] user ID
|
25
25
|
# @param details [String] details (content)
|
26
26
|
# @param url [String] url to redirect if clicked
|
27
27
|
# @return [Boolean] true if operation succeded
|
28
28
|
def send_notification(id, details, url = '#')
|
29
|
-
|
30
|
-
|
29
|
+
DList._validate_id id
|
30
|
+
DList._post("/users/#{id}/notifications", {
|
31
31
|
text: details,
|
32
32
|
url: url || '#'
|
33
33
|
}, @token)
|
@@ -35,14 +35,14 @@ module DBLista::User
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Sends notification to specified group (rank)
|
38
|
-
# Available only for
|
38
|
+
# Available only for DList staff
|
39
39
|
#
|
40
40
|
# @param rank [Integer] rank ID
|
41
41
|
# @param details [String] details (content)
|
42
42
|
# @param url [String] url to redirect if clicked
|
43
43
|
# @return [Boolean] true if operation succeded
|
44
44
|
def send_group_notification(rank, details, url = '#')
|
45
|
-
|
45
|
+
DList._post("/users/group/#{rank}/notifications", {
|
46
46
|
text: details,
|
47
47
|
url: url || '#'
|
48
48
|
}, @token)
|
data/lib/dblista/user/rating.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module DList::User
|
4
4
|
# User client - rating
|
5
5
|
module Rating
|
6
6
|
# Sends rate for a selected bot/server
|
@@ -11,10 +11,10 @@ module DBLista::User
|
|
11
11
|
# @param type [Symbol] type of entity (bot/server)
|
12
12
|
# @return [Boolean] true if operation succeded
|
13
13
|
def rate(id, rating, details, type = :bot)
|
14
|
-
|
15
|
-
raise
|
14
|
+
DList._validate_id id
|
15
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
16
16
|
|
17
|
-
|
17
|
+
DList._post("/#{type}s/#{id}/rate", {
|
18
18
|
rating: rating,
|
19
19
|
details: details
|
20
20
|
}, @token)
|
@@ -28,10 +28,10 @@ module DBLista::User
|
|
28
28
|
# @param type [Symbol] type of entity (bot/server)
|
29
29
|
# @return [Boolean] true if operation succeded
|
30
30
|
def delete_rate(id, target_id = nil, type = :bot)
|
31
|
-
|
32
|
-
raise
|
31
|
+
DList._validate_id id
|
32
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
33
33
|
|
34
|
-
|
34
|
+
DList._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
|
35
35
|
true
|
36
36
|
end
|
37
37
|
|
@@ -43,10 +43,10 @@ module DBLista::User
|
|
43
43
|
# @param type [Symbol] type of entity (bot/server)
|
44
44
|
# @return [Boolean] true if operation succeded
|
45
45
|
def report_rate(id, rate_id, report_reason = 'Brak powodu', type = :bot)
|
46
|
-
|
47
|
-
raise
|
46
|
+
DList._validate_id id
|
47
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
48
48
|
|
49
|
-
|
49
|
+
DList._post("/#{type}s/#{id}/ratings/#{rate_id}/report", {
|
50
50
|
reportReason: report_reason.to_s
|
51
51
|
}, @token)
|
52
52
|
true
|
@@ -54,19 +54,19 @@ module DBLista::User
|
|
54
54
|
|
55
55
|
# Fetches all rate reports
|
56
56
|
#
|
57
|
-
# @return [Hash] raw data from
|
57
|
+
# @return [Hash] raw data from DList
|
58
58
|
def reports
|
59
|
-
|
59
|
+
DList._get('/reports')
|
60
60
|
end
|
61
61
|
|
62
62
|
# Deletes rate report
|
63
63
|
#
|
64
64
|
# @param id [Integer] report ID
|
65
|
-
# @return [Hash] raw data from
|
65
|
+
# @return [Hash] raw data from DList
|
66
66
|
def delete_report(id, type = :bot)
|
67
|
-
raise
|
67
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
68
68
|
|
69
|
-
|
69
|
+
DList._delete("/reports/#{id}", nil, @token)
|
70
70
|
true
|
71
71
|
end
|
72
72
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'cgi'
|
4
4
|
|
5
|
-
module
|
5
|
+
module DList::User
|
6
6
|
# User client - verification (only for staff)
|
7
7
|
module Verification
|
8
8
|
# Approves specified bot
|
@@ -11,9 +11,9 @@ module DBLista::User
|
|
11
11
|
# @param reason [String] reason for approving
|
12
12
|
# @return [Boolean] true if operation succeded
|
13
13
|
def approve(id, reason = 'Brak powodu')
|
14
|
-
|
14
|
+
DList._validate_id id
|
15
15
|
|
16
|
-
|
16
|
+
DList._post("/bots/verify/#{id}/approve?reason=#{CGI.escape reason}", nil, @token)
|
17
17
|
true
|
18
18
|
end
|
19
19
|
|
@@ -23,9 +23,9 @@ module DBLista::User
|
|
23
23
|
# @param reason [String] reason for rejecting
|
24
24
|
# @return [Boolean] true if operation succeded
|
25
25
|
def reject(id, reason = 'Brak powodu')
|
26
|
-
|
26
|
+
DList._validate_id id
|
27
27
|
|
28
|
-
|
28
|
+
DList._post("/bots/verify/#{id}/reject?reason=#{CGI.escape reason}", nil, @token)
|
29
29
|
true
|
30
30
|
end
|
31
31
|
|
@@ -34,9 +34,9 @@ module DBLista::User
|
|
34
34
|
# @param id [Integer] bot ID
|
35
35
|
# @return [Boolean] true if operation succeded
|
36
36
|
def set_pending(id)
|
37
|
-
|
37
|
+
DList._validate_id id
|
38
38
|
|
39
|
-
|
39
|
+
DList._post("/bots/#{id}/set-pending", nil, @token)
|
40
40
|
true
|
41
41
|
end
|
42
42
|
end
|
data/lib/dblista/user/voting.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module DList::User
|
4
4
|
# User client - voting
|
5
5
|
module Voting
|
6
6
|
# Votes for a selected bot/server
|
@@ -9,10 +9,10 @@ module DBLista::User
|
|
9
9
|
# @param type [Symbol] type of entity (bot/server)
|
10
10
|
# @return [Boolean] true if operation succeded
|
11
11
|
def vote(id, type = :bot)
|
12
|
-
|
13
|
-
raise
|
12
|
+
DList._validate_id id
|
13
|
+
raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)
|
14
14
|
|
15
|
-
|
15
|
+
DList._post("/#{type}s/#{id}/vote", nil, @token)
|
16
16
|
true
|
17
17
|
end
|
18
18
|
end
|
data/lib/dblista/version.rb
CHANGED