Skip to content

Commit

Permalink
Add function to get raw ESI response
Browse files Browse the repository at this point in the history
Add function to refresh a given character's token
  • Loading branch information
Blacksmoke16 committed Sep 6, 2018
1 parent 125aa99 commit e348c7c
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/script/gesi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function onOpen(): void {

/**
* Parses array data into more readable format
* @param {string} endpoint_name Name of the endpoint data to be parsed is from.
* @param {string} column_name Name of the column to be parsed.
* @param {array} array Cell that holds the array data to be parsed.
* @param {string} endpoint_name (Required) Name of the endpoint data to be parsed is from.
* @param {string} column_name (Required) Name of the column to be parsed.
* @param {array} array (Required) Cell that holds the array data to be parsed.
* @param {boolean} opt_headers Default: True, Boolean if column headings should be listed or not.
* @return Parsed array data.
* @customfunction
Expand Down Expand Up @@ -58,7 +58,7 @@ function parseArray(endpoint_name: string, column_name: string, array: string, o

/**
* Returns a character's access_token if not expired
* @param {string} character_name Who's access_token to fetch
* @param {string} character_name (Required) Who's access_token to fetch.
* @return Access token
* @customfunction
*/
Expand All @@ -77,15 +77,36 @@ function getMainCharacter(): string {

/**
* Sets the sheets' MAIN_CHARACTER to the given character
* @param {string} name Name of the character to use as the new MAIN_CHARACTER.
* @param {string} character_name (Required) Name of the character to use as the new MAIN_CHARACTER.
* @return If it was successful. Should be deleted if it was.
* @customfunction
*/
function setMainCharacter(name: string): string {
function setMainCharacter(character_name: string): string {
DOCUMENT_PROPERTIES.setProperty('MAIN_CHARACTER', name);
return 'Done! Delete me.';
}

/**
* Gets the raw response from the given ESI endpoint
* @param {string} endpoint_name (Required) Name of the endpoint to fetch data from.
* @param {string} params params to use for the request.
* @return Hash of JSON data and headers
* @customfunction
*/
function getRawData(endpoint_name: string, params: IFunctionParam = {} as IFunctionParam): IRequestResponse {
return getData_(endpoint_name, params);
}

/**
* Refreshes the access token for a given character and returns a new access token
* @param {string} character_name (Required) Name of the character to refresh the token.
* @return A new access token for the character
* @customfunction
*/
function refreshToken(character_name: string): string {
return refreshToken_(character_name);
}

function showSSOModal(): void {
const redirectUrl = `https://script.google.com/macros/d/${ScriptApp.getScriptId()}/usercallback`;
const stateToken = ScriptApp.newStateToken().withMethod('authCallback').withTimeout(1200).createToken();
Expand Down Expand Up @@ -145,7 +166,7 @@ function parseData_(endpoint_name: string, params: IFunctionParam): any[][] {
return result;
}

function getData_(endpoint_name: string, params: IFunctionParam) {
function getData_(endpoint_name: string, params: IFunctionParam): IRequestResponse {
const endpoint: IEndpoint = ENDPOINTS[endpoint_name];
const character_name = params.name || DOCUMENT_PROPERTIES.getProperty('MAIN_CHARACTER');
const character = getCharacterRow_(character_name);
Expand Down

0 comments on commit e348c7c

Please sign in to comment.