commit
72716ce70f
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parser": "babel-eslint",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12
|
||||
},
|
||||
"rules": {
|
||||
"strict": 0
|
||||
}
|
||||
}
|
|
@ -0,0 +1,248 @@
|
|||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/node,python
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,python
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
pytestdebug.log
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
doc/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/node,python
|
||||
test.js
|
38
README.md
38
README.md
|
@ -1,2 +1,36 @@
|
|||
# SpookVooper API Libraries
|
||||
Pick a branch that corrosponds with your language.
|
||||
# SpookVooper API Libraries
|
||||
|
||||
Library that is used to easily access the SpookVooper API.
|
||||
|
||||
## Usage
|
||||
|
||||
We use ES6 modules, because CommonJS makes me want to cry.
|
||||
If anything returns a JSON object, you need to use it as an array.
|
||||
|
||||
**Example Script:**
|
||||
|
||||
```js
|
||||
import svAPI from "spookvooperapi";
|
||||
let a;
|
||||
|
||||
// Get the balance of SpikeViper, and save it to a variable, then console.log it with a prefix
|
||||
svAPI.eco.getBalance("2a0057e6-356a-4a49-b825-c37796cb7bd9", true).then(value => {
|
||||
a = value;
|
||||
console.log(`Spike's Balance: ${a}`);
|
||||
});
|
||||
```
|
||||
|
||||
The value variable is what the function returns as a result.
|
||||
It gets passed to the callback function where you can use it.
|
||||
|
||||
The [wiki](https://github.com/vexico/spookvooper-api/wiki) is getting worked on constantly, but it will take a while so in the meantime, you can use the inline wiki. To use this feature we recommend people use [Visual Studio Code](https://code.visualstudio.com/).
|
||||
|
||||
## Supported Routes
|
||||
|
||||
We support all the routes. We even made some in premade.
|
||||
|
||||
* Auth
|
||||
* User
|
||||
* Group
|
||||
* Eco
|
||||
* Premade
|
||||
|
|
|
@ -0,0 +1,426 @@
|
|||
// SpookVooper API - main.js
|
||||
// Written by Brendan Lane - https://brndnln.dev/
|
||||
|
||||
const userURL = "https://api.spookvooper.com/user";
|
||||
const groupURL = "https://api.spookvooper.com/group";
|
||||
const ecoURL = "https://api.spookvooper.com/eco";
|
||||
const authURL = "https://spookvooper.com/oauth2";
|
||||
|
||||
const axios = require('axios');
|
||||
let urlReturn;
|
||||
|
||||
class User {
|
||||
#apikey = undefined;
|
||||
|
||||
constructor(svid) {
|
||||
this.svid = svid
|
||||
}
|
||||
|
||||
getUser() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${userURL}/getUser?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getUsername() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${userURL}/getUsername?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getBalance() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getBalance?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
hasDiscordRole(role) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${userURL}/hasDiscordRole?userid=${this.svid}&role=${role}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getDiscordRoles() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${userURL}/getDiscordRoles?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getDaysSinceLastMove() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${userURL}/getDaysSinceLastMove?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
setApiKey(key) {
|
||||
this.#apikey = key;
|
||||
}
|
||||
|
||||
sendCredits(amount, to, reason) {
|
||||
if (typeof to === "string") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else if (typeof to === "object") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to.svid}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
throw "The 'to' parameter must be a string or an object!";
|
||||
}
|
||||
}
|
||||
|
||||
getUserStockOffers(ticker) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getUserStockOffers?ticker=${ticker}&svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
buyStock(ticker, amount, price) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/submitStockBuy?ticker=${ticker}&count=${amount}&price=${price}&accountid=${this.svid}&auth=${this.#apikey}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
sellStock(ticker, amount, price) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/submitStockSell?ticker=${ticker}&count=${amount}&price=${price}&accountid=${this.svid}&auth=${this.#apikey}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
cancelStockOrder(orderid) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/cancelOrder?orderid=${orderid}&accountid=${this.svid}&auth=${this.#apikey}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Stock {
|
||||
constructor(ticker) {
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getStockValue?ticker=${this.ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getStockBuyPrice() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getStockBuyPrice?ticker=${this.ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getQueueInfo(type) {
|
||||
switch (type) {
|
||||
case "BUY":
|
||||
break;
|
||||
|
||||
case "SELL":
|
||||
break;
|
||||
|
||||
default:
|
||||
throw "Parameter 'type' must be 'BUY' or 'SELL'"
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getQueueInfo?ticker=${this.ticker}&type=${type}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getOwner() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getOwnerData?ticker=${this.ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class District {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
getWealth(type) {
|
||||
switch (type) {
|
||||
case "ALL":
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getDistrictWealth?id=${this.name}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
case "USER":
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getDistrictUserWealth?id=${this.name}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
case "GROUP":
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/getDistrictGroupWealth?id=${this.name}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
default:
|
||||
throw "Parameter 'type' must be 'ALL', 'USER', or 'GROUP'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Group {
|
||||
#apikey = undefined;
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
getGroup() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/getGroup?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
setApiKey(key) {
|
||||
this.#apikey = key;
|
||||
}
|
||||
|
||||
sendCredits(amount, to, reason) {
|
||||
if (typeof to === "string") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else if (typeof to === "object") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to.svid}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
throw "The 'to' parameter must be a string or an object!";
|
||||
}
|
||||
}
|
||||
|
||||
doesGroupExist() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/doesGroupExist?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getGroupMembers() {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/getGroupMembers?svid=${this.svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
hasGroupPermission(user, permission) {
|
||||
if (typeof to === "string") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/hasGroupPermission?svid=${this.svid}&usersvid=${user}&permission=${permission}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else if (typeof to === "object") {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/hasGroupPermission?svid=${this.svid}&usersvid=${user.svid}&permission=${permission}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Auth {
|
||||
#clientsecret = undefined;
|
||||
#authcode = undefined;
|
||||
|
||||
constructor(clientid, clientsecret) {
|
||||
this.clientid = clientid;
|
||||
this.#clientsecret = clientsecret;
|
||||
}
|
||||
|
||||
genLink(redirect, scope, state) {
|
||||
if (redirect === undefined || scope === undefined) {
|
||||
throw "Both parameters 'redirect' and 'scope' must be defined!"
|
||||
} else if (state === undefined) {
|
||||
state = "";
|
||||
urlReturn = `${authURL}/authorize?response_type=code&client_id=${this.clientid}&redirect_uri=${redirect}&scope=${scope}&state=${state}`;
|
||||
urlReturn = urlReturn.split(" ").join("%20");
|
||||
return urlReturn;
|
||||
} else {
|
||||
urlReturn = `${authURL}/authorize?response_type=code&client_id=${this.clientid}&redirect_uri=${redirect}&scope=${scope}&state=${state}`;
|
||||
urlReturn = urlReturn.split(" ").join("%20");
|
||||
return urlReturn;
|
||||
}
|
||||
}
|
||||
|
||||
setAuthCode(authcode) {
|
||||
this.#authcode = authcode;
|
||||
}
|
||||
|
||||
requestToken(redirect) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${authURL}/requestToken?grant_type=authorization_code&code=${this.#authcode}&redirect_uri=${redirect}&client_id=${this.clientid}&client_secret=${this.#clientsecret}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
User,
|
||||
Stock,
|
||||
District,
|
||||
Group,
|
||||
Auth
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
// SpookVooper API - modules/auth.js
|
||||
// Written by Brendan Lane
|
||||
|
||||
/** @module modules/auth */
|
||||
import axios from 'axios'
|
||||
|
||||
const baseURL = 'https://spookvooper.com/oauth2'
|
||||
let urlReturn
|
||||
|
||||
/**
|
||||
* Generates a Oauth2 URL for you. This just builds a string and DOES NOT need a promise. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper. Get more information at the wiki. https://github.com/bowlingballindustries/spookvooper-api/wiki/Auth#authorize
|
||||
* @function authorize
|
||||
* @param {string} response_type The type of response you get back. Currently the only one that is supported is "code". This parameter is requried.
|
||||
* @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This parameter is requried.
|
||||
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" parameter if successful. This parameter is requried.
|
||||
* @param {string} scope The scope of what you want to be able to receive. All scopes are allowed. This parameter is requried.
|
||||
* @param {string} state The state parameter can have anything here. Will be returned to the server upon completion. This parameter is optional.
|
||||
* @returns {string} Will return a string containing a link to the Oauth2 authorization page. If there is an error, it will return "ERROR: Oauth2 URL Builder - A required variable is undefined or is missing."
|
||||
*/
|
||||
function authorize (response_type, client_id, redirect_uri, scope, state) {
|
||||
if (response_type === undefined || client_id === undefined || redirect_uri === undefined || scope === undefined) {
|
||||
return 'ERROR: Oauth2 URL Builder - A required variable is undefined or is missing.'
|
||||
} else if (state === undefined) {
|
||||
state = ''
|
||||
urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`
|
||||
urlReturn = urlReturn.split(' ').join('%20')
|
||||
return urlReturn
|
||||
} else {
|
||||
urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`
|
||||
urlReturn = urlReturn.split(' ').join('%20')
|
||||
return urlReturn
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a token that you can use for Oauth2. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper
|
||||
* @function requestToken
|
||||
* @param {string} grant_type The type of response you get back. Currently the one that is supported is "authorization_code"
|
||||
* @param {string} code The code that was returned from the authorization.
|
||||
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" parameter if successful.
|
||||
* @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2.
|
||||
* @param {string} client_secret The client secret of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This WILL NOT get shared with anything other than the function it is in, and will not get sent anywhere other than https://spookvooper.com/. We take privacy very seriously. You must keep this safe.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON Object containing the token, expire time in seconds, and the svid of the authorized user).
|
||||
*/
|
||||
function requestToken (grant_type, code, redirect_uri, client_id, client_secret, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/requestToken?grant_type=${grant_type}&code=${code}&redirect_uri=${redirect_uri}&client_id=${client_id}&client_secret=${client_secret}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
authorize,
|
||||
requestToken
|
||||
}
|
|
@ -0,0 +1,378 @@
|
|||
// SpookVooper API - modules/eco.js
|
||||
// Written by Brendan Lane
|
||||
|
||||
/** @module modules/eco */
|
||||
import axios from 'axios'
|
||||
|
||||
const baseURL = 'https://api.spookvooper.com/eco'
|
||||
|
||||
/**
|
||||
* Gets the balance of a user, given their svid.
|
||||
* @function getBalance
|
||||
* @param {string} svid The svid of the user in question.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getBalance (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getBalance?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a payment to and from accounts
|
||||
* @function sendTransactionByIDs
|
||||
* @param {string} to The svid of the user/group you want to send the payment to
|
||||
* @param {string} from The svid of the user/group you want to send the payment from
|
||||
* @param {string} amount The amount of money to be sent
|
||||
* @param {string} auth An api key which has permission to use funds from the sender or use oauthkey|app_secret formula for Oauth2.
|
||||
* @param {string} detail A short detail of why the payment happened. Must include "sale" if it was a sale.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function sendTransactionByIDs (to, from, amount, auth, detail, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/sendTransactionByIDs?to=${to}&from=${from}&amount=${amount}&auth=${auth}&detail=${detail}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a stock ticker.
|
||||
* @function getStockValue
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getStockValue (ticker, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getStockValue?ticker=${ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the history of a stock ticker.
|
||||
* @function getStockHistory
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {string} type Can be "MINUTE", "HOUR", or "DAY"
|
||||
* @param {string} count How far back to go. Don't use a count over 60!
|
||||
* @param {string} interval Set the time interval beteen data points
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an array).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getStockHistory (ticker, type, count, interval, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getStockHistory?ticker=${ticker}&type=${type}&count=${count}&interval=${interval}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchases Stocks
|
||||
* @function submitStockBuy
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {string} count How many stocks you want to purchase
|
||||
* @param {string} price How much you want to pay for each stock
|
||||
* @param {string} accountid The SVID of the account (user or group) you'd like to purchase from.
|
||||
* @param {string} auth API Key that has authentication to use the account specified in accountid or use oauthkey|app_secret formula for Oauth2.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a tesult).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function submitStockBuy (ticker, count, price, accountid, auth, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/submitStockBuy?ticker=${ticker}&count=${count}&price=${price}&accountid=${accountid}&auth=${auth}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sells Stocks
|
||||
* @function submitStockSell
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {string} count How many stocks you want to sell
|
||||
* @param {string} price How much you want to sell each stock for
|
||||
* @param {string} accountid The SVID of the account (user or group) you'd like to sell from.
|
||||
* @param {string} auth API Key that has authentication to use the account specified in accountid or use oauthkey|app_secret formula for Oauth2.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a result).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function submitStockSell (ticker, count, price, accountid, auth, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/submitStockSell?ticker=${ticker}&count=${count}&price=${price}&accountid=${accountid}&auth=${auth}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels an ongoing order.
|
||||
* @function cancelOrder
|
||||
* @param {string} orderid The ID of the order you'd like to cancel.
|
||||
* @param {string} accountid The SVID of the account (user or group) you'd like to purchase from.
|
||||
* @param {string} auth API Key that has authentication to use the account specified in accountid or use oauthkey|app_secret formula for Oauth2.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a result).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function cancelOrder (orderid, accountid, auth, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/submitStockBuy?orderid=${orderid}&accountid=${accountid}&auth=${auth}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current buy price of the ticker
|
||||
* @function getStockBuyPrice
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getStockBuyPrice (ticker, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getStockBuyPrice?ticker=${ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current buy price of the ticker
|
||||
* @function getStockBuyPrice
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {string} type The type of queue. Can either be "BUY" or "SELL"
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getQueueInfo (ticker, type, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getQueueInfo?ticker=${ticker}&type=${type}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets stock offer data for a user.
|
||||
* @function getUserStockOffers
|
||||
* @param {string} ticker The ticker id
|
||||
* @param {string} svid The SVID of the user you want to look up
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an array).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getUserStockOffers (ticker, svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getUserStockOffers?ticker=${ticker}&svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total wealth of a district
|
||||
* @function getDistrictWealth
|
||||
* @param {string} id The name of the district
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getDistrictWealth (id, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getDistrictWealth?id=${id}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total wealth of users in a district
|
||||
* @function getDistrictUserWealth
|
||||
* @param {string} id The name of the district
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getDistrictUserWealth (id, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getDistrictUserWealth?id=${id}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total wealth of groups in a district
|
||||
* @function getDistrictGroupWealth
|
||||
* @param {string} id The name of the district
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getDistrictGroupWealth (id, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getDistrictGroupWealth?id=${id}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getOwnerData
|
||||
* @param {string} ticker The stock ticker you want to query
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON Object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getOwnerData (ticker, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getOwnerData?ticker=${ticker}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
getBalance,
|
||||
sendTransactionByIDs,
|
||||
getStockValue,
|
||||
getStockHistory,
|
||||
submitStockBuy,
|
||||
submitStockSell,
|
||||
cancelOrder,
|
||||
getStockBuyPrice,
|
||||
getQueueInfo,
|
||||
getUserStockOffers,
|
||||
getDistrictWealth,
|
||||
getDistrictUserWealth,
|
||||
getDistrictGroupWealth,
|
||||
getOwnerData
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
// SpookVooper API - modules/group.js
|
||||
// Written by Brendan Lane
|
||||
|
||||
/** @module modules/group */
|
||||
import axios from 'axios'
|
||||
|
||||
const baseURL = 'https://api.spookvooper.com/group'
|
||||
|
||||
/**
|
||||
* Checks if a group exists.
|
||||
* @function doesGroupExist
|
||||
* @param {string} svid The svid of the group in question.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a boolean).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function doesGroupExist (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/doesGroupExist?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all members of a group.
|
||||
* @function getGroupMembers
|
||||
* @param {string} svid The svid of the group in question.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getGroupMembers (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getGroupMembers?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all members of a group.
|
||||
* @function hasGroupPermission
|
||||
* @param {string} svid The svid of the group in question.
|
||||
* @param {string} usersvid The svid of the user you want to check
|
||||
* @param {string} permission The permission you want to search for
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function hasGroupPermission (svid, usersvid, permission, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/hasGroupPermission?svid=${svid}&usersvid=${usersvid}&permission=${permission}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SVID from a name
|
||||
* @function getSvidFromName
|
||||
* @param {string} name The name of the group
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getSvidFromName (name, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getSvidFromName?name=${name}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the group
|
||||
* @function getGroupMembers
|
||||
* @param {string} svid The svid of the group in question.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getName (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getName?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
doesGroupExist,
|
||||
getGroupMembers,
|
||||
hasGroupPermission,
|
||||
getSvidFromName,
|
||||
getName
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// SpookVooper API - modules/premade.js
|
||||
// Written by Brendan Lane
|
||||
|
||||
/** @module modules/premade */
|
||||
import user from './user.js'
|
||||
import eco from './eco.js'
|
||||
|
||||
let StockOwnerAmount
|
||||
|
||||
/**
|
||||
* Gets the total XP of a user
|
||||
* @function getTotalXP
|
||||
* @param {string} svid The svid of the user you want to lookup.
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an integer).
|
||||
*/
|
||||
function getTotalXP (svid) {
|
||||
return new Promise((resolve) => {
|
||||
user.getUser(svid, true).then(value => {
|
||||
resolve(value.post_likes + value.comment_likes + (value.twitch_message_xp * 4) + (value.discord_commends * 5) + (value.discord_message_xp * 2) + (value.discord_game_xp / 100))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the stock owner and the amount they own.
|
||||
* @function getStockOwner
|
||||
* @param {string} ticker The ticker you want to lookup.
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an Object).
|
||||
*/
|
||||
function getStockOwner (ticker) {
|
||||
return new Promise((resolve) => {
|
||||
eco.getOwnerData(ticker, true).then(value => {
|
||||
StockOwnerAmount = value.length - 1
|
||||
resolve({ name: `${value[StockOwnerAmount].ownerName}`, amount: value[StockOwnerAmount].amount })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
getTotalXP,
|
||||
getStockOwner
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
// SpookVooper API - modules/user.js
|
||||
// Written by Brendan Lane
|
||||
|
||||
/** @module modules/user */
|
||||
import axios from 'axios'
|
||||
|
||||
const baseURL = 'https://api.spookvooper.com/user'
|
||||
|
||||
/**
|
||||
* Gets information on the user
|
||||
* @function getUser
|
||||
* @param {string} svid The svid for the user.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getUser (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getUser?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of a user
|
||||
* @function getUsername
|
||||
* @param {string} svid The svid for the user lookup.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getUsername (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getUsername?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the svid of a user from their username
|
||||
* @function getSvidFromUsername
|
||||
* @param {string} username The username of the user
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getSvidFromUsername (username, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getSvidFromUsername?username=${username}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username from their linked discord account
|
||||
* @function getUsernameFromDiscord
|
||||
* @param {string} discordid The discord User ID for the user account.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getUsernameFromDiscord (discordid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getUsernameFromDiscord?discordid=${discordid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SVID of a user who has their discord account linked.
|
||||
* @function getSvidFromDiscord
|
||||
* @param {string} discordid The discord user ID
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getSvidFromDiscord (discordid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getSvidFromDiscord?discordid=${discordid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username from the minecraft UUID.
|
||||
* @function getUsernameFromMinecraft
|
||||
* @param {string} minecraftid The UUID of the minecraft user.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getUsernameFromMinecraft (minecraftid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getUsernameFromMinecraft?minecraftid=${minecraftid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SVID from the minecraft UUID.
|
||||
* @function getSvidFromMinecraft
|
||||
* @param {string} minecraftid The UUID of the minecraft user.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getSvidFromMinecraft (minecraftid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getSvidFromMinecraft?minecraftid=${minecraftid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user has a discord role
|
||||
* @function hasDiscordRole
|
||||
* @param {string} userid The SVID of the user you want to lookup
|
||||
* @param {string} role The name of the role you want to lookup.
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a boolean).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function hasDiscordRole (userid, role, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/hasDiscordRole?userid=${userid}&role=${role}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the discord roles of a user
|
||||
* @function getDiscordRoles
|
||||
* @param {string} svid The svid of the user you want to lookup
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON Object).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getDiscordRoles (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getDiscordRoles?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the days since the last move of a user
|
||||
* @function getDiscordRoles
|
||||
* @param {string} svid The svid of the user you want to lookup
|
||||
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
|
||||
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a integer).
|
||||
* @author Brendan Lane <me@imbl.me>
|
||||
*/
|
||||
function getDaysSinceLastMove (svid, errToConsole) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${baseURL}/getDaysSinceLastMove?svid=${svid}`)
|
||||
.then(function (response) {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (errToConsole) {
|
||||
console.warn(error)
|
||||
} else {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
getUser,
|
||||
getUsername,
|
||||
getSvidFromUsername,
|
||||
getUsernameFromDiscord,
|
||||
getSvidFromDiscord,
|
||||
getUsernameFromMinecraft,
|
||||
getSvidFromMinecraft,
|
||||
hasDiscordRole,
|
||||
getDiscordRoles,
|
||||
getDaysSinceLastMove
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "spookvooperapi",
|
||||
"version": "1.3.0",
|
||||
"description": "Easy to use library for the SpookVooper API",
|
||||
"main": "main.js",
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"test": "node main.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vexico/spookvooper-api.git"
|
||||
},
|
||||
"keywords": [
|
||||
"spookvooper",
|
||||
"api",
|
||||
"library"
|
||||
],
|
||||
"author": "Vexi Technologies",
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^10.1.0",
|
||||
"eslint": "^7.9.0",
|
||||
"prettier": "^2.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.20.0"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vexico/spookvooper-api/issues"
|
||||
},
|
||||
"homepage": "https://vexi.cc/"
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
# API Routes
|
||||
|
||||
Allowed routes from the spookvooper api.
|
||||
**Note:** All API routes are api.spookvooper.com OR spookvooper.com/api/
|
||||
|
||||
## /User Routes
|
||||
|
||||
- /GetUser [svid]: Returns all user data
|
||||
- /GetUsername [svid]: Returns username
|
||||
- /GetSVIDFromUsername [username]: Returns SVID
|
||||
- /GetUsernameFromDiscord [discordid]: Returns username
|
||||
- /GetSVIDFromDiscord [discordid]: Returns SVID
|
||||
- /GetUsernameFromMinecraft [minecraftid]: Returns username
|
||||
- /GetSVIDFromMinecraft [minecraftid]: Returns SVID
|
||||
- /HasDiscordRole [userid, role]: Returns true or false
|
||||
- /GetDiscordRoles [svid]: Returns list of roles
|
||||
- /GetDaysSinceLastMove [svid]: Returns an integer
|
||||
|
||||
## Group Routes
|
||||
|
||||
- /DoesGroupExist [svid]: Returns true or false
|
||||
- /GetGroupMembers [svid]: Returns all member SVIDs, in a json list object
|
||||
- /HasGroupPermission [svid, usersvid, permission]: Returns true or false
|
||||
- /GetSVIDFromName [name]: Returns SVID
|
||||
- /GetName [svid]: Returns name
|
||||
|
||||
## /Eco Routes
|
||||
|
||||
- /GetBalance [svid]: Returns decimal
|
||||
- /SendTransactionByIDs [from, to, amount, auth, detail]: Returns a result. 'from' and 'to' are svids. Detail should include 'sale' if it is a sale.
|
||||
- /GetStockValue [ticker]: Returns decimal
|
||||
- /GetStockHistory [ticker, type, count, interval]: Returns list of stock history. Please do not use a count of over 60. Type can be "MINUTE", "HOUR", or "DAY".
|
||||
- /SubmitStockBuy [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it.
|
||||
- /SubmitStockSell [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it.
|
||||
- /CancelOrder [orderid, accountid, auth]: Returns a result.
|
||||
- /GetStockBuyPrice [ticker]: Returns decimal. Cheapest stock available for ticker.
|
||||
- /GetQueueInfo [ticker, type]: Returns list of queue data. Type can be "BUY" or "SELL".
|
||||
- /GetUserStockOffers [ticker, svid]: Returns list of stock offer data.
|
||||
- /GetDistrictWealth [id]: Returns total wealth of a district
|
||||
- /GetDistrictUserWealth [id]: Returns total user wealth of a district
|
||||
- /GetDistrictGroupWealth [id]: Returns total group wealth of a district
|
||||
|
||||
## Oauth2
|
||||
|
||||
What is Oauth2?
|
||||
|
||||
- Oauth2 allows applications to verify and control accounts from another platform without ever sharing sensitive information.
|
||||
How can I use Oauth2?
|
||||
- SpookVooper is currently matching the standard Oauth configuration, although it is limited to only "code" response type and "authorization_code" grant type currently.
|
||||
You can register apps at: <https://spookvooper.com/oauth2>
|
||||
|
||||
### Oauth2 Routes
|
||||
|
||||
- /Authorize [response_type, client_id, redirect_uri, scope, state]: Redirects back to 'redirect_uri' with a "code" and "state" parameter if successful
|
||||
- /RequestToken [grant_type, code, redirect_uri, client_id, client_secret]: Returns a json object containing the token, expire time in seconds, and svid of the authorized user
|
||||
|
||||
### What are the scopes
|
||||
|
||||
All scopes are now supported! Separate them with commas. The simplest scope is "view", which just gives you the id of the account. Also useful is "eco".
|
||||
|
||||
### How do I use the key?
|
||||
|
||||
Instead of an API key, format a key as "oauthkey|app_secret". SV will automatically split the two.
|
Loading…
Reference in New Issue