topgg 1.0.2 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cbae83079b3b78337e9006b5850b43a609d5b14f95d05a0a8c30e16a7a1075e
4
- data.tar.gz: 89d011bb153dbab77d40a5c2fb2afb09c8345f14807acb5593746280fd25ca56
3
+ metadata.gz: efdefad75123d5205da0ca899e47fe4f3c0c3a3269b7dfd7a68697f206bf36ec
4
+ data.tar.gz: 99703e90fe21baa924be88ea389ddf0bfb8a90e2580ef29138e350784feab723
5
5
  SHA512:
6
- metadata.gz: 242cdd6fbce9eea79010911afc0223d5611a65689e3332d2ff7d2cbc050e431ce138b77617e6d4c53e38f43e1f6452bd09165be7edcf2374e1bd05ae7a18d76d
7
- data.tar.gz: 7d2fe752e4f83879594909fd6d96fa699227b9bb4c9e3bfa851c28341739365f170a3825304155c0c17bb86df95d369bda42467d72d388822b76f58a0a6d61bb
6
+ metadata.gz: a31882f04bd664e714198254b4338fe5d8c68503fba6b0ae83f71d0e36dff130052c6f9c06dfd9eeef8c0abd384e750173f359a84746d73819d3083397cfad0b
7
+ data.tar.gz: 3f70900291e2d8fe4f7a574eda247281bb4f7e295286cea11f256f2648348e67c9d48aa7ba4966cef3ccefe6f8bd78c538840cdea4ceac49f509dd3c3ffcf323
data/Gemfile CHANGED
@@ -5,5 +5,4 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in topgg.gemspec
6
6
  gemspec
7
7
 
8
- gem 'faraday'
9
8
  gem 'rake', '~> 13.0'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 rhydderchc
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,17 +1,27 @@
1
- # Top.gg Ruby
1
+ # [Top.gg](https://top.gg) Ruby
2
2
 
3
- This Software Development Kit provides you with a wrapper to the top.gg api, that allows you
3
+ The Top.gg Ruby SDK is a lighweight package, that allows you
4
4
  to fetch data from the top.gg api and post data such as statistics to the website.
5
5
 
6
+ It provides you with numerous methods to interact with the API.
6
7
  ## Dependencies
7
8
 
8
9
  * Ruby
9
- * Faraday (The client to automate requests)
10
10
 
11
11
  ## Installation
12
12
 
13
+ ``` bash
13
14
 
15
+ gem install topgg
14
16
 
17
+ ```
18
+ ## Note
19
+
20
+ You require a Token to interact with the Api.
21
+ The token can be found at `https://top.gg/bot/[YOUR_BOT_ID]/webhooks`
22
+
23
+
24
+ ![page](https://i.ibb.co/txp0ghr/Screenshot-from-2021-10-31-00-59-39.png)
15
25
  ## Example
16
26
 
17
27
  Here's a straightforward example of how to request data with the wrapper.
@@ -21,27 +31,29 @@ require 'topgg'
21
31
 
22
32
  client = Topgg.new("AUTH_TOKEN", "BOTID")
23
33
 
24
- client.getBot("1234").defAvatar
34
+ client.get_bot("1234").defAvatar
25
35
  # returns
26
36
  # "6debd47ed13483642cf09e832ed0bc1b"
27
37
 
28
38
  ```
29
- ### AutoPosting
39
+ ### Auto Posting
30
40
 
31
- The wrapper provides you with autoposting functionality
32
- with the wrapper posting bot statistics every 30 minutes.
33
- Here's how you can enable it
41
+ The library provides you with autoposting functionality, and autoposts at an interval of 30 minutes.
42
+ Here's how you can use it
34
43
 
35
44
  ```ruby
36
45
  require 'topgg'
37
46
  require 'discordrb'
38
47
 
39
48
  bot = Discordrb::Bot.new token: "TOKEN"
40
- client = Topgg.new("AUTH_TOKEN", "BOTID")
41
49
 
42
- client.autoPostStats(bot) # The discordrb bot client.
50
+ client = Topgg.new("AUTH_TOKEN", "BOTID")
51
+ bot.ready do |event|
52
+ client.auto_post_stats(bot) # The discordrb bot client.
53
+ end
54
+ bot.run
43
55
  ```
44
56
 
45
57
  # Documentation
46
58
 
47
- Check out the documentation [here](https://discord.com)
59
+ Check out the api reference [here](https://rubydoc.info/gems/topgg/)
data/lib/lib.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'faraday'
2
+
3
+ require_relative 'topgg/utils/request'
3
4
  require 'json'
4
5
  require_relative 'topgg/bot'
5
6
  require_relative 'topgg/botSearch'
@@ -15,90 +16,85 @@ class Topgg
15
16
  def initialize(token, id)
16
17
  @id = id
17
18
  @token = token
18
- @conn = Faraday.new(
19
- url: 'https://top.gg/api',
20
- headers: { 'authorization' => @token }
21
- )
19
+ @request = Dbl::Utils::Request.new(token)
22
20
  end
23
21
 
24
22
  # The method fetches bot statistics from top.gg
25
23
  # @param id [String] The id of the bot you want to fetch statistics from.
26
- # @return [Spreader::Bot] The Bot Object
27
- def getBot(id)
28
- resp = @conn.get("bots/#{id}")
24
+ # @return [Dbl::Bot] The Bot Object
25
+ def get_bot(id)
26
+ resp = @request.get("bots/#{id}")
29
27
 
30
- Spreader::Bot.new(JSON.parse(resp.body))
28
+ Dbl::Bot.new(resp)
31
29
  end
32
30
 
33
31
  # The method searches bots from top.gg using a keyword query.
34
- # @param query [String] the search term
35
- # @param limit [Integer] the amount of results to return
36
- # @param offset [Integer] The Amount of bots to skip
37
- # @param sort [Boolean] The fields to sort by.
38
- # @return [Spreader::BotSearch] The BotSearch Object
39
- def searchBot(query, limit: 50, offset: 0, sort: nil, fields: nil)
40
- resp = @conn.get('bots', { search: query, limit: limit, offset: offset, sort: sort, fields: fields })
41
- Spreader::BotSearch.new(JSON.parse(resp.body))
32
+ # @param [Object] params The parameters that can be used to query a search
33
+ # To know what the parameters are check it out here
34
+ # @return [Dbl::BotSearch] The BotSearch Object
35
+ def search_bot(params)
36
+ resp = @request.get('bots/search', params)
37
+ Dbl::BotSearch.new(resp)
42
38
  end
43
39
 
44
40
  # Search for a user on top.gg with id
45
41
  # @param id [String] The id of the user to search for.
46
- # @return [Spreader::User]
42
+ # @return [Dbl::User]
47
43
  def user(id)
48
- resp = @conn.get("users/#{id}")
44
+ resp = @request.get("users/#{id}")
49
45
 
50
- Spreader::User.new(JSON.parse(resp.body))
46
+ Dbl::User.new(resp)
51
47
  end
52
48
 
53
49
  # Get Bot statistics.
54
50
  # @param id [String] Id of the bot you want to get statistics of
55
- # @return [Spreader::Stats]
56
- def getStats(id)
57
- resp = @conn.get("bots/#{id}/stats")
51
+ # @return [Dbl::Stats]
52
+ def get_stats(id)
53
+ resp = @request.get("bots/#{id}/stats")
58
54
 
59
- Spreader::Stats.new(JSON.parse(resp.body))
55
+ Dbl::Stats.new(resp)
60
56
  end
61
57
 
62
58
  # Mini-method to query if the bot(self) was voted by the user.
63
59
  # @param userid [String] The user id.
64
60
  # @return [Boolean]
65
61
  def voted?(userid)
66
- resp = @conn.get("bots/#{@id}/check", { userId: userid })
62
+ resp = @request.get("bots/#{@id}/check", { userId: userid })
67
63
 
68
- ret = JSON.parse(resp.body)
64
+ ret = resp
69
65
  ret['voted'] == 1
70
66
  end
71
67
 
72
68
  # Get the Last 1000 votes of the bot(self)
73
- # @return [Spreader::Votes]
69
+ # @return [Dbl::Votes]
74
70
  def votes
75
- resp = @conn.get("bots/#{@id}/votes")
71
+ resp = @request.get("bots/#{@id}/votes")
76
72
 
77
- Spreader::Votes.new(JSON.parse(resp.body))
73
+ Dbl::Votes.new(resp)
78
74
  end
79
75
 
80
76
  # Post Bot Statistics to the website
81
77
  # @param server_count [Integer] The amount of servers the bot is in.
82
78
  # @param shards [Integer] The amount of servers the bot is in per shard
83
79
  # @param shard_count [Integer] The total number of shards.
84
- def postStats(server_count, shards: nil, shard_count: nil)
85
- jsonPost = {
80
+ def post_stats(server_count, shards: nil, shard_count: nil)
81
+ json_post = {
86
82
  server_count: server_count,
87
83
  shards: shards,
88
84
  shard_count: shard_count
89
85
  }.to_json
90
- @conn.post("bots/#{@id}/stats", jsonPost, { 'Content-Type' => 'application/json' })
86
+ @request.post("bots/#{@id}/stats", json_post, { 'Content-Type' => 'application/json' })
91
87
  end
92
88
 
93
- # Autopost stats on to the top.gg website
89
+ # Auto-posts stats on to the top.gg website
94
90
  # @param client [Discordrb::Bot] instanceof discordrb client.
95
- def autoPostStats(client)
91
+ def auto_post_stats(client)
96
92
  semaphore = Mutex.new
97
93
  Thread.new do
98
94
  semaphore.synchronize do
99
95
  interval 1800 do
100
- serverLen = client.servers.length
101
- postStats(serverLen)
96
+ server_len = client.servers.length
97
+ post_stats(server_len)
102
98
  print("[TOPGG] : \033[31;1;4m Bot statistics has been successfully posted!\033[0m")
103
99
  end
104
100
  end
@@ -106,18 +102,19 @@ class Topgg
106
102
  end
107
103
 
108
104
  # Mini-method to get statistics on self
109
- # @return [getBot]
105
+ # @return [get_bot]
110
106
  def self
111
- getBot(@id)
107
+ get_bot(@id)
112
108
  end
113
109
 
114
110
  def interval(seconds)
115
111
  loop do
116
112
  yield
117
- sleep seconds
118
-
113
+ sleep seconds
119
114
  end
120
115
  end
121
116
  end
122
117
 
123
118
 
119
+
120
+
data/lib/topgg/bot.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Spreader
1
+ module Dbl
2
2
  # The Bot class spreads the json parsed hash into different methods
3
3
  class Bot
4
4
  # Initializes the Bot class
@@ -10,28 +10,31 @@ module Spreader
10
10
  # @return [Hash]
11
11
  attr_reader :obj
12
12
 
13
+ alias :raw :obj
14
+
15
+ alias data obj
13
16
  # Returns error message, if there's an error
14
17
  # @return [String]
15
18
  def error
16
- @obj['error']
19
+ @obj['error'].to_str
17
20
  end
18
21
 
19
22
  # Returns the default Avatar of the client
20
23
  # @return [String]
21
24
  def defAvatar
22
- @obj['defAvatar']
25
+ @obj['defAvatar'].to_str
23
26
  end
24
27
 
25
28
  # Returns the invite link of the bot
26
29
  # @return [String]
27
30
  def invite
28
- @obj['invite']
31
+ @obj['invite'].to_str
29
32
  end
30
33
 
31
34
  # Returns the bot website, if configured
32
35
  # @return [String]
33
36
  def website
34
- @obj['website']
37
+ @obj['website'].to_str
35
38
  end
36
39
 
37
40
  # Returns support server link
@@ -43,37 +46,37 @@ module Spreader
43
46
  # Returns github repository link, if any
44
47
  # @return [String]
45
48
  def github
46
- @obj['github']
49
+ @obj['github'].to_str
47
50
  end
48
51
 
49
52
  # Returns the long Description of the bot
50
53
  # @return [String]
51
54
  def longdesc
52
- @obj['longdesc']
55
+ @obj['longdesc'].to_str
53
56
  end
54
57
 
55
58
  # Returns the short description of the bot
56
59
  # @return [String]
57
60
  def shortdesc
58
- @obj['shortdesc']
61
+ @obj['shortdesc'].to_str
59
62
  end
60
63
 
61
64
  # Returns the default prefix of the bot
62
65
  # @return [String]
63
66
  def prefix
64
- @obj['prefix']
67
+ @obj['prefix'].to_str
65
68
  end
66
69
 
67
70
  # Returns the bot library
68
71
  # @return [String]
69
72
  def lib
70
- @obj['lib']
73
+ @obj['lib'].to_str
71
74
  end
72
75
 
73
76
  # Returns the bot client id
74
77
  # @return [String]
75
78
  def clientid
76
- @obj['clientid']
79
+ @obj['clientid'].to_str
77
80
  end
78
81
 
79
82
  # Returns the avatar link of the bot
@@ -85,19 +88,19 @@ module Spreader
85
88
  # Returns the bot id
86
89
  # @return [String]
87
90
  def id
88
- @obj['id']
91
+ @obj['id'].to_str
89
92
  end
90
93
 
91
94
  # Returns the bot descriminator
92
95
  # @return [String]
93
96
  def descriminator
94
- @obj['descriminator']
97
+ @obj['descriminator'].to_str
95
98
  end
96
99
 
97
100
  # Returns the bot username
98
101
  # @return [String]
99
102
  def username
100
- @obj['username']
103
+ @obj['username'].to_str
101
104
  end
102
105
 
103
106
  # Returns the date on which the bot was submitted
@@ -115,61 +118,61 @@ module Spreader
115
118
  # Returns the amount of shards
116
119
  # @return [String]
117
120
  def shard_count
118
- @obj['shard_count']
121
+ @obj['shard_count'].to_str
119
122
  end
120
123
 
121
124
  # Returns configured guilds in which the bot is in
122
125
  # @return [String]
123
126
  def guilds
124
- @obj['guilds']
127
+ @obj['guilds'].to_str
125
128
  end
126
129
 
127
130
  # Returns the amount of guilds per shard of the bot
128
131
  # @return [String]
129
132
  def shards
130
- @obj['shards']
133
+ @obj['shards'].to_str
131
134
  end
132
135
 
133
136
  # Returns the monthyPoints of the bot
134
137
  # @return [String]
135
138
  def monthlyPoints
136
- @obj['monthlyPoints']
139
+ @obj['monthlyPoints'].to_str
137
140
  end
138
141
 
139
142
  # Returns the total points of the bot
140
143
  # @return [String]
141
144
  def points
142
- @obj['points']
145
+ @obj['points'].to_str
143
146
  end
144
147
 
145
148
  # Returns true/false depending on if the bot is certified or not
146
149
  # @return [Boolean]
147
150
  def certifiedBot
148
- @obj['certifiedBot']
151
+ @obj['certifiedBot'].to_str
149
152
  end
150
153
 
151
154
  # Returns the owner ids
152
155
  # @return [Array<String>]
153
156
  def owners
154
- @obj['owners']
157
+ @obj['owners'].to_str
155
158
  end
156
159
 
157
160
  # Return the bot tags
158
161
  # @return [Array<String>]
159
162
  def tags
160
- @obj['tags']
163
+ @obj['tags'].to_str
161
164
  end
162
165
 
163
166
  # Returns the bot banner url
164
167
  # @return [String]
165
168
  def bannerUrl
166
- @obj['bannerUrl']
169
+ @obj['bannerUrl'].to_str
167
170
  end
168
171
 
169
172
  # Returns the donate bot guild ID
170
173
  # @return [String]
171
174
  def donatebotguildid
172
- @obj['donatebotguildid']
175
+ @obj['donatebotguildid'].to_str
173
176
  end
174
177
  end
175
178
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- module Spreader
2
+ module Dbl
3
3
  # This class spreads the BotSearch Response body into different methods
4
4
  class BotSearch
5
5
  # Initalizes the BotSearch class
@@ -10,11 +10,15 @@ module Spreader
10
10
  # Get raw hash response
11
11
  # @return [Hash]
12
12
  attr_reader :obj
13
+
14
+ alias raw obj
15
+
16
+ alias data obj
13
17
 
14
18
  # The Total number of results
15
19
  # @return [Integer]
16
20
  def total
17
- @obj['total']
21
+ @obj['total'].to_i
18
22
  end
19
23
 
20
24
  # The first result
@@ -26,7 +30,7 @@ module Spreader
26
30
  # The number of bots shown in the first page
27
31
  # @return [Integer]
28
32
  def count
29
- @obj['count']
33
+ @obj['count'].to_i
30
34
  end
31
35
 
32
36
  # Iterates through the results
data/lib/topgg/stats.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Spreader
1
+ module Dbl
2
2
  # The Stats class spreads the json response into different methods
3
3
  class Stats
4
4
  # Initializes the Stats class
@@ -9,7 +9,10 @@ module Spreader
9
9
 
10
10
  # Returns raw Hash of the response
11
11
  attr_reader :obj
12
+
13
+ alias raw obj
12
14
 
15
+ alias data obj
13
16
  # Returns the server Count of the bot
14
17
  # @return [Integer]
15
18
  def server_count
data/lib/topgg/user.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- module Spreader
2
+ module Dbl
3
3
  # The User class, used for Spreading the response body into different methods
4
4
  class User
5
5
  # Instantiates the class variables
@@ -10,6 +10,9 @@ module Spreader
10
10
 
11
11
  attr_reader :obj
12
12
 
13
+ alias raw obj
14
+
15
+ alias data obj
13
16
  # Check for errors, if any
14
17
  def error
15
18
  @obj['error']
data/lib/topgg/votes.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Spreader
1
+ module Dbl
2
2
  # This class Spreads the Vote response body into different methods.
3
3
  class Votes
4
4
  # Initializes the votes class
@@ -10,7 +10,10 @@ module Spreader
10
10
  # Get raw hash return of the object
11
11
  # @return [Hash]
12
12
  attr_reader :obj
13
+
14
+ alias raw obj
13
15
 
16
+ alias data obj
14
17
  # Get the first vote amongst all the other votes.
15
18
  # @return [Spreader::User]
16
19
  def first
data/topgg.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'topgg'
5
- spec.version = '1.0.2'
5
+ spec.version = '1.1.0'
6
6
  spec.authors = ['Adonis Tremblay']
7
7
  spec.email = ['rhydderchc@gmail.com']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: topgg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adonis Tremblay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-29 00:00:00.000000000 Z
11
+ date: 2021-10-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is a ruby library of the top.gg API.
14
14
  email:
@@ -17,9 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".bundle/config"
21
- - CHANGELOG.md
22
20
  - Gemfile
21
+ - LICENSE
23
22
  - LICENSE.txt
24
23
  - README.md
25
24
  - Rakefile
@@ -29,7 +28,6 @@ files:
29
28
  - lib/topgg/stats.rb
30
29
  - lib/topgg/user.rb
31
30
  - lib/topgg/votes.rb
32
- - pkg/topgg-1.0.1.gem
33
31
  - topgg.gemspec
34
32
  homepage: https://github.com/rhydderchc/topgg-ruby
35
33
  licenses:
@@ -54,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  requirements: []
57
- rubygems_version: 3.0.3
55
+ rubygems_version: 3.2.22
58
56
  signing_key:
59
57
  specification_version: 4
60
58
  summary: A top.gg api wrapper for ruby.
data/.bundle/config DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_WITHOUT: "test"
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2021-06-24
4
-
5
- - Initial release
data/pkg/topgg-1.0.1.gem DELETED
Binary file