🟢 Update to add new API route (v1.1.0-Stable)
This commit is contained in:
parent
70f311458d
commit
c24f086aff
|
@ -5,6 +5,7 @@ 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:**
|
||||
|
||||
|
@ -22,9 +23,11 @@ svAPI.eco.getBalance("2a0057e6-356a-4a49-b825-c37796cb7bd9", true).then(value =>
|
|||
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/bowlingballindustries/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.
|
||||
We support all the routes. We even made some in premade.
|
||||
|
||||
* Auth
|
||||
* User
|
||||
|
|
|
@ -8,13 +8,13 @@ let 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
|
||||
* 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 argument 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 argument is requried.
|
||||
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" perameter if successful. This argument is requried.
|
||||
* @param {string} scope The scope of what you want to be able to recieve. Currently the only supported scope is "view". This argument is requried.
|
||||
* @param {string} state The state parameter can have anything here. Will be returned to the server upon completion. This argument is optional.
|
||||
* @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. Currently the only supported scope is "view". 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) {
|
||||
|
@ -37,7 +37,7 @@ function authorize(response_type, client_id, redirect_uri, scope, state) {
|
|||
* @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" perameter if successful.
|
||||
* @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
|
||||
|
|
|
@ -337,6 +337,29 @@ function getDistrictGroupWealth(id, errToConsole) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
|
@ -350,5 +373,6 @@ export default {
|
|||
getUserStockOffers,
|
||||
getDistrictWealth,
|
||||
getDistrictUserWealth,
|
||||
getDistrictGroupWealth
|
||||
getDistrictGroupWealth,
|
||||
getOwnerData
|
||||
};
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
/** @module modules/premade */
|
||||
import user from "./user.js";
|
||||
import eco from "./eco.js";
|
||||
|
||||
let UserResponse;
|
||||
let StockOwnerAmount;
|
||||
|
||||
/**
|
||||
* Gets the total XP of a user
|
||||
|
@ -20,6 +21,22 @@ function getTotalXP(svid) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
getTotalXP,
|
||||
getStockOwner
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "spookvooperapi",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "Easy to use library for the SpookVooper API",
|
||||
"main": "main.js",
|
||||
"type": "module",
|
||||
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.imbl.me/btech/spookvooper-api-libraries.git"
|
||||
"url": "https://github.com/bowlingballindustries/spookvooper-api.git"
|
||||
},
|
||||
"keywords": [
|
||||
"spookvooper",
|
||||
|
|
18
test.js
18
test.js
|
@ -7,19 +7,29 @@ svAPI.eco.getBalance("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value =>
|
|||
*/
|
||||
|
||||
svAPI.eco.getStockBuyPrice("VNB", true).then(value => {
|
||||
console.log(value);
|
||||
console.log(`[VNB] Current Stock Buy Price: ${value}`);
|
||||
});
|
||||
|
||||
svAPI.group.getSvidFromName("Bowling Ball Industries").then(value => {
|
||||
console.log(value);
|
||||
console.log(`Bowling Ball Industries SVID: ${value}`);
|
||||
});
|
||||
|
||||
svAPI.user.getUser("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value => {
|
||||
console.log(value.userName);
|
||||
console.log(`[lonr] getUser.userName value: ${value}`);
|
||||
});
|
||||
|
||||
svAPI.premade.getTotalXP("02c977bb-0a6c-4eb2-bfca-5e9101025aaf").then(value => {
|
||||
console.log(value);
|
||||
console.log(`Total XP for lonr: ${value}`);
|
||||
});
|
||||
|
||||
svAPI.eco.getOwnerData("NEWS", true).then(value => {
|
||||
console.log(`[NEWS] Owner Data: ${value[0].ownerName}`);
|
||||
});
|
||||
|
||||
svAPI.premade.getStockOwner("NEWS").then(value => {
|
||||
console.log(`[NEWS] Owner: ${value.name}`)
|
||||
})
|
||||
|
||||
console.log(`Your Oauth2 URL: ${svAPI.auth.authorize("code", "AAAA-BBBBB-CCCCC-DDDD", "https://example.com/callback", "view", "succeeded")}`);
|
||||
|
||||
// Intended result should be whats on this page: https://api.spookvooper.com/eco/getbalance?svid=02c977bb-0a6c-4eb2-bfca-5e9101025aaf
|
||||
|
|
Loading…
Reference in New Issue