verimor-api-sdk
Version:
A NodeJS SDK for the Verimor API
92 lines • 4.04 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlacklistApi = void 0;
const base_api_1 = require("./base-api");
const error_response_1 = require("../models/error-response");
/**
* BlacklistApi class provides methods to manage blacklisted numbers.
*/
class BlacklistApi extends base_api_1.BaseApi {
/**
* Creates an instance of BlacklistApi.
* @param username - The API username.
* @param password - The API password.
* @param proxyConfig - Optional proxy configuration.
*/
constructor(username, password, proxyConfig) {
super(username, password, proxyConfig);
}
/**
* Retrieves blacklisted numbers.
* @param offset - The offset for pagination.
* @param limit - The number of records to retrieve (max 100).
* @returns Promise resolving to an object containing total and records.
* @throws ErrorResponse if the API call fails.
*/
getBlacklistedNumbers(offset = 0, limit = 100) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const params = this.withCredentialsParams({ offset, limit });
const response = yield this.apiClient.get('/blacklists', {
params,
});
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Adds numbers to the blacklist.
* @param phones - Array of phone numbers to blacklist.
* @returns Promise resolving to a success message.
* @throws ErrorResponse if the API call fails.
*/
addNumbersToBlacklist(phones) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const params = this.withCredentialsParams({ phones: phones.join(',') });
const response = yield this.apiClient.post('/blacklists', null, {
params,
});
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Removes numbers from the blacklist.
* @param phones - Array of phone numbers to remove from blacklist.
* @returns Promise resolving to a success message.
* @throws ErrorResponse if the API call fails.
*/
deleteNumbersFromBlacklist(phones) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const params = this.withCredentialsParams({});
const response = yield this.apiClient.delete(`/blacklists/${phones.join(',')}`, { params });
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
}
exports.BlacklistApi = BlacklistApi;
//# sourceMappingURL=blacklist-api.js.map