spitfirepm
Version:
Client API Tools for Spitfire Project Management
410 lines • 16.3 kB
JavaScript
"use strict";
/* tslint:disable */
/* eslint-disable */
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v13.11.2.0 (NJsonSchema v10.4.4.0 (Newtonsoft.Json v11.0.0.0)) (http://NSwag.org)
// </auto-generated>
//----------------------
// ReSharper disable InconsistentNaming
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiException = exports.UITrialRequest = exports.UITrialResponse = exports.Client = void 0;
const jQuery = require("jquery");
class Client {
constructor(baseUrl) {
this.beforeSend = undefined;
this.jsonParseReviver = undefined;
this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : "http://localhost:60499";
}
/**
* Authenticates a session and generates a FormsAuthenticationTicket and cookie
*/
apiAccount(siteID, uID) {
return new Promise((resolve, reject) => {
this.apiAccountWithCallbacks(siteID, uID, (result) => resolve(result), (exception, _reason) => reject(exception));
});
}
apiAccountWithCallbacks(siteID, uID, onSuccess, onFail) {
let url_ = this.baseUrl + "/api/account?";
if (siteID === undefined || siteID === null)
throw new Error("The parameter 'siteID' must be defined and cannot be null.");
else
url_ += "siteID=" + encodeURIComponent("" + siteID) + "&";
if (uID === undefined || uID === null)
throw new Error("The parameter 'uID' must be defined and cannot be null.");
else
url_ += "uID=" + encodeURIComponent("" + uID) + "&";
url_ = url_.replace(/[?&]$/, "");
jQuery.ajax({
url: url_,
beforeSend: this.beforeSend,
type: "get",
dataType: "text",
headers: {
"Accept": "application/json"
}
}).done((_data, _textStatus, xhr) => {
this.processApiAccountWithCallbacks(url_, xhr, onSuccess, onFail);
}).fail((xhr) => {
this.processApiAccountWithCallbacks(url_, xhr, onSuccess, onFail);
});
}
processApiAccountWithCallbacks(_url, xhr, onSuccess, onFail) {
try {
let result = this.processApiAccount(xhr);
if (onSuccess !== undefined)
onSuccess(result);
}
catch (e) {
if (onFail !== undefined)
onFail(e, "http_service_exception");
}
}
processApiAccount(xhr) {
const status = xhr.status;
let _headers = {};
if (status === 401) {
const _responseText = xhr.responseText;
let result401 = null;
let resultData401 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result401 = resultData401 !== undefined ? resultData401 : null;
return throwException("unusable credentials", status, _responseText, _headers, result401);
}
else if (status === 400) {
const _responseText = xhr.responseText;
let result400 = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = resultData400 !== undefined ? resultData400 : null;
return throwException("not allowed now", status, _responseText, _headers, result400);
}
else if (status === 200) {
const _responseText = xhr.responseText;
let result200 = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : null;
return result200;
}
else if (status !== 200 && status !== 204) {
const _responseText = xhr.responseText;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return null;
}
/**
* Requests permission to try the UI
*/
apiUitrial(request) {
return new Promise((resolve, reject) => {
this.apiUitrialWithCallbacks(request, (result) => resolve(result), (exception, _reason) => reject(exception));
});
}
apiUitrialWithCallbacks(request, onSuccess, onFail) {
let url_ = this.baseUrl + "/api/uitrial";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(request);
jQuery.ajax({
url: url_,
beforeSend: this.beforeSend,
type: "post",
data: content_,
dataType: "text",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
}).done((_data, _textStatus, xhr) => {
this.processApiUitrialWithCallbacks(url_, xhr, onSuccess, onFail);
}).fail((xhr) => {
this.processApiUitrialWithCallbacks(url_, xhr, onSuccess, onFail);
});
}
processApiUitrialWithCallbacks(_url, xhr, onSuccess, onFail) {
try {
let result = this.processApiUitrial(xhr);
if (onSuccess !== undefined)
onSuccess(result);
}
catch (e) {
if (onFail !== undefined)
onFail(e, "http_service_exception");
}
}
processApiUitrial(xhr) {
const status = xhr.status;
let _headers = {};
if (status === 400) {
const _responseText = xhr.responseText;
let result400 = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = resultData400 !== undefined ? resultData400 : null;
return throwException("Incorrect site key or email", status, _responseText, _headers, result400);
}
else if (status === 200) {
const _responseText = xhr.responseText;
let result200 = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? UITrialResponse.fromJS(resultData200) : null;
return result200;
}
else if (status !== 200 && status !== 204) {
const _responseText = xhr.responseText;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return null;
}
/**
* Ends this session
*/
apiAccountLogout() {
return new Promise((resolve, reject) => {
this.apiAccountLogoutWithCallbacks((result) => resolve(result), (exception, _reason) => reject(exception));
});
}
apiAccountLogoutWithCallbacks(onSuccess, onFail) {
let url_ = this.baseUrl + "/api/account/logout";
url_ = url_.replace(/[?&]$/, "");
jQuery.ajax({
url: url_,
beforeSend: this.beforeSend,
type: "get",
dataType: "text",
headers: {
"Accept": "application/json"
}
}).done((_data, _textStatus, xhr) => {
this.processApiAccountLogoutWithCallbacks(url_, xhr, onSuccess, onFail);
}).fail((xhr) => {
this.processApiAccountLogoutWithCallbacks(url_, xhr, onSuccess, onFail);
});
}
processApiAccountLogoutWithCallbacks(_url, xhr, onSuccess, onFail) {
try {
let result = this.processApiAccountLogout(xhr);
if (onSuccess !== undefined)
onSuccess(result);
}
catch (e) {
if (onFail !== undefined)
onFail(e, "http_service_exception");
}
}
processApiAccountLogout(xhr) {
const status = xhr.status;
let _headers = {};
if (status === 200) {
const _responseText = xhr.responseText;
let result200 = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : null;
return result200;
}
else if (status !== 200 && status !== 204) {
const _responseText = xhr.responseText;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return null;
}
/**
* Returns name of site
*/
apiSiteName(siteID) {
return new Promise((resolve, reject) => {
this.apiSiteNameWithCallbacks(siteID, (result) => resolve(result), (exception, _reason) => reject(exception));
});
}
apiSiteNameWithCallbacks(siteID, onSuccess, onFail) {
let url_ = this.baseUrl + "/api/site/{siteID}/name";
if (siteID === undefined || siteID === null)
throw new Error("The parameter 'siteID' must be defined.");
url_ = url_.replace("{siteID}", encodeURIComponent("" + siteID));
url_ = url_.replace(/[?&]$/, "");
jQuery.ajax({
url: url_,
beforeSend: this.beforeSend,
type: "get",
dataType: "text",
headers: {}
}).done((_data, _textStatus, xhr) => {
this.processApiSiteNameWithCallbacks(url_, xhr, onSuccess, onFail);
}).fail((xhr) => {
this.processApiSiteNameWithCallbacks(url_, xhr, onSuccess, onFail);
});
}
processApiSiteNameWithCallbacks(_url, xhr, onSuccess, onFail) {
try {
let result = this.processApiSiteName(xhr);
if (onSuccess !== undefined)
onSuccess(result);
}
catch (e) {
if (onFail !== undefined)
onFail(e, "http_service_exception");
}
}
processApiSiteName(xhr) {
const status = xhr.status;
let _headers = {};
if (status === 400) {
const _responseText = xhr.responseText;
let result400 = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = resultData400 !== undefined ? resultData400 : null;
return throwException("Incorrect site key", status, _responseText, _headers, result400);
}
else if (status !== 200 && status !== 204) {
const _responseText = xhr.responseText;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return;
}
/**
* Returns license for the requested server
*/
apiSiteLicense(siteID, serverName) {
return new Promise((resolve, reject) => {
this.apiSiteLicenseWithCallbacks(siteID, serverName, (result) => resolve(result), (exception, _reason) => reject(exception));
});
}
apiSiteLicenseWithCallbacks(siteID, serverName, onSuccess, onFail) {
let url_ = this.baseUrl + "/api/site/{siteID}/license?";
if (siteID === undefined || siteID === null)
throw new Error("The parameter 'siteID' must be defined.");
url_ = url_.replace("{siteID}", encodeURIComponent("" + siteID));
if (serverName === undefined)
throw new Error("The parameter 'serverName' must be defined.");
else if (serverName !== null)
url_ += "serverName=" + encodeURIComponent("" + serverName) + "&";
url_ = url_.replace(/[?&]$/, "");
jQuery.ajax({
url: url_,
beforeSend: this.beforeSend,
type: "get",
dataType: "text",
headers: {}
}).done((_data, _textStatus, xhr) => {
this.processApiSiteLicenseWithCallbacks(url_, xhr, onSuccess, onFail);
}).fail((xhr) => {
this.processApiSiteLicenseWithCallbacks(url_, xhr, onSuccess, onFail);
});
}
processApiSiteLicenseWithCallbacks(_url, xhr, onSuccess, onFail) {
try {
let result = this.processApiSiteLicense(xhr);
if (onSuccess !== undefined)
onSuccess(result);
}
catch (e) {
if (onFail !== undefined)
onFail(e, "http_service_exception");
}
}
processApiSiteLicense(xhr) {
const status = xhr.status;
let _headers = {};
if (status === 400) {
const _responseText = xhr.responseText;
let result400 = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = resultData400 !== undefined ? resultData400 : null;
return throwException("Incorrect site key", status, _responseText, _headers, result400);
}
else if (status !== 200 && status !== 204) {
const _responseText = xhr.responseText;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return;
}
}
exports.Client = Client;
class UITrialResponse {
constructor(data) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
this[property] = data[property];
}
}
}
init(_data) {
if (_data) {
this.responseKey = _data["responseKey"];
this.permissionGranted = _data["permissionGranted"];
this.grantCount = _data["grantCount"];
this.grantInfo = _data["grantInfo"];
this.checksum = _data["checksum"];
}
}
static fromJS(data) {
data = typeof data === 'object' ? data : {};
let result = new UITrialResponse();
result.init(data);
return result;
}
toJSON(data) {
data = typeof data === 'object' ? data : {};
data["responseKey"] = this.responseKey;
data["permissionGranted"] = this.permissionGranted;
data["grantCount"] = this.grantCount;
data["grantInfo"] = this.grantInfo;
data["checksum"] = this.checksum;
return data;
}
}
exports.UITrialResponse = UITrialResponse;
class UITrialRequest {
constructor(data) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
this[property] = data[property];
}
}
}
init(_data) {
if (_data) {
this.email = _data["email"];
this.fullName = _data["fullName"];
this.userKey = _data["userKey"];
this.siteKey = _data["siteKey"];
this.comment = _data["comment"];
}
}
static fromJS(data) {
data = typeof data === 'object' ? data : {};
let result = new UITrialRequest();
result.init(data);
return result;
}
toJSON(data) {
data = typeof data === 'object' ? data : {};
data["email"] = this.email;
data["fullName"] = this.fullName;
data["userKey"] = this.userKey;
data["siteKey"] = this.siteKey;
data["comment"] = this.comment;
return data;
}
}
exports.UITrialRequest = UITrialRequest;
class ApiException extends Error {
constructor(message, status, response, headers, result) {
super();
this.isApiException = true;
this.message = message;
this.status = status;
this.response = response;
this.headers = headers;
this.result = result;
}
static isApiException(obj) {
return obj.isApiException === true;
}
}
exports.ApiException = ApiException;
function throwException(message, status, response, headers, result) {
if (result !== null && result !== undefined)
throw result;
else
throw new ApiException(message, status, response, headers, null);
}
//# sourceMappingURL=SWSRestClients.js.map