domrobot-client
Version:
INWX Domrobot Node.JS Client
46 lines • 2.64 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 });
const domrobot_1 = require("../domrobot");
const username = '';
const password = '';
const sharedSecret = ''; // only needed for 2FA.
const domain = 'my-test-domain-' + Math.round(Math.random() * 1e8) + '.com'; // the domain which will be checked.
const asyncFunc = () => __awaiter(void 0, void 0, void 0, function* () {
// By default, your ApiClient uses the test api (OT&E). If you want to use the production/live api
// we have a constant named API_URL_LIVE in the ApiClient class. Just set apiUrl=ApiClient.API_URL_LIVE and you're good.
const apiClient = new domrobot_1.ApiClient(domrobot_1.ApiClient.API_URL_OTE, domrobot_1.Language.EN, true);
const loginResponse = yield apiClient.login(username, password, sharedSecret);
if (loginResponse.code !== 1000) {
throw new Error(`Api login error. Code: ${loginResponse.code} Message: ${loginResponse.msg}`);
}
// Make an api call and save the result in a variable.
// We want to check if a domain is available, so we call the api method 'domain.check'.
const domainCheckResponse = yield apiClient.callApi('domain.check', { domain });
if (domainCheckResponse.code !== 1000) {
throw new Error(`Api error while checking domain status. Code:
${domainCheckResponse.code} Message: ${domainCheckResponse.msg}`);
}
// get the first domain in the result array 'domain'
const checkedDomain = domainCheckResponse.resData.domain[0];
if (checkedDomain.avail === 1) {
console.log(`${domain} is still available!`);
}
else if (checkedDomain.avail === -1) {
console.log(`Availability of ${domain} could not be checked.`);
}
else {
console.log(`Unfortunately, ${domain} is already registered.`);
}
});
// call the async function
asyncFunc().catch(console.error);
//# sourceMappingURL=domaincheck.js.map