Skip to content

Commit

Permalink
V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Knightplayzz committed Jun 13, 2024
1 parent 5c7b0b9 commit a9cae70
Show file tree
Hide file tree
Showing 39 changed files with 1,084 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
25 changes: 25 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on: ["push", "pull_request"]

name: Test Coveralls

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v1

- name: Use Node.js 20.14.0
uses: actions/setup-node@v3
with:
node-version: 20.14.0

- name: npm install, make test-coverage
run: |
npm install
npm test -- --coverage
- name: Coveralls
uses: coverallsapp/github-action@v2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
coverage/
package-lock.json
todo.txt
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sudo: false

language: node_js

node_js:
- 20.14.0

before_install:
- npm i -g [email protected]

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## V1.0.0

Inital creation
16 changes: 16 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Creative Commons Attribution-NonCommercial License

This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

You are free to:
- Share: Copy and redistribute the material in any medium or format
- Adapt: Remix, transform, and build upon the material

Under the following terms:
- Attribution: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- NonCommercial: You may not use the material for commercial purposes.
- No additional restrictions: You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Notices:
- You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
- No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div align="center">
<img src="https://static.wikia.nocookie.net/supercell-fankit/images/f/ff/Brawl_Stars_Smile_Logo.png/revision/latest/scale-to-width-down/250?cb=20201119180831" height="200px" alt="Brawl Stars"/>
<br>
<p>A light-weight module that makes <a href="https://developer.brawlstars.com/">Brawl Stars API</a> become easy.</p>
<a href=""><img src="https://app.travis-ci.com/Knightplayzz/brawl-stars.svg?branch=main"></a>
<a href='https://coveralls.io/github/Knightplayzz/brawl-stars?branch=main'><img src='https://coveralls.io/repos/github/Knightplayzz/brawl-stars-node/badge.svg?branch=main' alt='Coverage Status' /></a>
<a href="https://www.npmjs.com/package/brawl-stars-node"><img src="https://img.shields.io/npm/dt/brawl-stars-node.svg?maxAge=3600"></a>

<a href="https://www.npmjs.com/package/brawl-stars-node"><img src="https://img.shields.io/npm/v/brawl-stars-node" alt="Install size"></a>
<a href="https://packagephobia.now.sh/result?p=brawl-stars-node"><img src="https://badgen.net/packagephobia/install/brawl-stars-node" alt="Current version"></a>
</div>

# Introduction

Provides an easy way to get started with the [Brawl Stars API](https://developer.brawlstars.com/)
For more information about the responses please check [Official Brawl Stars Dev Website](https://developer.brawlstars.com/#/documentation).
Not releated to Supercell.
Created By: Philippe Smeets

## Installation

`npm install brawl-stars-node`

## Links

- [Documentation](https://github.com/Knightplayzz/brawl-stars/blob/main/documentation.md)
- [Brawl Stars Developer Website](https://developer.brawlstars.com/#/documentation)

## Example

```javascript
const client = require('brawl-stars-node');
async function myFunction() {
await client.login('YOUR-TOKEN-HERE');
const player = await client.getPlayer('PLAYER-TAG-HERE');
console.log(`${player.name} (${player.tag})`);
}
myFunction();
```

### Disclaimer

> This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see Supercell's Fan Content Policy: <www.supercell.com/en/fan-content-policy/>
26 changes: 26 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Security Policy

## Supported Versions

All versions are suppored. But we highly recommend useing the latest version.
Old versions still work but don't have new functinalities and safety updates.

| Version | Supported |
| ------- | ------------------ |
| 1.0.0 - 1.0.0 | :white_check_mark: |

## Reporting a Vulnerability

If you find out that there is a vulnerability please report ASAP.

To report please visit [clash-of-clans-issue](https://github.com/Knightplayzz/brawl-stars/issues) and report.
If there is a report about a potiential safety issue, we will immediately evaluate the situation and see if there is an issue.
If there is an safety issue it will be our priority to resolve that issue.

## For more information please contact us

| Type | Information |
|------|-------------|
| Mail |<[email protected]> |
| Github | Knightplayzz |
| Discord | philippesmeets (philippe#0354) |
Binary file added documentation.md
Binary file not shown.
10 changes: 10 additions & 0 deletions functions/auth/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let authToken;

function setAuthToken(auth) {
authToken = auth;
}
function getAuthToken() {
return authToken;
}

module.exports = { setAuthToken, getAuthToken };
16 changes: 16 additions & 0 deletions functions/auth/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fetch = require('node-fetch');
const context = require('./context');

/**
* Logs the player in using the auth token.
* @param {string} auth The authentication token used to make API requests.
*/
async function login(auth) {
if (typeof auth !== 'string') { throw new Error('Authentication token must be a string.'); }
const response = await fetch('https://api.brawlstars.com/v1/brawlers', { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
if (!response.ok) throw new Error('Authentication token is wrong.');
context.setAuthToken(auth);
console.log('You succesfully logged in.');
}

module.exports = { login };
14 changes: 14 additions & 0 deletions functions/brawlers/brawlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves all brawlers information.
* @param {string} clubTag - The tag of the club.
* @returns {Promise<JSON>} JSON
*/

async function brawlers() {
const response = await fetch('https://api.brawlstars.com/v1/brawlers', { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { brawlers };
16 changes: 16 additions & 0 deletions functions/brawlers/getBrawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves brawler information by brawlerId.
* @param {string|number} brawlerId - The id of the brawler.
*
* @returns {Promise<JSON>} JSON
*/

async function getBrawler(brawlerId) {
if (typeof brawlerId !== 'string' && typeof brawlerId !== 'number') return { 'reason': 'notFound', 'message': 'brawlerId must be a string or number' };
const response = await fetch(`https://api.brawlstars.com/v1/brawlers/${encodeURIComponent(brawlerId)}`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getBrawler };
16 changes: 16 additions & 0 deletions functions/clubs/getClub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves club information by clubTag.
* @param {string} clubTag - The tag of the club.
* @returns {Promise<JSON>} JSON
*/

async function getClub(clubTag) {
if (typeof clubTag !== 'string') return { 'reason': 'notFound', 'message': 'playerTag must be a string' };
if (!clubTag.startsWith('#')) return { 'reason': 'NotFound', 'message': 'playerTag must start with #' };
const response = await fetch(`https://api.brawlstars.com/v1/clubs/${encodeURIComponent(clubTag)}`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getClub };
16 changes: 16 additions & 0 deletions functions/clubs/getClubMembers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves clubMembers by clubTag.
* @param {string} clubTag - The tag of the club.
* @returns {Promise<JSON>} JSON
*/

async function getClubMembers(clubTag) {
if (typeof clubTag !== 'string') return { 'reason': 'notFound', 'message': 'playerTag must be a string' };
if (!clubTag.startsWith('#')) return { 'reason': 'NotFound', 'message': 'playerTag must start with #' };
const response = await fetch(`https://api.brawlstars.com/v1/clubs/${encodeURIComponent(clubTag)}/members`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getClubMembers };
14 changes: 14 additions & 0 deletions functions/events/getEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves event information.
*
* @returns {Promise<JSON>} JSON
*/

async function getEvents() {
const response = await fetch('https://api.brawlstars.com/v1/events/rotation', { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getEvents };
17 changes: 17 additions & 0 deletions functions/players/getBattlelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves user battlelog information by playerTag.
* @param {string} playerTag - The tag of the user.
*
* @returns {Promise<JSON>} JSON
*/

async function getBattlelog(playerTag) {
if (typeof playerTag !== 'string') return { 'reason': 'notFound', 'message': 'playerTag must be a string' };
if (!playerTag.startsWith('#')) return { 'reason': 'NotFound', 'message': 'playerTag must start with #' };
const response = await fetch(`https://api.brawlstars.com/v1/players/${encodeURIComponent(playerTag)}/battlelog`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getBattlelog };
15 changes: 15 additions & 0 deletions functions/players/getPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves user information by playerTag.
* @param {string} playerTag - The tag of the user.
* @returns {Promise<JSON>} JSON
*/

async function getPlayer(playerTag) {
if (typeof playerTag !== 'string') return { 'reason': 'notFound', 'message': 'playerTag must be a string' };
if (!playerTag.startsWith('#')) return { 'reason': 'NotFound', 'message': 'playerTag must start with #' };
const response = await fetch(`https://api.brawlstars.com/v1/players/${encodeURIComponent(playerTag)}`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}
module.exports = { getPlayer };
18 changes: 18 additions & 0 deletions functions/rankings/getRankingsBrawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves clubs rankings information.
* @param {string} countryCode - Two letter country code, or 'global' for global rankings.
*
* @param {string|number} brawlerId - The id of the brawler.
* @returns {Promise<JSON>} JSON
*/

async function getRankingsBrawlers(countryCode, brawlerId) {
if (typeof countryCode !== 'string') return { 'reason': 'notFound', 'message': 'countryCode must be a string' };
if (typeof brawlerId !== 'string' && typeof brawlerId !== 'number') return { 'reason': 'notFound', 'message': 'brawlerId must be a string or a number' };
const response = await fetch(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/brawlers/${encodeURIComponent(brawlerId)}`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getRankingsBrawlers };
15 changes: 15 additions & 0 deletions functions/rankings/getRankingsClubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves clubs rankings information.
* @param {string} countryCode - Two letter country code, or 'global' for global rankings.
* @returns {Promise<JSON>} JSON
*/

async function getRankingsClubs(countryCode) {
if (typeof countryCode !== 'string') return { 'reason': 'notFound', 'message': 'countryCode must be a string' };
const response = await fetch(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/clubs`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getRankingsClubs };
15 changes: 15 additions & 0 deletions functions/rankings/getRankingsPlayers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves player rankings information.
* @param {string} countryCode - Two letter country code, or 'global' for global rankings.
* @returns {Promise<JSON>} JSON
*/

async function getRankingsPlayers(countryCode) {
if (typeof countryCode !== 'string') return { 'reason': 'notFound', 'message': 'countryCode must be a string' };
const response = await fetch(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/players`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getRankingsPlayers };
19 changes: 19 additions & 0 deletions functions/rankings/getRankingsPowerplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fetch = require('node-fetch');
const context = require('../auth/context');
/**
* Retrieves player rankings information.
* @param {string} countryCode - Two letter country code, or 'global' for global rankings.
*
* @param {string|number} seasonId - The id of a season.
*
* @returns {Promise<JSON>} JSON
*/

async function getRankingsPowerplay(countryCode, seasonId) {
if (typeof countryCode !== 'string') return { 'reason': 'notFound', 'message': 'countryCode must be a string' };
if (typeof seasonId !== 'string' && typeof seasonId !== 'number') return { 'reason': 'notFound', 'message': 'seasonId must be a string or a number' };
const response = await fetch(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/players`, { headers: { 'Authorization': `Bearer ${context.getAuthToken()}` } });
return await response.json();
}

module.exports = { getRankingsPowerplay };
Loading

0 comments on commit a9cae70

Please sign in to comment.