Created
October 9, 2022 23:22
-
-
Save anvilation/db2826a58cae84b41b3e2cd99c821957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { request } from 'urllib'; | |
export class OTRestAPI { | |
user: string; | |
pass: string; | |
csurl: string; | |
otdsurl: string; | |
ticket: string | null = null; | |
constructor(user: string, pass: string, csurl: string, otdsurl: string) { | |
this.user = user; | |
this.pass = pass; | |
this.csurl = csurl; | |
this.otdsurl = otdsurl; | |
} | |
async login() { | |
try { | |
const url = `${this.otdsurl}/otdsws/v1/authentication/credentials`; | |
const body = { | |
user_name: this.user, | |
password: this.pass, | |
ticket_type: 'OTDSTICKET' | |
}; | |
let options: urllib.RequestOptions = { | |
method: 'POST', | |
maxRedirects: 10, | |
data: body, | |
contentType: 'json', | |
dataType: 'json' | |
} | |
const req = await request(url, options); | |
this.ticket = req.data.ticket; | |
return Promise.resolve(); | |
} catch (error) { | |
console.error(`Error: OTRestAPI.login`); | |
console.error(error); | |
return Promise.reject(error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment