topgg 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ccf9bfc94f4939b8638002c04189a3ef52caf2d22403ef387b188184e7d0735c
4
+ data.tar.gz: b66aecd679df93a5db506f83fddfc825872994940f79ddf22e6ab235fa4709fb
5
+ SHA512:
6
+ metadata.gz: 4913aef45f94f44a694a1b6bd1ff185c5908443dc811b16f7652d4fd5d30c1f81a2821830d1ca61ab2a6994e5307980853d094215044fffb1ca08b351a57d0da
7
+ data.tar.gz: 8d82c6d6831f29322692d57120b7340ecef95d14962fe49e69946fca92b1f31337cd8a043b8f83bdb9da173de315fb8fa03a7c0e95d12ec00dc821f5247fcdf6
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_WITHOUT: "test"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-06-24
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in topgg.gemspec
6
+ gemspec
7
+
8
+ gem 'faraday'
9
+ gem 'rake', '~> 13.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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,47 @@
1
+ # Top.gg Ruby
2
+
3
+ This Software Development Kit provides you with a wrapper to the top.gg api, that allows you
4
+ to fetch data from the top.gg api and post data such as statistics to the website.
5
+
6
+ ## Dependencies
7
+
8
+ * Ruby
9
+ * Faraday (The client to automate requests)
10
+
11
+ ## Installation
12
+
13
+
14
+
15
+ ## Example
16
+
17
+ Here's a straightforward example of how to request data with the wrapper.
18
+
19
+ ```ruby
20
+ require 'topgg'
21
+
22
+ client = Topgg.new("AUTH_TOKEN", "BOTID")
23
+
24
+ client.getBot("1234").defAvatar
25
+ # returns
26
+ # "6debd47ed13483642cf09e832ed0bc1b"
27
+
28
+ ```
29
+ ### AutoPosting
30
+
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
34
+
35
+ ```ruby
36
+ require 'topgg'
37
+ require 'discordrb'
38
+
39
+ bot = Discordrb::Bot.new token: "TOKEN"
40
+ client = Topgg.new("AUTH_TOKEN", "BOTID")
41
+
42
+ client.autoPostStats(bot) # The discordrb bot client.
43
+ ```
44
+
45
+ # Documentation
46
+
47
+ Check out the documentation [here](https://discord.com)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/lib/lib.rb ADDED
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+ require 'faraday'
3
+ require 'json'
4
+ require_relative 'topgg/bot'
5
+ require_relative 'topgg/botSearch'
6
+ require_relative 'topgg/user'
7
+ require_relative 'topgg/stats'
8
+ require_relative 'topgg/votes'
9
+ # Class Topgg
10
+ # The class instantiates all the methods for api requests and posts.
11
+ class Topgg
12
+ # initializes the class attributes.
13
+ # @param token [String] The authorization token from top.gg
14
+ # @param id [String] The client id of the bot.
15
+ def initialize(token, id)
16
+ @id = id
17
+ @token = token
18
+ @conn = Faraday.new(
19
+ url: 'https://top.gg/api',
20
+ headers: { 'authorization' => @token }
21
+ )
22
+ end
23
+
24
+ # The method fetches bot statistics from top.gg
25
+ # @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}")
29
+
30
+ Spreader::Bot.new(JSON.parse(resp.body))
31
+ end
32
+
33
+ # 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))
42
+ end
43
+
44
+ # Search for a user on top.gg with id
45
+ # @param id [String] The id of the user to search for.
46
+ # @return [Spreader::User]
47
+ def user(id)
48
+ resp = @conn.get("users/#{id}")
49
+
50
+ Spreader::User.new(JSON.parse(resp.body))
51
+ end
52
+
53
+ # Get Bot statistics.
54
+ # @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")
58
+
59
+ Spreader::Stats.new(JSON.parse(resp.body))
60
+ end
61
+
62
+ # Mini-method to query if the bot(self) was voted by the user.
63
+ # @param userid [String] The user id.
64
+ # @return [Boolean]
65
+ def voted?(userid)
66
+ resp = @conn.get("bots/#{@id}/check", { userId: userid })
67
+
68
+ ret = JSON.parse(resp.body)
69
+ ret['voted'] == 1
70
+ end
71
+
72
+ # Get the Last 1000 votes of the bot(self)
73
+ # @return [Spreader::Votes]
74
+ def votes
75
+ resp = @conn.get("bots/#{@id}/votes")
76
+
77
+ Spreader::Votes.new(JSON.parse(resp.body))
78
+ end
79
+
80
+ # Post Bot Statistics to the website
81
+ # @param server_count [Integer] The amount of servers the bot is in.
82
+ # @param shards [Integer] The amount of servers the bot is in per shard
83
+ # @param shard_count [Integer] The total number of shards.
84
+ def postStats(server_count, shards: nil, shard_count: nil)
85
+ jsonPost = {
86
+ server_count: server_count,
87
+ shards: shards,
88
+ shard_count: shard_count
89
+ }.to_json
90
+ @conn.post("bots/#{@id}/stats", jsonPost, { 'Content-Type' => 'application/json' })
91
+ end
92
+
93
+ # Autopost stats on to the top.gg website
94
+ # @param client [Discordrb::Bot] instanceof discordrb client.
95
+ def autoPostStats(client)
96
+ serverLen = client.servers.length
97
+ interval 1800 do
98
+ postStats(serverLen)
99
+ end
100
+ end
101
+ # Mini-method to get statistics on self
102
+ # @return [getBot]
103
+ def self
104
+ getBot(@id)
105
+ end
106
+
107
+ def interval(seconds)
108
+ loop do
109
+ yield
110
+ sleep seconds
111
+ end
112
+ end
113
+ end
114
+
115
+
data/lib/topgg/bot.rb ADDED
@@ -0,0 +1,175 @@
1
+ module Spreader
2
+ # The Bot class spreads the json parsed hash into different methods
3
+ class Bot
4
+ # Initializes the Bot class
5
+ # @param obj [Object]
6
+ def initialize(obj)
7
+ @obj = obj
8
+ end
9
+ # Returns raw hash of the parsed json object
10
+ # @return [Hash]
11
+ attr_reader :obj
12
+
13
+ # Returns error message, if there's an error
14
+ # @return [String]
15
+ def error
16
+ @obj['error']
17
+ end
18
+
19
+ # Returns the default Avatar of the client
20
+ # @return [String]
21
+ def defAvatar
22
+ @obj['defAvatar']
23
+ end
24
+
25
+ # Returns the invite link of the bot
26
+ # @return [String]
27
+ def invite
28
+ @obj['invite']
29
+ end
30
+
31
+ # Returns the bot website, if configured
32
+ # @return [String]
33
+ def website
34
+ @obj['website']
35
+ end
36
+
37
+ # Returns support server link
38
+ # @return [String]
39
+ def support
40
+ "https://discord.gg/#{@obj['support']}"
41
+ end
42
+
43
+ # Returns github repository link, if any
44
+ # @return [String]
45
+ def github
46
+ @obj['github']
47
+ end
48
+
49
+ # Returns the long Description of the bot
50
+ # @return [String]
51
+ def longdesc
52
+ @obj['longdesc']
53
+ end
54
+
55
+ # Returns the short description of the bot
56
+ # @return [String]
57
+ def shortdesc
58
+ @obj['shortdesc']
59
+ end
60
+
61
+ # Returns the default prefix of the bot
62
+ # @return [String]
63
+ def prefix
64
+ @obj['prefix']
65
+ end
66
+
67
+ # Returns the bot library
68
+ # @return [String]
69
+ def lib
70
+ @obj['lib']
71
+ end
72
+
73
+ # Returns the bot client id
74
+ # @return [String]
75
+ def clientid
76
+ @obj['clientid']
77
+ end
78
+
79
+ # Returns the avatar link of the bot
80
+ # @return [String]
81
+ def avatar
82
+ "https://cdn.discordapp.com/avatars/#{@obj['id']}/#{@obj['avatar']}.webp?size=1024"
83
+ end
84
+
85
+ # Returns the bot id
86
+ # @return [String]
87
+ def id
88
+ @obj['id']
89
+ end
90
+
91
+ # Returns the bot descriminator
92
+ # @return [String]
93
+ def descriminator
94
+ @obj['descriminator']
95
+ end
96
+
97
+ # Returns the bot username
98
+ # @return [String]
99
+ def username
100
+ @obj['username']
101
+ end
102
+
103
+ # Returns the date on which the bot was submitted
104
+ # @return [Date]
105
+ def date
106
+ Date.parse(@obj['date'])
107
+ end
108
+
109
+ # Returns the server count of the bot
110
+ # @return [Integer]
111
+ def server_count
112
+ @obj['server_count'].to_i
113
+ end
114
+
115
+ # Returns the amount of shards
116
+ # @return [String]
117
+ def shard_count
118
+ @obj['shard_count']
119
+ end
120
+
121
+ # Returns configured guilds in which the bot is in
122
+ # @return [String]
123
+ def guilds
124
+ @obj['guilds']
125
+ end
126
+
127
+ # Returns the amount of guilds per shard of the bot
128
+ # @return [String]
129
+ def shards
130
+ @obj['shards']
131
+ end
132
+
133
+ # Returns the monthyPoints of the bot
134
+ # @return [String]
135
+ def monthlyPoints
136
+ @obj['monthlyPoints']
137
+ end
138
+
139
+ # Returns the total points of the bot
140
+ # @return [String]
141
+ def points
142
+ @obj['points']
143
+ end
144
+
145
+ # Returns true/false depending on if the bot is certified or not
146
+ # @return [Boolean]
147
+ def certifiedBot
148
+ @obj['certifiedBot']
149
+ end
150
+
151
+ # Returns the owner ids
152
+ # @return [Array<String>]
153
+ def owners
154
+ @obj['owners']
155
+ end
156
+
157
+ # Return the bot tags
158
+ # @return [Array<String>]
159
+ def tags
160
+ @obj['tags']
161
+ end
162
+
163
+ # Returns the bot banner url
164
+ # @return [String]
165
+ def bannerUrl
166
+ @obj['bannerUrl']
167
+ end
168
+
169
+ # Returns the donate bot guild ID
170
+ # @return [String]
171
+ def donatebotguildid
172
+ @obj['donatebotguildid']
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module Spreader
3
+ # This class spreads the BotSearch Response body into different methods
4
+ class BotSearch
5
+ # Initalizes the BotSearch class
6
+ # @param obj [Object] Response Hash
7
+ def initialize(obj)
8
+ @obj = obj
9
+ end
10
+ # Get raw hash response
11
+ # @return [Hash]
12
+ attr_reader :obj
13
+
14
+ # The Total number of results
15
+ # @return [Integer]
16
+ def total
17
+ @obj['total']
18
+ end
19
+
20
+ # The first result
21
+ # @return [Spreader::Bot]
22
+ def first
23
+ Spreader::Bot.new(@obj['results'][0])
24
+ end
25
+
26
+ # The number of bots shown in the first page
27
+ # @return [Integer]
28
+ def count
29
+ @obj['count']
30
+ end
31
+
32
+ # Iterates through the results
33
+ # @return [Array<Spreader::Bot>]
34
+ def results
35
+ arr = []
36
+ flag = 0 # iteration flag
37
+ @obj['results'].each do |data|
38
+ arr[flag] = Spreader::Bot.new(data)
39
+ flag += 1
40
+ end
41
+ arr
42
+ end
43
+
44
+ # Length of the results.
45
+ # @return [Integer]
46
+ def size
47
+ @obj['results'].length
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ module Spreader
2
+ # The Stats class spreads the json response into different methods
3
+ class Stats
4
+ # Initializes the Stats class
5
+ # @param obj [Object] Response Hash
6
+ def initialize(obj)
7
+ @obj = obj
8
+ end
9
+
10
+ # Returns raw Hash of the response
11
+ attr_reader :obj
12
+
13
+ # Returns the server Count of the bot
14
+ # @return [Integer]
15
+ def server_count
16
+ @obj['server_count']
17
+ end
18
+
19
+ # The amount of servers per shard
20
+ # @return [Integer]
21
+ def shards
22
+ @obj['shards']
23
+ end
24
+
25
+ # Returns the total number of shards
26
+ # @return [Integer]
27
+ def shard_count
28
+ @obj['shard_count']
29
+ end
30
+ end
31
+ end
data/lib/topgg/user.rb ADDED
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+ module Spreader
3
+ # The User class, used for Spreading the response body into different methods
4
+ class User
5
+ # Instantiates the class variables
6
+ # @param obj [Object] Response Data Object
7
+ def initialize(obj)
8
+ @obj = obj
9
+ end
10
+
11
+ attr_reader :obj
12
+
13
+ # Check for errors, if any
14
+ def error
15
+ @obj['error']
16
+ end
17
+
18
+ # The Id of the user
19
+ def id
20
+ @obj['id']
21
+ end
22
+
23
+ # The username of the user
24
+ def username
25
+ @obj['username']
26
+ end
27
+
28
+ # The avatar of the user
29
+ # @return [String]
30
+ def avatar
31
+ "https://cdn.discordapp.com/avatars/#{@obj['id']}/#{@obj['avatar']}.webp?size=1024"
32
+ end
33
+
34
+ # The default avatar of the user
35
+ # @return [String]
36
+ def defAvatar
37
+ @obj['defAvatar']
38
+ end
39
+
40
+ # Returns true/false depending upon if the user is a moderator or not.
41
+ # @return [Boolean]
42
+ def mod
43
+ @obj['mod']
44
+ end
45
+
46
+ # Returns true/false depending upon if the user is a supporter or not.
47
+ # @return [Boolean]
48
+ def supporter
49
+ @obj['supporter']
50
+ end
51
+
52
+ # Returns true/false depending upon if the user is a certified developer or not.
53
+ # @return [Boolean]
54
+ def certifiedDev
55
+ @obj['certifiedDev']
56
+ end
57
+
58
+ # Returns an object containing all user social integrations.
59
+ # @return [Object]
60
+ def social
61
+ @obj['social']
62
+ end
63
+
64
+ # Returns true/false depending on weather the user is an admin or not.
65
+ # @return [Boolean]
66
+ def admin
67
+ @obj['admin']
68
+ end
69
+
70
+ # Returns true/false depending on weather the user is a website Moderator or not.
71
+ # @return [Boolean]
72
+ def webMod
73
+ @obj['webMod']
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,26 @@
1
+ module Spreader
2
+ # This class Spreads the Vote response body into different methods.
3
+ class Votes
4
+ # Initializes the votes class
5
+ # @param obj [Object] JSON parsed object
6
+ def initialize(obj)
7
+ @obj = obj
8
+ end
9
+
10
+ # Get raw hash return of the object
11
+ # @return [Hash]
12
+ attr_reader :obj
13
+
14
+ # Get the first vote amongst all the other votes.
15
+ # @return [Spreader::User]
16
+ def first
17
+ Spreader::User.new(@obj[0])
18
+ end
19
+
20
+ # Get the total number of votes
21
+ # @return [Integer]
22
+ def total
23
+ @obj.length
24
+ end
25
+ end
26
+ end
Binary file
data/topgg.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'topgg'
5
+ spec.version = '1.0.1'
6
+ spec.authors = ['Adonis Tremblay']
7
+ spec.email = ['rhydderchc@gmail.com']
8
+
9
+ spec.summary = 'A top.gg api wrapper for ruby.'
10
+ spec.description = 'This is a ruby library of the top.gg API.'
11
+ spec.homepage = 'https://github.com/rhydderchc/topgg-ruby'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
+
15
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/rhydderchc/topgg-ruby'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/rhydderchc/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ # Uncomment to register a new dependency of your gem
31
+ # spec.add_dependency "example-gem", "~> 1.0"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: topgg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adonis Tremblay
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a ruby library of the top.gg API.
14
+ email:
15
+ - rhydderchc@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".bundle/config"
21
+ - CHANGELOG.md
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/lib.rb
27
+ - lib/topgg/bot.rb
28
+ - lib/topgg/botSearch.rb
29
+ - lib/topgg/stats.rb
30
+ - lib/topgg/user.rb
31
+ - lib/topgg/votes.rb
32
+ - pkg/topgg-1.0.1.gem
33
+ - topgg.gemspec
34
+ homepage: https://github.com/rhydderchc/topgg-ruby
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ homepage_uri: https://github.com/rhydderchc/topgg-ruby
40
+ source_code_uri: https://github.com/rhydderchc/topgg-ruby
41
+ changelog_uri: https://github.com/rhydderchc/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.5.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A top.gg api wrapper for ruby.
61
+ test_files: []