add functionality

This commit is contained in:
Philipp Kunz 2016-05-16 03:29:29 +02:00
parent b2182ec63d
commit f4c2bb6e5b
7 changed files with 166 additions and 16 deletions

View File

@ -7,9 +7,11 @@ export declare class CflareAccount {
email: string; email: string;
key: string; key: string;
}): void; }): void;
getZoneId(domainName: string): any;
createRecord(): any; createRecord(): any;
removeRecord(): any; removeRecord(): any;
updateRecord(): void;
listRecords(domainName: string): any; listRecords(domainName: string): any;
listDomains(): any; listZones(domainName?: string): any;
request(methodArg: string, routeArg: string): any; request(methodArg: string, routeArg: string, bodyArg?: any): any;
} }

File diff suppressed because one or more lines are too long

View File

@ -26,6 +26,7 @@
"request": "^2.72.0" "request": "^2.72.0"
}, },
"devDependencies": { "devDependencies": {
"npmts": "^5.1.5" "npmts": "^5.1.5",
"should": "^8.3.1"
} }
} }

View File

@ -1,11 +1,46 @@
"use strict"; "use strict";
/// <reference path="../ts/typings/main.d.ts" /> /// <reference path="../ts/typings/main.d.ts" />
var cflare = require("../dist/index"); var cflare = require("../dist/index");
var should = require("should");
var nogit = require("../nogit/nogit.json"); var nogit = require("../nogit/nogit.json");
var testCflareAccount = new cflare.CflareAccount(); var testCflareAccount = new cflare.CflareAccount();
testCflareAccount.auth({ testCflareAccount.auth({
email: nogit.cfemail, email: nogit.cfemail,
key: nogit.cfkey 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;char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Jcbn0pO1xyXG5cclxuZGVzY3JpYmUoXCJjZmxhcmVcIixmdW5jdGlvbigpe1xyXG4gICAgZGVzY3JpYmUoXCIuQ2ZsYXJlQWNjb3VudFwiLGZ1bmN0aW9uKCl7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIubGlzdFpvbmVzKClcIixmdW5jdGlvbigpe1xyXG4gICAgICAgICAgICBpdChcInNob3VsZCBkaXNwbGF5IGFuIGFjY291bnRcIixmdW5jdGlvbihkb25lKXtcclxuICAgICAgICAgICAgICAgIHRoaXMudGltZW91dCgxMDAwMCk7XHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5saXN0Wm9uZXMoKVxyXG4gICAgICAgICAgICAgICAgICAgIC50aGVuKChyZXNwb25zZUFyZyk9PntcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2VBcmcpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSlcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIuZ2V0Wm9uZUlkKGRvbWFpbk5hbWUpXCIsZnVuY3Rpb24oKXtcclxuICAgICAgICAgICAgaXQoXCJzaG91bGQgZ2V0IGFuIENsb3VkZmxhcmUgSWQgZm9yIGEgZG9tYWluIHN0cmluZ1wiLGZ1bmN0aW9uKGRvbmUpe1xyXG4gICAgICAgICAgICAgICAgdGhpcy50aW1lb3V0KDUwMDApXHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5nZXRab25lSWQoXCJwdXNoLnJvY2tzXCIpXHJcbiAgICAgICAgICAgICAgICAgICAgLnRoZW4oKHJlc3BvbnNlQXJnKT0+e1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXNwb25zZUFyZyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGRvbmUoKTtcclxuICAgICAgICAgICAgICAgICAgICB9KTtcclxuICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgfSk7XHJcbiAgICAgICAgZGVzY3JpYmUoXCIubGlzdFJlY29yZHMoZG9tYWluTmFtZSlcIixmdW5jdGlvbigpe1xyXG4gICAgICAgICAgICBpdChcInNob3VsZCBsaXN0IGFsbCByZWNvcmRzIGZvciBhIHNwZWNpZmljIERvbWFpbiBOYW1lXCIsZnVuY3Rpb24oZG9uZSl7XHJcbiAgICAgICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XHJcbiAgICAgICAgICAgICAgICB0ZXN0Q2ZsYXJlQWNjb3VudC5saXN0UmVjb3JkcyhcInB1c2gucm9ja3NcIilcclxuICAgICAgICAgICAgICAgICAgICAudGhlbigocmVzcG9uc2VBcmcpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2VBcmcpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkb25lKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH0pO1xyXG4gICAgICAgIH0pXHJcbiAgICB9KVxyXG59KTtcclxuIl19

View File

@ -1,5 +1,6 @@
/// <reference path="../ts/typings/main.d.ts" /> /// <reference path="../ts/typings/main.d.ts" />
import cflare = require("../dist/index"); import cflare = require("../dist/index");
let should = require("should");
let nogit = require("../nogit/nogit.json"); let nogit = require("../nogit/nogit.json");
let testCflareAccount = new cflare.CflareAccount(); let testCflareAccount = new cflare.CflareAccount();
@ -8,3 +9,37 @@ testCflareAccount.auth({
key: nogit.cfkey 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();
});
});
})
})
});

View File

@ -15,6 +15,32 @@ export class CflareAccount {
this.authEmail = optionsArg.email; this.authEmail = optionsArg.email;
this.authKey = optionsArg.key; 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(){ createRecord(){
let done = plugins.q.defer(); let done = plugins.q.defer();
return done.promise; return done.promise;
@ -23,20 +49,34 @@ export class CflareAccount {
let done = plugins.q.defer(); let done = plugins.q.defer();
return done.promise; return done.promise;
}; };
updateRecord(domainNameArg:string,typeArg:string,valueArg){
let done = plugins.q.defer();
return done.promise;
};
listRecords(domainName:string){ listRecords(domainName:string){
let done = plugins.q.defer(); 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; return done.promise;
} }
listDomains(){ listZones(domainName?:string){ // TODO: handle pagination
let done = plugins.q.defer(); 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){ .then(function(responseArg){
result = responseArg;
done.resolve(result);
}); });
return done.promise; return done.promise;
}; };
request(methodArg:string,routeArg:string){ request(methodArg:string,routeArg:string,jsonArg?){
let done = plugins.q.defer(); let done = plugins.q.defer();
let options = { let options = {
method:methodArg, method:methodArg,
@ -45,8 +85,9 @@ export class CflareAccount {
"Content-Type":"application/json", "Content-Type":"application/json",
"X-Auth-Email":this.authEmail, "X-Auth-Email":this.authEmail,
"X-Auth-Key":this.authKey "X-Auth-Key":this.authKey
} },
} json:jsonArg
};
plugins.request(options,function(err, res, body){ plugins.request(options,function(err, res, body){
if (!err && res.statusCode == 200) { if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body); var responseObj = JSON.parse(body);

View File

@ -3,6 +3,7 @@
"dependencies": {}, "dependencies": {},
"ambientDependencies": { "ambientDependencies": {
"colors": "registry:dt/colors#0.6.0-1+20160425153322", "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" "node": "registry:dt/node#4.0.0+20160423143914"
} }
} }