Skip to content

Instantly share code, notes, and snippets.

@anvilation
Created October 9, 2022 23:22
Show Gist options
  • Save anvilation/db2826a58cae84b41b3e2cd99c821957 to your computer and use it in GitHub Desktop.
Save anvilation/db2826a58cae84b41b3e2cd99c821957 to your computer and use it in GitHub Desktop.
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