From f4c2bb6e5b23629b54a5045e724fc3050c0755f7 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 16 May 2016 03:29:29 +0200 Subject: [PATCH] add functionality --- dist/cflare.classes.cflareaccount.d.ts | 6 ++- dist/cflare.classes.cflareaccount.js | 45 ++++++++++++++++++--- package.json | 3 +- test/test.js | 37 ++++++++++++++++- test/test.ts | 35 ++++++++++++++++ ts/cflare.classes.cflareaccount.ts | 55 ++++++++++++++++++++++---- ts/typings.json | 1 + 7 files changed, 166 insertions(+), 16 deletions(-) diff --git a/dist/cflare.classes.cflareaccount.d.ts b/dist/cflare.classes.cflareaccount.d.ts index 3bb950e..897eb44 100644 --- a/dist/cflare.classes.cflareaccount.d.ts +++ b/dist/cflare.classes.cflareaccount.d.ts @@ -7,9 +7,11 @@ export declare class CflareAccount { email: string; key: string; }): void; + getZoneId(domainName: string): any; createRecord(): any; removeRecord(): any; + updateRecord(): void; listRecords(domainName: string): any; - listDomains(): any; - request(methodArg: string, routeArg: string): any; + listZones(domainName?: string): any; + request(methodArg: string, routeArg: string, bodyArg?: any): any; } diff --git a/dist/cflare.classes.cflareaccount.js b/dist/cflare.classes.cflareaccount.js index 7ad36ad..d581309 100644 --- a/dist/cflare.classes.cflareaccount.js +++ b/dist/cflare.classes.cflareaccount.js @@ -12,6 +12,23 @@ var CflareAccount = (function () { this.authEmail = optionsArg.email; this.authKey = optionsArg.key; }; + CflareAccount.prototype.getZoneId = function (domainName) { + var done = plugins.q.defer(); + this.listZones(domainName) + .then(function (responseArg) { + var filteredResponse = responseArg.result.filter(function (zoneArg) { + return zoneArg.name === domainName; + }); + if (filteredResponse.length >= 1) { + done.resolve(filteredResponse[0].id); + } + else { + plugins.beautylog.error("the domain " + domainName.blue + " does not appear to be in this account!"); + done.reject(undefined); + } + }); + return done.promise; + }; CflareAccount.prototype.createRecord = function () { var done = plugins.q.defer(); return done.promise; @@ -22,19 +39,36 @@ var CflareAccount = (function () { return done.promise; }; ; + CflareAccount.prototype.updateRecord = function () { + }; + ; CflareAccount.prototype.listRecords = function (domainName) { + var _this = this; var done = plugins.q.defer(); + this.getZoneId(domainName) + .then(function (domainIdArg) { + _this.request("GET", "/zones/" + domainIdArg + "/dns_records?per_page=100") + .then(function (responseArg) { + done.resolve(responseArg); + }); + }); return done.promise; }; - CflareAccount.prototype.listDomains = function () { + CflareAccount.prototype.listZones = function (domainName) { var done = plugins.q.defer(); - this.request("GET", "/zones") + var requestRoute = "/zones?per_page=50"; + if (domainName) + requestRoute = requestRoute + "&name=" + domainName; + var result = {}; + this.request("GET", requestRoute) .then(function (responseArg) { + result = responseArg; + done.resolve(result); }); return done.promise; }; ; - CflareAccount.prototype.request = function (methodArg, routeArg) { + CflareAccount.prototype.request = function (methodArg, routeArg, bodyArg) { var done = plugins.q.defer(); var options = { method: methodArg, @@ -43,7 +77,8 @@ var CflareAccount = (function () { "Content-Type": "application/json", "X-Auth-Email": this.authEmail, "X-Auth-Key": this.authKey - } + }, + json: bodyArg }; plugins.request(options, function (err, res, body) { if (!err && res.statusCode == 200) { @@ -64,4 +99,4 @@ var CflareAccount = (function () { exports.CflareAccount = CflareAccount; ; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxrQkFBa0IsQ0FBQyxDQUFDO0FBRzdDO0lBTUk7SUFFQSxDQUFDO0lBTE8saUNBQVMsR0FBakI7UUFDSSxNQUFNLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxJQUFJLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLDRCQUE0QjtJQUN6RSxDQUFDOztJQUlELDRCQUFJLEdBQUosVUFBSyxVQUFvQztRQUNyQyxJQUFJLENBQUMsU0FBUyxHQUFHLFV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AgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICBcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfVxyXG4gICAgbGlzdERvbWFpbnMoKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIHRoaXMucmVxdWVzdChcIkdFVFwiLFwiL3pvbmVzXCIpXHJcbiAgICAgICAgICAgIC50aGVuKGZ1bmN0aW9uKHJlc3BvbnNlQXJnKXtcclxuICAgICAgICAgICAgICAgIFxyXG4gICAgICAgICAgICB9KTtcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfTtcclxuICAgIHJlcXVlc3QobWV0aG9kQXJnOnN0cmluZyxyb3V0ZUFyZzpzdHJpbmcpe1xyXG4gICAgICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICAgICAgbGV0IG9wdGlvbnMgPSB7XHJcbiAgICAgICAgICAgIG1ldGhvZDptZXRob2RBcmcsXHJcbiAgICAgICAgICAgIHVybDpcImh0dHBzOi8vYXBpLmNsb3VkZmxhcmUuY29tL2NsaWVudC92NFwiICsgcm91dGVBcmcsXHJcbiAgICAgICAgICAgIGhlYWRlcnM6e1xyXG4gICAgICAgICAgICAgICAgXCJDb250ZW50LVR5cGVcIjpcImFwcGxpY2F0aW9uL2pzb25cIixcclxuICAgICAgICAgICAgICAgIFwiWC1BdXRoLUVtYWlsXCI6dGhpcy5hdXRoRW1haWwsXHJcbiAgICAgICAgICAgICAgICBcIlgtQXV0aC1LZXlcIjp0aGlzLmF1dGhLZXlcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBwbHVnaW5zLnJlcXVlc3Qob3B0aW9ucyxmdW5jdGlvbihlcnIsIHJlcywgYm9keSl7XHJcbiAgICAgICAgICAgIGlmICghZXJyICYmIHJlcy5zdGF0dXNDb2RlID09IDIwMCkge1xyXG4gICAgICAgICAgICAgICAgdmFyIHJlc3BvbnNlT2JqID0gSlNPTi5wYXJzZShib2R5KTtcclxuICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZShyZXNwb25zZU9iaik7XHJcbiAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpO1xyXG4gICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKTtcclxuICAgICAgICAgICAgICAgIGRvbmUucmVqZWN0KGVycik7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcclxuICAgIH1cclxufTsiXX0= +//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxrQkFBa0IsQ0FBQyxDQUFDO0FBRzdDO0lBTUk7SUFFQSxDQUFDO0lBTE8saUNBQVMsR0FBakI7UUFDSSxNQUFNLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxJQUFJLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLDRCQUE0QjtJQUN6RSxDQUFDOztJQUlELDRCQUFJLEdBQUosVUFBSyxVQUFvQztRQUNyQyxJQUFJLENBQUMsU0FBUyxHQUFHLFVBQVUsQ0FBQyxLQUFLLENBQUM7UUFDbEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUMsR0FBRyxDQUFDO0lBQ2xDLENBQUM7SUFDRCxpQ0FBUyxHQUFULFVBQVUsVUFBaUI7UUFDdkIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUU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fVxyXG4gICAgZ2V0Wm9uZUlkKGRvbWFpbk5hbWU6c3RyaW5nKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIHRoaXMubGlzdFpvbmVzKGRvbWFpbk5hbWUpXHJcbiAgICAgICAgICAgIC50aGVuKChyZXNwb25zZUFyZykgPT4ge1xyXG4gICAgICAgICAgICAgICAgbGV0IGZpbHRlcmVkUmVzcG9uc2UgPSByZXNwb25zZUFyZy5yZXN1bHQuZmlsdGVyKCh6b25lQXJnKT0+e1xyXG4gICAgICAgICAgICAgICAgICAgIHJldHVybiB6b25lQXJnLm5hbWUgPT09IGRvbWFpbk5hbWU7XHJcbiAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgICAgIGlmIChmaWx0ZXJlZFJlc3BvbnNlLmxlbmd0aCA+PSAxKXtcclxuICAgICAgICAgICAgICAgICAgICBkb25lLnJlc29sdmUoZmlsdGVyZWRSZXNwb25zZVswXS5pZCk7XHJcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xyXG4gICAgICAgICAgICAgICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLmVycm9yKFwidGhlIGRvbWFpbiBcIiArIGRvbWFpbk5hbWUuYmx1ZSArIFwiIGRvZXMgbm90IGFwcGVhciB0byBiZSBpbiB0aGlzIGFjY291bnQhXCIpO1xyXG4gICAgICAgICAgICAgICAgICAgIGRvbmUucmVqZWN0KHVuZGVmaW5lZCk7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9XHJcbiAgICBjcmVhdGVSZWNvcmQoKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9O1xyXG4gICAgcmVtb3ZlUmVjb3JkKCl7XHJcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfTtcclxuICAgIHVwZGF0ZVJlY29yZCgpe1xyXG4gICAgICAgIFxyXG4gICAgfTtcclxuICAgIGxpc3RSZWNvcmRzKGRvbWFpbk5hbWU6c3RyaW5nKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIHRoaXMuZ2V0Wm9uZUlkKGRvbWFpbk5hbWUpXHJcbiAgICAgICAgICAgIC50aGVuKChkb21haW5JZEFyZyk9PntcclxuICAgICAgICAgICAgICAgIHRoaXMucmVxdWVzdChcIkdFVFwiLFwiL3pvbmVzL1wiICsgZG9tYWluSWRBcmcgKyBcIi9kbnNfcmVjb3Jkcz9wZXJfcGFnZT0xMDBcIilcclxuICAgICAgICAgICAgICAgICAgICAudGhlbihmdW5jdGlvbihyZXNwb25zZUFyZyl7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZShyZXNwb25zZUFyZyk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9XHJcbiAgICBsaXN0Wm9uZXMoZG9tYWluTmFtZT86c3RyaW5nKXtcclxuICAgICAgICBsZXQgZG9uZSA9IHBsdWdpbnMucS5kZWZlcigpO1xyXG4gICAgICAgIGxldCByZXF1ZXN0Um91dGUgPSBcIi96b25lcz9wZXJfcGFnZT01MFwiXHJcbiAgICAgICAgaWYoZG9tYWluTmFtZSkgcmVxdWVzdFJvdXRlID0gcmVxdWVzdFJvdXRlICsgXCImbmFtZT1cIiArIGRvbWFpbk5hbWU7XHJcbiAgICAgICAgbGV0IHJlc3VsdCA9IHt9OyBcclxuICAgICAgICB0aGlzLnJlcXVlc3QoXCJHRVRcIixyZXF1ZXN0Um91dGUpXHJcbiAgICAgICAgICAgIC50aGVuKGZ1bmN0aW9uKHJlc3BvbnNlQXJnKXtcclxuICAgICAgICAgICAgICAgIHJlc3VsdCA9IHJlc3BvbnNlQXJnO1xyXG4gICAgICAgICAgICAgICAgZG9uZS5yZXNvbHZlKHJlc3VsdCk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbiAgICB9O1xyXG4gICAgcmVxdWVzdChtZXRob2RBcmc6c3RyaW5nLHJvdXRlQXJnOnN0cmluZyxib2R5QXJnPyl7XHJcbiAgICAgICAgbGV0IGRvbmUgPSBwbHVnaW5zLnEuZGVmZXIoKTtcclxuICAgICAgICBsZXQgb3B0aW9ucyA9IHtcclxuICAgICAgICAgICAgbWV0aG9kOm1ldGhvZEFyZyxcclxuICAgICAgICAgICAgdXJsOlwiaHR0cHM6Ly9hcGkuY2xvdWRmbGFyZS5jb20vY2xpZW50L3Y0XCIgKyByb3V0ZUFyZyxcclxuICAgICAgICAgICAgaGVhZGVyczp7XHJcbiAgICAgICAgICAgICAgICBcIkNvbnRlbnQtVHlwZVwiOlwiYXBwbGljYXRpb24vanNvblwiLFxyXG4gICAgICAgICAgICAgICAgXCJYLUF1dGgtRW1haWxcIjp0aGlzLmF1dGhFbWFpbCxcclxuICAgICAgICAgICAgICAgIFwiWC1BdXRoLUtleVwiOnRoaXMuYXV0aEtleVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBqc29uOmJvZHlBcmdcclxuICAgICAgICB9O1xyXG4gICAgICAgIHBsdWdpbnMucmVxdWVzdChvcHRpb25zLGZ1bmN0aW9uKGVyciwgcmVzLCBib2R5KXtcclxuICAgICAgICAgICAgaWYgKCFlcnIgJiYgcmVzLnN0YXR1c0NvZGUgPT0gMjAwKSB7XHJcbiAgICAgICAgICAgICAgICB2YXIgcmVzcG9uc2VPYmogPSBKU09OLnBhcnNlKGJvZHkpO1xyXG4gICAgICAgICAgICAgICAgZG9uZS5yZXNvbHZlKHJlc3BvbnNlT2JqKTtcclxuICAgICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycik7XHJcbiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpO1xyXG4gICAgICAgICAgICAgICAgZG9uZS5yZWplY3QoZXJyKTtcclxuICAgICAgICAgICAgfTtcclxuICAgICAgICB9KTtcclxuICAgICAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG4gICAgfVxyXG59OyJdfQ== diff --git a/package.json b/package.json index abf13cb..3b480f4 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "request": "^2.72.0" }, "devDependencies": { - "npmts": "^5.1.5" + "npmts": "^5.1.5", + "should": "^8.3.1" } } diff --git a/test/test.js b/test/test.js index 709f334..d6a27cf 100644 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,46 @@ "use strict"; /// var cflare = require("../dist/index"); +var should = require("should"); var nogit = require("../nogit/nogit.json"); var testCflareAccount = new cflare.CflareAccount(); testCflareAccount.auth({ email: nogit.cfemail, key: nogit.cfkey }); +describe("cflare", function () { + describe(".CflareAccount", function () { + describe(".listZones()", function () { + it("should display an account", function (done) { + this.timeout(10000); + testCflareAccount.listZones() + .then(function (responseArg) { + console.log(responseArg); + done(); + }); + }); + }); + describe(".getZoneId(domainName)", function () { + it("should get an Cloudflare Id for a domain string", function (done) { + this.timeout(5000); + testCflareAccount.getZoneId("push.rocks") + .then(function (responseArg) { + console.log(responseArg); + done(); + }); + }); + }); + describe(".listRecords(domainName)", function () { + it("should list all records for a specific Domain Name", function (done) { + this.timeout(5000); + testCflareAccount.listRecords("push.rocks") + .then(function (responseArg) { + console.log(responseArg); + done(); + }); + }); + }); + }); +}); -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW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mUoXCIuQ2ZsYXJlQWNjb3VudFwiLGZ1bmN0aW9uKCl7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIubGlzdFpvbmVzKClcIixmdW5jdGlvbigpe1xyXG4gICAgICAgICAgICBpdChcInNob3VsZCBkaXNwbGF5IGFuIGFjY291bnRcIixmdW5jdGlvbihkb25lKXtcclxuICAgICAgICAgICAgICAgIHRoaXMudGltZW91dCgxMDAwMCk7XHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5saXN0Wm9uZXMoKVxyXG4gICAgICAgICAgICAgICAgICAgIC50aGVuKChyZXNwb25zZUFyZyk9PntcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2VBcmcpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIuZ2V0Wm9uZUlkKGRvbWFpbk5hbWUpXCIsZnVuY3Rpb24oKXtcclxuICAgICAgICAgICAgaXQoXCJzaG91bGQgZ2V0IGFuIENsb3VkZmxhcmUgSWQgZm9yIGEgZG9tYWluIHN0cmluZ1wiLGZ1bmN0aW9uKGRvbmUpe1xyXG4gICAgICAgICAgICAgICAgdGhpcy50aW1lb3V0KDUwMDApXHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5nZXRab25lSWQoXCJwdXNoLnJvY2tzXCIpXHJcbiAgICAgICAgICAgICAgICAgICAgLnRoZW4oKHJlc3BvbnNlQXJnKT0+e1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXNwb25zZUFyZyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIubGlzdFJlY29yZHMoZG9tYWluTmFtZSlcIixmdW5jdGlvbigpe1xyXG4gICAgICAgICAgICBpdChcInNob3VsZCBsaXN0IGFsbCByZWNvcmRzIGZvciBhIHNwZWNpZmljIERvbWFpbiBOYW1lXCIsZnVuY3Rpb24oZG9uZSl7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5saXN0UmVjb3JkcyhcInB1c2gucm9ja3NcIilcclxuICAgICAgICAgICAgICAgICAgICAudGhlbigocmVzcG9uc2VBcmcpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2VBcmcpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pXHJcbiAgICB9KVxyXG59KTtcclxuIl19 diff --git a/test/test.ts b/test/test.ts index 3debc2f..6d36e8b 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,5 +1,6 @@ /// import cflare = require("../dist/index"); +let should = require("should"); let nogit = require("../nogit/nogit.json"); let testCflareAccount = new cflare.CflareAccount(); @@ -8,3 +9,37 @@ testCflareAccount.auth({ key: nogit.cfkey }); +describe("cflare",function(){ + describe(".CflareAccount",function(){ + describe(".listZones()",function(){ + it("should display an account",function(done){ + this.timeout(10000); + testCflareAccount.listZones() + .then((responseArg)=>{ + console.log(responseArg); + done(); + }) + }); + }); + describe(".getZoneId(domainName)",function(){ + it("should get an Cloudflare Id for a domain string",function(done){ + this.timeout(5000) + testCflareAccount.getZoneId("push.rocks") + .then((responseArg)=>{ + console.log(responseArg); + done(); + }); + }); + }); + describe(".listRecords(domainName)",function(){ + it("should list all records for a specific Domain Name",function(done){ + this.timeout(5000); + testCflareAccount.listRecords("push.rocks") + .then((responseArg) => { + console.log(responseArg); + done(); + }); + }); + }) + }) +}); diff --git a/ts/cflare.classes.cflareaccount.ts b/ts/cflare.classes.cflareaccount.ts index d992042..4ed5060 100644 --- a/ts/cflare.classes.cflareaccount.ts +++ b/ts/cflare.classes.cflareaccount.ts @@ -15,6 +15,32 @@ export class CflareAccount { this.authEmail = optionsArg.email; this.authKey = optionsArg.key; } + getZoneId(domainName:string){ + let done = plugins.q.defer(); + this.listZones(domainName) + .then((responseArg) => { + let filteredResponse = responseArg.result.filter((zoneArg)=>{ + return zoneArg.name === domainName; + }); + if (filteredResponse.length >= 1){ + done.resolve(filteredResponse[0].id); + } else { + plugins.beautylog.error("the domain " + domainName.blue + " does not appear to be in this account!"); + done.reject(undefined); + } + }); + return done.promise; + } + getRecord(domainNameArg:string,typeArg:string){ + let done = plugins.q.defer(); + this.listRecords(domainNameArg) + .then((responseArg) => { + let filteredResponse = responseArg.result.filter((recordArg) => { + return (recordArg.type == typeArg && recordArg.name == domainNameArg); + }) + }) + return done.promise; + }; createRecord(){ let done = plugins.q.defer(); return done.promise; @@ -23,20 +49,34 @@ export class CflareAccount { let done = plugins.q.defer(); return done.promise; }; + updateRecord(domainNameArg:string,typeArg:string,valueArg){ + let done = plugins.q.defer(); + return done.promise; + }; listRecords(domainName:string){ let done = plugins.q.defer(); - + this.getZoneId(domainName) + .then((domainIdArg)=>{ + this.request("GET","/zones/" + domainIdArg + "/dns_records?per_page=100") + .then(function(responseArg){ + done.resolve(responseArg); + }); + }); return done.promise; } - listDomains(){ + listZones(domainName?:string){ // TODO: handle pagination let done = plugins.q.defer(); - this.request("GET","/zones") + let requestRoute = "/zones?per_page=50" + if(domainName) requestRoute = requestRoute + "&name=" + domainName; + let result = {}; + this.request("GET",requestRoute) .then(function(responseArg){ - + result = responseArg; + done.resolve(result); }); return done.promise; }; - request(methodArg:string,routeArg:string){ + request(methodArg:string,routeArg:string,jsonArg?){ let done = plugins.q.defer(); let options = { method:methodArg, @@ -45,8 +85,9 @@ export class CflareAccount { "Content-Type":"application/json", "X-Auth-Email":this.authEmail, "X-Auth-Key":this.authKey - } - } + }, + json:jsonArg + }; plugins.request(options,function(err, res, body){ if (!err && res.statusCode == 200) { var responseObj = JSON.parse(body); diff --git a/ts/typings.json b/ts/typings.json index e66d896..8f505d5 100644 --- a/ts/typings.json +++ b/ts/typings.json @@ -3,6 +3,7 @@ "dependencies": {}, "ambientDependencies": { "colors": "registry:dt/colors#0.6.0-1+20160425153322", + "mocha": "registry:dt/mocha#2.2.5+20160317120654", "node": "registry:dt/node#4.0.0+20160423143914" } }