@ariusii/intersect.ts
Version:
The Intersect Engine API Client Library based on TS.
85 lines • 3.1 kB
JavaScript
/**
* This is the Variables Class, it contains all the methods to handle the Variables.
* Those actions do not require any Query Role.
* @class Variables
* @link https://docs.freemmorpgmaker.com/en-US/api/v1/endpoints/variables.html
* @author AriusII
*/
export class Variables {
_url;
_token;
constructor(_url, _token) {
this._url = _url;
this._token = _token;
}
/**
* Retrieves global variables from the server along with their ids and values.
* @param page - The page number you want to retrieve.
* @param count - The number of variables you want to retrieve.
* @returns - The response from the server.
*/
async getVariables(page, count) {
const response = await fetch(`${this._url}/api/v1/variables/global`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._token}`
},
body: JSON.stringify({
page: page || 0,
count: count || 10
})
});
return await response.json();
}
/**
* Retrieves a variable and it's value from the server by id.
* @param variableid - The variable ID you want to retrieve the value for.
* @returns - The response from the server.
*/
async getVariable(variableid) {
const res = await fetch(`${this._url}/api/v1/variables/global/${variableid}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._token}`
},
});
return await res.json();
}
/**
* Sets a specified variable's value given it's id.
* @param variableid - The variable ID you want to set the value for.
* @param value - The value you want to set the variable to.
* @returns - The response from the server.
*/
async setVariableValue(variableid, value) {
const res = await fetch(`${this._url}/api/v1/variables/global/${variableid}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._token}`
},
body: JSON.stringify({
value: value
})
});
return await res.json();
}
/**
* Retrieves the stored value of a variable from the server by id.
* @param variableid - The variable ID you want to retrieve the value for.
* @returns - The response from the server.
*/
async getVariableValue(variableid) {
const res = await fetch(`${this._url}/api/v1/variables/global/${variableid}/value`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._token}`
}
});
return await res.json();
}
}
//# sourceMappingURL=variables.js.map