Skip to content

Commit

Permalink
Add release GitHub action and documentation (#39)
Browse files Browse the repository at this point in the history
* Add release action

* Add documentation

* Finishing touches

* Fix package.json
  • Loading branch information
jpbberry committed Dec 18, 2020
1 parent 42f1918 commit 4443a95
Show file tree
Hide file tree
Showing 16 changed files with 1,190 additions and 169 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish to NPM

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm publish --unsafe-perm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist/

docs/build
# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
src/
docs/
logs/
*.log

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ An official module for interacting with the Top.<span>gg API

# Introduction

The base client is Topgg.API, and it takes your top.<span>gg token and provides you with plenty of methods to interact with the API.
The base client is Topgg.Api, and it takes your top.<span>gg token and provides you with plenty of methods to interact with the API.

Your Top.<span>gg token can be found [here](https://top.gg/api/docs#mybots)

You can also setup webhooks via Topgg.Webhook, look down below at the examples for how to do so!

# Links

[API Docs](https://top.gg/api/docs)
[Documentation](https://topggjs.rtfd.io)

[GitHub](https://github.com/top-gg/node-sdk) | [NPM](https://npmjs.com/package/@top-gg/sdk) | [Discord Server](https://discord.gg/EYHTgJX)
[API Reference](https://top.gg/api/docs) | [GitHub](https://github.com/top-gg/node-sdk) | [NPM](https://npmjs.com/package/@top-gg/sdk) | [Discord Server](https://discord.gg/EYHTgJX)

# Auto-Posting

Expand Down
229 changes: 229 additions & 0 deletions docs/Api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<a name="Api"></a>

## Api
Top.gg API Client for Posting stats or Fetching data

**Kind**: global class
**Link**: https://top.gg/api/docs

* [Api](#Api)
* [new Api(token, options)](#new_Api_new)
* [.postStats(stats)](#Api+postStats) ⇒ <code>BotStats</code>
* [.getStats(id)](#Api+getStats) ⇒ <code>BotStats</code>
* [.getBot(id)](#Api+getBot) ⇒ <code>BotInfo</code>
* [.getUser(id)](#Api+getUser) ⇒ <code>UserInfo</code>
* [.getBots(query)](#Api+getBots) ⇒ <code>BotsResponse</code>
* [.getVotes()](#Api+getVotes) ⇒ <code>Array.&lt;ShortUser&gt;</code>
* [.hasVoted(id)](#Api+hasVoted) ⇒ <code>Boolean</code>
* [.isWeekend()](#Api+isWeekend) ⇒ <code>Boolean</code>

<a name="new_Api_new"></a>

### new Api(token, options)
Create Top.gg API instance


| Param | Type | Description |
| --- | --- | --- |
| token | <code>string</code> | Token or options |
| options | <code>object</code> | API Options |

**Example**
```js
const Topgg = require(`@top-gg/sdk`)

const api = new Topgg.Api('Your top.gg token')
```
<a name="Api+postStats"></a>

### api.postStats(stats) ⇒ <code>BotStats</code>
Post bot stats to Top.gg (Do not use if you supplied a client)

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>BotStats</code> - Passed object

| Param | Type | Description |
| --- | --- | --- |
| stats | <code>Object</code> | Stats object |
| stats.serverCount | <code>number</code> | Server count |
| stats.shardCount | <code>number</code> | Shard count |
| stats.shardId | <code>number</code> | Posting shard (useful for process sharding) |

**Example**
```js
await client.postStats({
serverCount: 28199,
shardCount: 1
})
```
<a name="Api+getStats"></a>

### api.getStats(id) ⇒ <code>BotStats</code>
Get a bots stats

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>BotStats</code> - Stats of bot requested

| Param | Type | Description |
| --- | --- | --- |
| id | <code>Snowflake</code> | Bot ID |

**Example**
```js
await client.getStats('461521980492087297')
// =>
{
serverCount: 28199,
shardCount 1,
shards: []
}
```
<a name="Api+getBot"></a>

### api.getBot(id) ⇒ <code>BotInfo</code>
Get bot info

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>BotInfo</code> - Info for bot

| Param | Type | Description |
| --- | --- | --- |
| id | <code>Snowflake</code> | Bot ID |

**Example**
```js
await client.getBot('461521980492087297') // returns bot info
```
<a name="Api+getUser"></a>

### api.getUser(id) ⇒ <code>UserInfo</code>
Get user info

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>UserInfo</code> - Info for user

| Param | Type | Description |
| --- | --- | --- |
| id | <code>Snowflake</code> | User ID |

**Example**
```js
await client.getUser('205680187394752512')
// =>
user.username // Xignotic
```
<a name="Api+getBots"></a>

### api.getBots(query) ⇒ <code>BotsResponse</code>
Get a list of bots

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>BotsResponse</code> - Return response

| Param | Type | Description |
| --- | --- | --- |
| query | <code>BotsQuery</code> | Bot Query |

**Example**
```js
// Finding by properties
await client.getBots({
search: {
username: 'shiro',
certifiedBot: true
...any other bot object properties
}
})
// =>
{
results: [
{
id: '461521980492087297',
username: 'Shiro',
discriminator: '8764',
lib: 'discord.js',
...rest of bot object
}
...other shiro knockoffs B)
],
limit: 10,
offset: 0,
count: 1,
total: 1
}
// Restricting fields
await client.getBots({
fields: ['id', 'username']
})
// =>
{
results: [
{
id: '461521980492087297',
username: 'Shiro'
},
{
id: '493716749342998541',
username: 'Mimu'
},
...
],
...
}
```
<a name="Api+getVotes"></a>

### api.getVotes() ⇒ <code>Array.&lt;ShortUser&gt;</code>
Get users who've voted

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>Array.&lt;ShortUser&gt;</code> - Array of users who've voted
**Example**
```js
await client.getVotes()
// =>
[
{
username: 'Xignotic',
discriminator: '0001',
id: '205680187394752512',
avatar: '3b9335670c7213b3a2d4e990081900c7'
},
{
username: 'iara',
discriminator: '0001',
id: '395526710101278721',
avatar: '3d1477390b8d7c3cec717ac5c778f5f4'
}
...more
]
```
<a name="Api+hasVoted"></a>

### api.hasVoted(id) ⇒ <code>Boolean</code>
Get whether or not a user has voted

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>Boolean</code> - Whether the user has voted

| Param | Type | Description |
| --- | --- | --- |
| id | <code>Snowflake</code> | User ID |

**Example**
```js
await client.hasVoted('205680187394752512')
// => true/false
```
<a name="Api+isWeekend"></a>

### api.isWeekend() ⇒ <code>Boolean</code>
Whether or not the weekend multiplier is active

**Kind**: instance method of [<code>Api</code>](#Api)
**Returns**: <code>Boolean</code> - Whether the the multiplier is active
**Example**
```js
await client.hasVoted()
// => true/false
```
20 changes: 20 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<a name="Change Log"></a>

# Change Log

## 3.0.4
- Released official documentation page
- Added GitHub actions to publish to npm on release

## 3.0.3
- Fixed some webhook bugs
- Improved a few typings

## 3.0.2
Some day-one patches to README, 3.0.1 is a dud release

## 3.0.0
A full rewrite of the package, here's some of the major changes:
- The webhook and API interaction have been full separated, into two different classes, `Api` and `Webhook`
- Auto-Posting is no longer natively supported in the package, instead you can use the officially *supported* [`topgg-autoposter`](https://npmjs.com/topgg-autoposter) package.
- The webhook class is no longer ran off of events, instead acting as a middleware function that defines `req.vote`
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = ./
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
53 changes: 53 additions & 0 deletions docs/Webhook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<a name="Webhook"></a>

## Webhook
Top.gg Webhook

**Kind**: global class

* [Webhook](#Webhook)
* [new Webhook(authorization)](#new_Webhook_new)
* [.middleware()](#Webhook+middleware)

<a name="new_Webhook_new"></a>

### new Webhook(authorization)
Create a new webhook client instance


| Param | Description |
| --- | --- |
| authorization | Webhook authorization to verify requests |

**Example**
```js
const express = require('express')
const { Webhook } = require(`@top-gg/sdk`)

const app = express()
const wh = new Webhook('webhookauth123')

app.post('/dblwebhook', wh.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // => 321714991050784770
})

app.listen(80)

// In this situation, your TopGG Webhook dashboard should look like
// URL = http://your.server.ip:80/dblwebhook
// Authorization: webhookauth123
```
<a name="Webhook+middleware"></a>

### webhook.middleware()
Middleware function to pass to express, sets req.vote to the payload

**Kind**: instance method of [<code>Webhook</code>](#Webhook)
**Example**
```js
app.post('/dblwebhook', wh.middleware(), (req, res) => {
// req.vote is your payload e.g
console.log(req.vote.user) // => 395526710101278721
})
```
16 changes: 16 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project = "Topgg Node SDK"
author = "Top.gg"

extensions = ["recommonmark", "sphinx_markdown_tables"]

source_suffix = [".md", ".rst"]

html_theme = "sphinx_rtd_theme"

master_doc = "master"

html_theme_options = {
"collapse_navigation": True,
"sticky_navigation": True,
"includehidden": True
}
Loading

0 comments on commit 4443a95

Please sign in to comment.