tempnumber-client
Version:
temp-number.org SMS Typescript client
44 lines (43 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Activation = void 0;
const base_1 = require("../base");
const activation_1 = require("../../types/activation");
const exceptions_1 = require("../exceptions");
class Activation extends base_1.Base {
async newActivation(payload) {
const response = await this.apiCall('/activation', payload, 'post');
return response.data;
}
async getActivationState(id) {
const response = await this.apiCall(`/activation/${id}`);
try {
response.data.status = activation_1.NumActivationStatus[response.data.status];
}
catch (err) {
throw new exceptions_1.InternalException(err, 'Invalid activation status');
}
return response.data;
}
async getActivationsHistory(page = 1, limit = 10) {
const response = await this.apiCall(`/activations`, { page, limit });
try {
for (let i = 0; i < response.data.activations.length; i++) {
response.data.activations[i].status = activation_1.NumActivationStatus[response.data.activations[i].status];
}
}
catch (err) {
throw new exceptions_1.InternalException(err, 'Invalid activation status');
}
return response.data;
}
async retryActivation(id) {
const response = await this.apiCall(`/activation/${id}/retry`, undefined, 'put');
return response.data;
}
async cancelActivation(id) {
const response = await this.apiCall(`/activation/${id}/cancel`, undefined, 'put');
return response.data;
}
}
exports.Activation = Activation;