dblista 0.1.0 → 0.1.5

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: fe876f912dc34c34135859b96b9460f420e57cdd6e033bb52a085940399ac4fc
4
- data.tar.gz: b7ab68ca09a1b4a7a430a1c863d15276a0c76775cfb2672a13ce65361b99d05b
3
+ metadata.gz: a8a9f1ef63473322f8f5cfb544e460fe77740bfba0bf6e767be8d583f2906cb6
4
+ data.tar.gz: 855aeed578c2e189b9c57098e1978b24c1a38a2225ddb232fa84959f6ac2c264
5
5
  SHA512:
6
- metadata.gz: 4460c9f351195b3d80dca99723b59cf80aa07933f8ab1b2b7d6c2a1074d1b40d32b86935e400505d1352f1a7460efcaa1c23697981c77d457bd8ceac72ea4fe8
7
- data.tar.gz: 6811d7ac6a357dcd8f3bc54d692de9708c057a6811954402aad3227b43577884c10be0a9ee103985f87a5b36249a66262f91d4b385e466f2c7fcc1a2cb0100a1
6
+ metadata.gz: cc04945b098ae8850aac02baec8cc6d20fc8f6388ec60e86a8ac6533d00b85d6439613ea7da5ba5a0dc097f95bba79c4f09b3a718fda7954215723d1ab887bb3
7
+ data.tar.gz: 3c94d344e3c0e5f61a0114daa40845dfd8d83d60baaa2f2ec942b7618e37c0d6bd5143dfaf1b3b110f5721daa6e38b62df84617695f899477eed4119ff0b9723
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dblista (0.1.0)
4
+ dblista (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # DBLista
1
+ # DBLista Ruby wrapper [![Gem Version](https://badge.fury.io/rb/dblista.svg)](https://badge.fury.io/rb/dblista)
2
2
 
3
3
  [Dokumentacja](https://www.rubydoc.info/github/marek12306/dblista-wrapper-ruby)
4
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.
5
+ Gem pozwalający na komunikację z API DBListy. Pozwala m.in. na automatyczne wysyłanie statystyk (dla botów napisanych w Discordrb), CRUD botów i serwerów oraz pare innych rzeczy.
6
6
 
7
7
  ## Instalacja
8
8
 
@@ -36,6 +36,6 @@ top = DBLista::List::Bot.top
36
36
  puts top['data'].inspect
37
37
  ```
38
38
 
39
- ## License
39
+ ## Licencja
40
40
 
41
41
  Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z nim co chcesz.
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Wrapper for dblista.pl API}
13
13
  spec.homepage = "https://github.com/marek12306/dblista-wrapper-ruby"
14
14
  spec.license = "MIT"
15
+ spec.required_ruby_version = '>= 2.4'
15
16
 
16
17
  # Specify which files should be added to the gem when it is released.
17
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -22,12 +22,6 @@ module DBLista
22
22
  # Regexp for checking if string is a number
23
23
  IS_NUMBER = /^\d+$/.freeze
24
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
25
  def self._https(uri)
32
26
  Net::HTTP.new(uri.host, uri.port).tap do |http|
33
27
  http.use_ssl = true
@@ -40,7 +34,16 @@ module DBLista
40
34
  req['Content-Type'] = 'application/json'
41
35
  req['Authorization'] = token if token
42
36
  response = _https(uri).request(req)
43
- JSON.parse response.body
37
+ result = JSON.parse response.body
38
+ raise DBLista::Error, result['error'].capitalize unless result['status'] == 'success'
39
+ result
40
+ end
41
+
42
+ # @!visibility private
43
+ def self._get(path, token = nil)
44
+ uri = URI("#{DBLista::API_PATH}#{path}")
45
+ req = Net::HTTP::Get.new(uri)
46
+ _handle_request(req, uri, token, nil)
44
47
  end
45
48
 
46
49
  # @!visibility private
@@ -14,4 +14,6 @@ module DBLista::Errors
14
14
  QUERY_NOT_PROVIDED = 'Search query is not provided'
15
15
  # Raised when body is not a hash
16
16
  BODY_HASH = 'Body must be a hash'
17
+ # Raised when token is invalid or expired
18
+ INVALID_TOKEN = 'Invalid or expired token'
17
19
  end
@@ -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
  #
@@ -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
  #
@@ -4,6 +4,7 @@ require_relative './actions'
4
4
  require_relative './boosting'
5
5
  require_relative './rating'
6
6
  require_relative './voting'
7
+ require_relative './notifications'
7
8
 
8
9
  # User module - client + client modules
9
10
  module DBLista::User
@@ -21,6 +22,7 @@ module DBLista::User
21
22
  include DBLista::User::Actions
22
23
  include DBLista::User::Boosting
23
24
  include DBLista::User::Rating
25
+ include DBLista::User::Notifications
24
26
 
25
27
  # Allowed entity types to use
26
28
  ALLOWED_TYPES = %i[bot server].freeze
@@ -31,6 +33,22 @@ module DBLista::User
31
33
  raise DBLista::Error, DBLista::Errors::TOKEN_NOT_PROVIDED unless token
32
34
 
33
35
  @token = token
36
+
37
+ raise DBLista::Error, DBLista::Errors::INVALID_TOKEN unless me['status'] == 'success'
38
+ end
39
+
40
+ # Fetches information about current user
41
+ #
42
+ # @return [Hash] raw data from DBLista
43
+ def me
44
+ DBLista._get('/users/me', @token)
45
+ end
46
+
47
+ # Fetches current user guilds
48
+ #
49
+ # @return [Hash] raw data from DBLista
50
+ def guilds
51
+ DBLista._get('/users/me/guilds', @token)
34
52
  end
35
53
  end
36
54
  end
@@ -0,0 +1,20 @@
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
+ end
20
+ 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
  #
@@ -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.0'
5
+ VERSION = '0.1.5'
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.0
4
+ version: 0.1.5
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-03 00:00:00.000000000 Z
11
+ date: 2020-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,7 @@ files:
78
78
  - lib/dblista/user/actions.rb
79
79
  - lib/dblista/user/boosting.rb
80
80
  - lib/dblista/user/client.rb
81
+ - lib/dblista/user/notifications.rb
81
82
  - lib/dblista/user/rating.rb
82
83
  - lib/dblista/user/voting.rb
83
84
  - lib/dblista/version.rb
@@ -93,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - ">="
95
96
  - !ruby/object:Gem::Version
96
- version: '0'
97
+ version: '2.4'
97
98
  required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
100
  - - ">="