citeright-sdk-js
Version:
An SDK to connect to the CiteRight API.
53 lines (52 loc) • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var EventNotification = /** @class */ (function () {
function EventNotification() {
}
/**
* Execute this function if we want to track the time between this execution and the sending of the event.
* @constructor
*/
EventNotification.prototype.StartTimer = function () {
this.TimerStartTime = new Date().getTime();
};
/**
* This will return the number of seconds elapsed since the timer was started, or this event object was first
* created.
* @constructor
*/
EventNotification.prototype.GetElapsedSeconds = function () {
if (this.TimerStartTime) {
return (new Date().getTime() - this.TimerStartTime) / 1000;
}
else {
return 0;
}
};
/**
* To help control what data we ultimately send out, use this method to stringify an event to JSON.
*/
EventNotification.prototype.toJSONString = function () {
// This is a hack to remove a private field before sending it as JSON
var data = Object.assign({}, this);
data.TimerStartTime = undefined;
if (!data.EventType) {
data.EventType = this.GetEventNameFromClassName();
}
return JSON.stringify(data);
};
/**
* This method is used to derive an event name from the event's class name.
*
* @constructor
*/
EventNotification.prototype.GetEventNameFromClassName = function () {
var className = this.constructor.name;
return className
.split(/(?=[A-Z])/)
.join('_')
.toLowerCase();
};
return EventNotification;
}());
exports.EventNotification = EventNotification;