dblista 0.1.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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dblista.gemspec +29 -0
- data/example/info.rb +3 -0
- data/lib/dblista.rb +76 -0
- data/lib/dblista/errors.rb +17 -0
- data/lib/dblista/info.rb +40 -0
- data/lib/dblista/list/bot.rb +57 -0
- data/lib/dblista/list/server.rb +36 -0
- data/lib/dblista/stats.rb +53 -0
- data/lib/dblista/user/actions.rb +44 -0
- data/lib/dblista/user/boosting.rb +31 -0
- data/lib/dblista/user/client.rb +36 -0
- data/lib/dblista/user/rating.rb +36 -0
- data/lib/dblista/user/voting.rb +18 -0
- data/lib/dblista/version.rb +6 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fe876f912dc34c34135859b96b9460f420e57cdd6e033bb52a085940399ac4fc
|
4
|
+
data.tar.gz: b7ab68ca09a1b4a7a430a1c863d15276a0c76775cfb2672a13ce65361b99d05b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4460c9f351195b3d80dca99723b59cf80aa07933f8ab1b2b7d6c2a1074d1b40d32b86935e400505d1352f1a7460efcaa1c23697981c77d457bd8ceac72ea4fe8
|
7
|
+
data.tar.gz: 6811d7ac6a357dcd8f3bc54d692de9708c057a6811954402aad3227b43577884c10be0a9ee103985f87a5b36249a66262f91d4b385e466f2c7fcc1a2cb0100a1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dblista (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (13.0.1)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x86-mingw32
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.17)
|
30
|
+
dblista!
|
31
|
+
rake (>= 12.3.3)
|
32
|
+
rspec (~> 3.2)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 deepivin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# DBLista
|
2
|
+
|
3
|
+
[Dokumentacja](https://www.rubydoc.info/github/marek12306/dblista-wrapper-ruby)
|
4
|
+
|
5
|
+
Gem pozwalający na komunikację z API DBListy. Pozwala m.in. na automatyczne wysyłanie statystyk (dla botów napisanych w Discordrb) oraz na CRUD botów oraz serwerów.
|
6
|
+
|
7
|
+
## Instalacja
|
8
|
+
|
9
|
+
Wystarczy dodać tą linijkę do Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dblista'
|
13
|
+
```
|
14
|
+
|
15
|
+
I potem odpalić komendę:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Albo zainstalować ręcznie poprzez gem:
|
20
|
+
|
21
|
+
$ gem install dblista
|
22
|
+
|
23
|
+
## Przykładowe użycie
|
24
|
+
|
25
|
+
Automatyczne statystyki:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
bot = Discordrb::Bot.new token: 'TOKEN'
|
29
|
+
dbl = DBLista::Stats.new 'DBLISTA_TOKEN', bot
|
30
|
+
```
|
31
|
+
|
32
|
+
Pobieranie topki botów:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
top = DBLista::List::Bot.top
|
36
|
+
puts top['data'].inspect
|
37
|
+
```
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z nim co chcesz.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dblista"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dblista.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "dblista/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dblista"
|
8
|
+
spec.version = DBLista::VERSION
|
9
|
+
spec.authors = ["deepivin"]
|
10
|
+
spec.email = ["marek12306@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Wrapper for dblista.pl API}
|
13
|
+
spec.homepage = "https://github.com/marek12306/dblista-wrapper-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
29
|
+
end
|
data/example/info.rb
ADDED
data/lib/dblista.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require_relative 'dblista/version'
|
9
|
+
require_relative 'dblista/info'
|
10
|
+
require_relative 'dblista/stats'
|
11
|
+
require_relative 'dblista/errors'
|
12
|
+
require_relative 'dblista/list/bot'
|
13
|
+
require_relative 'dblista/list/server'
|
14
|
+
require_relative 'dblista/user/client'
|
15
|
+
|
16
|
+
# Main module
|
17
|
+
module DBLista
|
18
|
+
# DBLista error class
|
19
|
+
class Error < StandardError; end
|
20
|
+
# API path prefix
|
21
|
+
API_PATH = 'https://api.dblista.pl/v1'
|
22
|
+
# Regexp for checking if string is a number
|
23
|
+
IS_NUMBER = /^\d+$/.freeze
|
24
|
+
|
25
|
+
# @!visibility private
|
26
|
+
def self._get(path)
|
27
|
+
req = URI.open("#{DBLista::API_PATH}#{path}")
|
28
|
+
JSON.parse req.read
|
29
|
+
end
|
30
|
+
|
31
|
+
def self._https(uri)
|
32
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
33
|
+
http.use_ssl = true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @!visibility private
|
38
|
+
def self._handle_request(req, uri, token, data)
|
39
|
+
req.body = data.to_json if data
|
40
|
+
req['Content-Type'] = 'application/json'
|
41
|
+
req['Authorization'] = token if token
|
42
|
+
response = _https(uri).request(req)
|
43
|
+
JSON.parse response.body
|
44
|
+
end
|
45
|
+
|
46
|
+
# @!visibility private
|
47
|
+
def self._post(path, data = nil, token = nil)
|
48
|
+
uri = URI("#{DBLista::API_PATH}#{path}")
|
49
|
+
req = Net::HTTP::Post.new(uri)
|
50
|
+
_handle_request(req, uri, token, data)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @!visibility private
|
54
|
+
def self._delete(path, data = nil, token = nil)
|
55
|
+
uri = URI("#{DBLista::API_PATH}#{path}")
|
56
|
+
req = Net::HTTP::Delete.new(uri)
|
57
|
+
_handle_request(req, uri, token, data)
|
58
|
+
end
|
59
|
+
|
60
|
+
# @!visibility private
|
61
|
+
def self._put(path, data = nil, token = nil)
|
62
|
+
uri = URI("#{DBLista::API_PATH}#{path}")
|
63
|
+
req = Net::HTTP::Put.new(uri)
|
64
|
+
_handle_request(req, uri, token, data)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @!visibility private
|
68
|
+
def self._validate_id(id)
|
69
|
+
raise DBLista::Error, DBLista::Errors::ID_NEEDED unless DBLista::IS_NUMBER.match?(id.to_s)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @!visibility private
|
73
|
+
def self._page_integer(input)
|
74
|
+
raise DBLista::Error, DBLista::Errors::PAGE_INTEGER unless input.is_a?(Integer)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Error messages
|
4
|
+
module DBLista::Errors
|
5
|
+
# Raised when ID is not provided
|
6
|
+
ID_NEEDED = 'You need to enter ID'
|
7
|
+
# Raised when provided page is not an integer
|
8
|
+
PAGE_INTEGER = 'Page must be an integer'
|
9
|
+
# Raised when token is not provided
|
10
|
+
TOKEN_NOT_PROVIDED = 'Token is not provided'
|
11
|
+
# Raised when type symbol is invalid
|
12
|
+
TYPE_NOT_ALLOWED = 'Only bot and server types are allowed'
|
13
|
+
# Raised wheen search query is not provided
|
14
|
+
QUERY_NOT_PROVIDED = 'Search query is not provided'
|
15
|
+
# Raised when body is not a hash
|
16
|
+
BODY_HASH = 'Body must be a hash'
|
17
|
+
end
|
data/lib/dblista/info.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module DBLista
|
7
|
+
# Bot/server/user detailed information
|
8
|
+
#
|
9
|
+
# @example Checking DBLista user information
|
10
|
+
# info = DBLista::Information.user 123456789012345678
|
11
|
+
# puts info['data']
|
12
|
+
module Information
|
13
|
+
# Fetches DBLista bot information
|
14
|
+
#
|
15
|
+
# @param id [Integer] bot ID
|
16
|
+
# @return [Hash] raw data from DBLista
|
17
|
+
def self.bot(id)
|
18
|
+
DBLista._validate_id id
|
19
|
+
DBLista._get("/bots/#{id}")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Fetches DBLista server information
|
23
|
+
#
|
24
|
+
# @param id [Integer] server ID
|
25
|
+
# @return [Hash] raw data from DBLista
|
26
|
+
def self.server(id)
|
27
|
+
DBLista._validate_id id
|
28
|
+
DBLista._get("/servers/#{id}")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Fetches DBLista user information
|
32
|
+
#
|
33
|
+
# @param id [Integer] user ID
|
34
|
+
# @return [Hash] raw data from DBLista
|
35
|
+
def self.user(id)
|
36
|
+
DBLista._validate_id id
|
37
|
+
DBLista._get("/users/#{id}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
# Lists
|
8
|
+
#
|
9
|
+
# @example Fetch top 25 bots
|
10
|
+
# top = DBLista::List::Bot.top
|
11
|
+
# puts top['data'].inspect
|
12
|
+
module DBLista::List
|
13
|
+
# Bot lists
|
14
|
+
module Bot
|
15
|
+
# Fetches top bots
|
16
|
+
#
|
17
|
+
# @param page [Integer] page
|
18
|
+
# @return [Hash] raw data from DBLista
|
19
|
+
def self.top(page = 0)
|
20
|
+
DBLista._page_integer page
|
21
|
+
DBLista._get("/bots/list/top/#{page}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Fetches premium bots
|
25
|
+
#
|
26
|
+
# @param page [Integer] page
|
27
|
+
# @return [Hash] raw data from DBLista
|
28
|
+
def self.premium(page = 0)
|
29
|
+
DBLista._page_integer page
|
30
|
+
DBLista._get("/bots/list/premium/#{page}")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Fetches unverified bots
|
34
|
+
#
|
35
|
+
# @return [Hash] raw data from DBLista
|
36
|
+
def self.unverified
|
37
|
+
DBLista._get('/bots/list/unverified')
|
38
|
+
end
|
39
|
+
|
40
|
+
# Fetches rejected bots
|
41
|
+
#
|
42
|
+
# @return [Hash] raw data from DBLista
|
43
|
+
def self.rejected
|
44
|
+
DBLista._get('/bots/list/rejected')
|
45
|
+
end
|
46
|
+
|
47
|
+
# Bot search
|
48
|
+
#
|
49
|
+
# @param query [String] query search
|
50
|
+
# @return [Hash] raw data from DBLista
|
51
|
+
def self.search(query)
|
52
|
+
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
53
|
+
|
54
|
+
DBLista._get("/bots/search/#{CGI.escape query}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module DBLista::List
|
6
|
+
# Server lists
|
7
|
+
module Server
|
8
|
+
# Fetches top servers
|
9
|
+
#
|
10
|
+
# @param page [Integer] page
|
11
|
+
# @return [Hash] raw data from DBLista
|
12
|
+
def self.top(page = 0)
|
13
|
+
DBLista._page_integer page
|
14
|
+
DBLista._get("/servers/list/top/#{page}")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Fetches premium servers
|
18
|
+
#
|
19
|
+
# @param page [Integer] page
|
20
|
+
# @return [Hash] raw data from DBLista
|
21
|
+
def self.premium(page = 0)
|
22
|
+
DBLista._page_integer page
|
23
|
+
DBLista._get("/servers/list/premium/#{page}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Server search
|
27
|
+
#
|
28
|
+
# @param query [String] search query
|
29
|
+
# @return [Hash] raw data from DBLista
|
30
|
+
def self.search(query)
|
31
|
+
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
32
|
+
|
33
|
+
DBLista._get("/servers/search/#{CGI.escape query}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module DBLista
|
7
|
+
# Class for updating bot statistics
|
8
|
+
#
|
9
|
+
# @example Hook bot stats to DBLista
|
10
|
+
# bot = Discordrb::Bot.new token: 'TOKEN'
|
11
|
+
# dbl = DBLista::Stats.new 'DBLISTA_TOKEN', bot
|
12
|
+
class Stats
|
13
|
+
attr_accessor :token
|
14
|
+
|
15
|
+
# @param token [String] DBLista bot token
|
16
|
+
# @param bot [Discordrb::Bot] discordrb bot for auto-sending statistics
|
17
|
+
def initialize(token, bot = nil)
|
18
|
+
raise DBLista::Error, DBLista::Errors::TOKEN_NOT_PROVIDED unless token
|
19
|
+
|
20
|
+
@token = token
|
21
|
+
if bot&.connected?
|
22
|
+
hook_bot(bot)
|
23
|
+
elsif bot
|
24
|
+
bot.ready { hook_bot(bot) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Hooks discordrb bot to stats client instance
|
29
|
+
#
|
30
|
+
# @param bot [Discordrb::Bot] the bot
|
31
|
+
# @return [Thread] stat updating thread
|
32
|
+
def hook_bot(bot)
|
33
|
+
@thread.exit if @thread&.alive?
|
34
|
+
@thread = Thread.new do
|
35
|
+
update_stats(bot.users.size, bot.servers.size)
|
36
|
+
sleep 10 * 60
|
37
|
+
end
|
38
|
+
@thread
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sends statistics to DBLista
|
42
|
+
#
|
43
|
+
# @param members [Integer] member count
|
44
|
+
# @param servers [Integer] server count
|
45
|
+
# @return [Hash] raw data from DBLista
|
46
|
+
def update_stats(members, servers)
|
47
|
+
DBLista._post('/bots/stats', {
|
48
|
+
'servers' => servers,
|
49
|
+
'members' => members
|
50
|
+
}, @token)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# User client - actions
|
6
|
+
module DBLista::User
|
7
|
+
module Actions
|
8
|
+
# Adds bot/server to DBLista
|
9
|
+
#
|
10
|
+
# @param body [Hash] raw body to send
|
11
|
+
# @param type [Symbol] type of entity (bot/server)
|
12
|
+
# @return [Hash] raw data from DBLista
|
13
|
+
def add(body, type = 'bot')
|
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)
|
16
|
+
|
17
|
+
DBLista._post("/#{type}s", body, @token)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Edits bot/server in DBLista
|
21
|
+
#
|
22
|
+
# @param body [Hash] raw body to send
|
23
|
+
# @param type [Symbol] type of entity (bot/server)
|
24
|
+
# @return [Hash] raw data from DBLista
|
25
|
+
def edit(body, type = :bot)
|
26
|
+
raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
|
27
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
28
|
+
|
29
|
+
DBLista._put("/#{type}s", body, @token)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Deletes bot/server from DBLista
|
33
|
+
#
|
34
|
+
# @param id [Integer] entity ID
|
35
|
+
# @param type [Symbol] type of entity (bot/server)
|
36
|
+
# @return [Hash] raw data from DBLista
|
37
|
+
def delete(id, type = :bot)
|
38
|
+
DBLista._validate_id id
|
39
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
40
|
+
|
41
|
+
DBLista._delete("/#{type}s/#{id}", nil, @token)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# User client - boosting
|
5
|
+
module DBLista::User
|
6
|
+
module Boosting
|
7
|
+
# Boosts selected bot/server
|
8
|
+
#
|
9
|
+
# @param id [Integer] entity ID
|
10
|
+
# @param type [Symbol] type of entity (bot/server)
|
11
|
+
# @return [Hash] raw data from DBLista
|
12
|
+
def boost(id, type = :bot)
|
13
|
+
DBLista._validate_id id
|
14
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless ALLOWED_TYPES.include?(type)
|
15
|
+
|
16
|
+
DBLista._post("/#{type}s/#{id}/boost", nil, @token)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Removes boost from a selected bot/server
|
20
|
+
#
|
21
|
+
# @param id [Integer] entity ID
|
22
|
+
# @param type [Symbol] type of entity (bot/server)
|
23
|
+
# @return [Hash] raw data from DBLista
|
24
|
+
def delete_boost(id, type = :bot)
|
25
|
+
DBLista._validate_id id
|
26
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
27
|
+
|
28
|
+
DBLista._delete("/#{type}s/#{id}/boost", nil, @token)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './actions'
|
4
|
+
require_relative './boosting'
|
5
|
+
require_relative './rating'
|
6
|
+
require_relative './voting'
|
7
|
+
|
8
|
+
# User module - client + client modules
|
9
|
+
module DBLista::User
|
10
|
+
# DBLista user client
|
11
|
+
#
|
12
|
+
# @example Server voting
|
13
|
+
# client = DBLista::User::Client.new "USER_TOKEN"
|
14
|
+
# response = client.vote(123456789012345678, :server)
|
15
|
+
#
|
16
|
+
# @example Bot rating
|
17
|
+
# client = DBLista::User::Client.new "USER_TOKEN"
|
18
|
+
# response = client.rate(123456789012345678, 5, 'Nice bot')
|
19
|
+
class Client
|
20
|
+
include DBLista::User::Voting
|
21
|
+
include DBLista::User::Actions
|
22
|
+
include DBLista::User::Boosting
|
23
|
+
include DBLista::User::Rating
|
24
|
+
|
25
|
+
# Allowed entity types to use
|
26
|
+
ALLOWED_TYPES = %i[bot server].freeze
|
27
|
+
|
28
|
+
attr_accessor :token
|
29
|
+
|
30
|
+
def initialize(token)
|
31
|
+
raise DBLista::Error, DBLista::Errors::TOKEN_NOT_PROVIDED unless token
|
32
|
+
|
33
|
+
@token = token
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# User client - rating
|
4
|
+
module DBLista::User
|
5
|
+
module Rating
|
6
|
+
# Sends rate for a selected bot/server
|
7
|
+
#
|
8
|
+
# @param id [Integer] entity ID
|
9
|
+
# @param rating [Integer] rating from 0 to 5
|
10
|
+
# @param details [String] details (description)
|
11
|
+
# @param type [Symbol] type of entity (bot/server)
|
12
|
+
# @return [Hash] raw data from DBLista
|
13
|
+
def rate(id, rating, details, type = :bot)
|
14
|
+
DBLista._validate_id id
|
15
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless ALLOWED_TYPES.include?(type)
|
16
|
+
|
17
|
+
DBLista._post("/#{type}s/#{id}/rate", {
|
18
|
+
rating: rating,
|
19
|
+
details: details
|
20
|
+
}, @token)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Removes rate for a selected bot/server
|
24
|
+
#
|
25
|
+
# @param id [Integer] entity ID
|
26
|
+
# @param target_id [Integer] target user to remove rate from (for owners only)
|
27
|
+
# @param type [Symbol] type of entity (bot/server)
|
28
|
+
# @return [Hash] raw data from DBLista
|
29
|
+
def delete_rate(id, target_id = nil, type = :bot)
|
30
|
+
DBLista._validate_id id
|
31
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
32
|
+
|
33
|
+
DBLista._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# User client - voting
|
4
|
+
module DBLista::User
|
5
|
+
module Voting
|
6
|
+
# Votes for a selected bot/server
|
7
|
+
#
|
8
|
+
# @param id [Integer] entity ID
|
9
|
+
# @param type [Symbol] type of entity (bot/server)
|
10
|
+
# @return [Hash] raw data from DBLista
|
11
|
+
def vote(id, type = :bot)
|
12
|
+
DBLista._validate_id id
|
13
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
14
|
+
|
15
|
+
DBLista._post("/#{type}s/#{id}/vote", nil, @token)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dblista
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- deepivin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- marek12306@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- dblista.gemspec
|
71
|
+
- example/info.rb
|
72
|
+
- lib/dblista.rb
|
73
|
+
- lib/dblista/errors.rb
|
74
|
+
- lib/dblista/info.rb
|
75
|
+
- lib/dblista/list/bot.rb
|
76
|
+
- lib/dblista/list/server.rb
|
77
|
+
- lib/dblista/stats.rb
|
78
|
+
- lib/dblista/user/actions.rb
|
79
|
+
- lib/dblista/user/boosting.rb
|
80
|
+
- lib/dblista/user/client.rb
|
81
|
+
- lib/dblista/user/rating.rb
|
82
|
+
- lib/dblista/user/voting.rb
|
83
|
+
- lib/dblista/version.rb
|
84
|
+
homepage: https://github.com/marek12306/dblista-wrapper-ruby
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.0.3
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Wrapper for dblista.pl API
|
107
|
+
test_files: []
|