Skip to content

feat: adapt to v1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 (2.0.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.
166 changes: 134 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,159 @@
# [Top.gg](https://top.gg) Ruby
# Top.gg Ruby SDK

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.
The community-maintained Ruby library for Top.gg.

It provides you with numerous methods to interact with the API.
## Dependencies
## Installation

* Ruby
```sh
$ gem install topgg
```

## Installation
## Setting up

``` bash
```rb
require "topgg"

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

## Usage

### Getting a bot

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

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

## Example
```rb
bots = client.get_bots({ sort: "date", limit: 50, offset: 0 })

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

```ruby
require 'topgg'
### Getting your bot's voters

client = Topgg.new("AUTH_TOKEN", "BOTID")
#### First page

client.get_bot("1234").defAvatar
# returns
# "6debd47ed13483642cf09e832ed0bc1b"
```rb
voters = client.get_voters

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

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

```rb
voters = client.get_voters(2)

```ruby
require 'topgg'
require 'discordrb'
for voter in voters.results do
puts voter.username
end
```

bot = Discordrb::Bot.new token: "TOKEN"
### Check if a user has voted for your bot

client = Topgg.new("AUTH_TOKEN", "BOTID")
bot.ready do |event|
client.auto_post_stats(bot) # The discordrb bot client.
```rb
has_voted = client.voted?("661200758510977084")
```

### Getting your bot's server count

```rb
server_count = client.get_server_count
```

### Posting your bot's server count

```rb
client.post_server_count(bot.server_count)
```

### Automatically posting your bot's server count every few minutes

For 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

Check out the api reference [here](https://rubydoc.info/gems/topgg/)
```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")
```

#### 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 bot

##### 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
```
120 changes: 0 additions & 120 deletions lib/lib.rb

This file was deleted.

Loading