UNPKG

@team-internet/apiconnector

Version:
108 lines (107 loc) 2.59 kB
export const fixedURLEnc = (str) => { return encodeURIComponent(str).replace(/[!'()*]/g, (c) => { return `%${c.charCodeAt(0).toString(16).toUpperCase()}`; }); }; /** * SocketConfig Class */ export class SocketConfig { /** * account name */ login; /** * persistent for session request */ persistent; /** * account password */ pw; /** * API session id */ sessionid; constructor() { this.login = ""; this.persistent = ""; this.pw = ""; this.sessionid = ""; } /** * Create POST data string out of connection data * @returns POST data string */ getPOSTData() { let data = ""; if (this.login !== "") { data += `${fixedURLEnc("s_login")}=${fixedURLEnc(this.login)}&`; } if (this.persistent !== "") { data += `${fixedURLEnc("persistent")}=${fixedURLEnc(this.persistent)}&`; } if (this.pw !== "") { data += `${fixedURLEnc("s_pw")}=${fixedURLEnc(this.pw)}&`; } if (this.sessionid !== "") { data += `${fixedURLEnc("s_sessionid")}=${fixedURLEnc(this.sessionid)}&`; } return data; } /** * Get API Session ID in use * @returns API Session ID */ getSession() { return this.sessionid; } /** * Set account login to use * @param value account login * @returns Current SocketConfig instance for method chaining */ setLogin(value) { this.sessionid = ""; this.login = value; return this; } /** * Get account login to use * @returns Current login */ getLogin() { return this.login; } /** * Set persistent to request session id * @param value one time password * @returns Current SocketConfig instance for method chaining */ setPersistent() { this.sessionid = ""; this.persistent = "1"; return this; } /** * Set account password to use * @param value account password * @returns Current SocketConfig instance for method chaining */ setPassword(value) { this.sessionid = ""; this.pw = value; return this; } /** * Set API Session ID to use * @param value API Session ID * @returns Current SocketConfig instance for method chaining */ setSession(value) { this.sessionid = value; this.pw = ""; this.persistent = ""; return this; } }