Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8cd5df5
feat: adapt to v0
null8626 Jun 16, 2025
39e4385
meta: update copyright year
null8626 Jun 16, 2025
3d17381
meta: bump version from 1.1.0 to 2.0.0
null8626 Jun 16, 2025
ffb34f8
feat: add widgets
null8626 Jun 17, 2025
e4acb29
feat: add small widgets
null8626 Jun 18, 2025
e18a03a
docs: readme overhaul
null8626 Jun 23, 2025
3d00aab
feat: add webhooks
null8626 Jun 26, 2025
beb754e
feat: rename stats methods
null8626 Jul 4, 2025
eb3cdf3
feat: rename methods
null8626 Jul 4, 2025
7851039
doc: add chapters
null8626 Jul 19, 2025
b2b4d50
feat: proceed with the breaking changes (temporary)
null8626 Oct 9, 2025
7185abb
revert: revert breaking changes (part 1)
null8626 Oct 9, 2025
9755255
[doc,fix]: better documentation, fix bearer prefix inconsistency
null8626 Oct 9, 2025
7743947
meta: change the latest version from 2.0.0 to 1.2.0
null8626 Oct 9, 2025
881566c
revert: revert renaming of lib.rb to topgg.rb
null8626 Oct 9, 2025
9ede331
[doc,revert]: improve documentation, revert breaking changes
null8626 Oct 10, 2025
98661bd
revert: revert README.md for now (for diff readability)
null8626 Oct 10, 2025
da1dbbf
revert: revert removal of discriminator
null8626 Oct 10, 2025
d3b1dba
revert: shift defAvatar declaration order for diff readability
null8626 Oct 10, 2025
1968389
revert: revert the removal of shard_count, guilds, and shards
null8626 Oct 10, 2025
a7cd27c
revert: revert the removal of lib
null8626 Oct 10, 2025
2b1abb5
revert: revert the removal of certifiedBot
null8626 Oct 10, 2025
3b4eb2d
revert: revert the removal of bannerUrl and donatebotguildid
null8626 Oct 10, 2025
7672917
fix: move declarations to help for diff readability and fix syntax error
null8626 Oct 10, 2025
8a2035b
fix: fix potential bug
null8626 Oct 10, 2025
a3a80a2
[feat,doc]: add error handling and documentation tweaks
null8626 Oct 10, 2025
2b8c805
doc: fix API version links in README.md
null8626 Oct 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.bundle
.bundle
*.gem
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in topgg.gemspec
gemspec

gem 'rake', '~> 13.0'
gem "rack"
gem "rake"
gem "ostruct"
gem "cgi"
14 changes: 11 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
PATH
remote: .
specs:
topgg (1.1.0)
topgg (1.2.0)
rack (~> 3.0.9.1)

GEM
remote: https://rubygems.org/
specs:
cgi (0.5.0)
ostruct (0.6.1)
rack (3.0.9.1)
rake (13.0.6)

PLATFORMS
x64-mingw-ucrt
x86_64-linux

DEPENDENCIES
rake (~> 13.0)
cgi (~> 0.5.0)
ostruct
rack
rake
topgg!

BUNDLED WITH
2.2.22
2.6.9
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 rhydderchc
Copyright (c) 2021-2025 rhydderchc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) 2021 TODO: Write your name
Copyright (c) 2021-2025 rhydderchc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
227 changes: 195 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,220 @@
# [Top.gg](https://top.gg) Ruby
# Top.gg Ruby SDK

The community-maintained Ruby library for Top.gg.

## Chapters

- [Installation](#installation)
- [Setting up](#setting-up)
- [Usage](#usage)
- [API v1](#api-v1-1)
- [Getting your project's vote information of a user](#getting-your-projects-vote-information-of-a-user)
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
- [API v0](#api-v0-1)
- [Getting a bot](#getting-a-bot)
- [Getting several bots](#getting-several-bots)
- [Getting your project's voters](#getting-your-projects-voters)
- [Check if a user has voted for your project](#check-if-a-user-has-voted-for-your-project)
- [Getting your bot's statistics](#getting-your-bots-statistics)
- [Posting your bot's statistics](#posting-your-bots-statistics)
- [Automatically posting your bot's statistics every few minutes](#automatically-posting-your-bots-statistics-every-few-minutes)
- [Checking if the weekend vote multiplier is active](#checking-if-the-weekend-vote-multiplier-is-active)
- [Generating widget URLs](#generating-widget-urls)
- [Webhooks](#webhooks)
- [Being notified whenever someone voted for your project](#being-notified-whenever-someone-voted-for-your-project)

The Top.gg Ruby SDK is a lighweight package, that allows you
to fetch data from the top.gg api and post data such as statistics to the website.
## Installation

It provides you with numerous methods to interact with the API.
## Dependencies
```sh
$ gem install topgg
```

* Ruby
## Setting up

## Installation
### API v1

> **NOTE**: API v1 also includes API v0.

```rb
require "topgg"

client = V1Topgg.new(ENV["TOPGG_TOKEN"])
```

### API v0

```rb
require "topgg"

client = Topgg.new(ENV["TOPGG_TOKEN"])
```

## Usage

### API v1

#### Getting your project's vote information of a user

```rb
vote = client.vote("661200758510977084")
```

#### Posting your bot's application commands list

##### Discordrb

```rb
commands = bot.rest.api.get_global_application_commands(bot.application_id).to_json

client.post_commands(commands)
```

##### Raw

```rb
commands = "[{\"options\":[],\"name\":\"test\",\"name_localizations\":null,\"description\":\"command description\",\"description_localizations\":null,\"contexts\":[],\"default_permission\":null,\"default_member_permissions\":null,\"dm_permission\":false,\"integration_types\":[],\"nsfw\":false}]"

client.post_commands(commands)
```

### API v0

#### Getting a bot

```rb
bot = client.get_bot("264811613708746752")
```

#### Getting several bots

```rb
bots = client.search_bot({ sort: "id", limit: 50, offset: 0 })

for bot in bots.results do
puts bot.username
end
```

#### Getting your project's voters

``` bash
##### First page

gem install topgg
```rb
voters = client.votes

for voter in voters.results do
puts voter.username
end
```
## Note

You require a Token to interact with the Api.
The token can be found at `https://top.gg/bot/[YOUR_BOT_ID]/webhooks`
##### Subsequent pages

## Example
```rb
voters = client.votes(2)

Here's a straightforward example of how to request data with the wrapper.
for voter in voters.results do
puts voter.username
end
```

```ruby
require 'topgg'
#### Check if a user has voted for your project

client = Topgg.new("AUTH_TOKEN", "BOTID")
```rb
has_voted = client.voted?("8226924471638491136")
```

client.get_bot("1234").defAvatar
# returns
# "6debd47ed13483642cf09e832ed0bc1b"
#### Getting your bot's statistics

```rb
stats = client.get_stats
```
### Auto Posting

The library provides you with autoposting functionality, and autoposts at an interval of 30 minutes.
Here's how you can use it
#### Posting your bot's statistics

```ruby
require 'topgg'
require 'discordrb'
```rb
client.post_stats(bot.server_count)
```

bot = Discordrb::Bot.new token: "TOKEN"
#### Automatically posting your bot's statistics every few minutes

client = Topgg.new("AUTH_TOKEN", "BOTID")
bot.ready do |event|
client.auto_post_stats(bot) # The discordrb bot client.
With Discordrb:

```rb
require "discordrb"

bot = Discordrb::Bot.new(token: env["BOT_TOKEN"], intents: [:servers])

bot.ready do |event|
client.auto_post_stats(bot)

puts("Bot is now ready!")
end

bot.run
```

# Documentation
#### Checking if the weekend vote multiplier is active

```rb
is_weekend = client.is_weekend?
```

#### Generating widget URLs

##### Large

```rb
widget_url = Dbl::Widget.large(:discord_bot, "574652751745777665")
```

##### Votes

```rb
widget_url = Dbl::Widget.votes(:discord_bot, "574652751745777665")
```

Check out the api reference [here](https://rubydoc.info/gems/topgg/)
##### Owner

```rb
widget_url = Dbl::Widget.owner(:discord_bot, "574652751745777665")
```

##### Social

```rb
widget_url = Dbl::Widget.social(:discord_bot, "574652751745777665")
```

### Webhooks

#### Being notified whenever someone voted for your project

##### Ruby on Rails

In your `config/application.rb`:

```rb
module MyServer
class Application < Rails::Application
# ...

config.middleware.use Dbl::Webhook,
type: Dbl::Webhook::VOTE,
path: "/votes",
auth: ENV["MY_TOPGG_WEBHOOK_SECRET"] do |vote|
Rails.logger.info "A user with the ID of #{vote.voter_id} has voted us on Top.gg!"
end
end
end
```

##### Sinatra

```rb
use Dbl::Webhook,
type: Dbl::Webhook::VOTE,
path: "/votes",
auth: ENV["MY_TOPGG_WEBHOOK_SECRET"] do |vote|
puts "A user with the ID of #{vote.voter_id} has voted us on Top.gg!"
end
```
Loading