implemented .createRecord

This commit is contained in:
Philipp Kunz 2016-05-24 23:36:06 +02:00
parent f4d4bc238b
commit 0ed9c7f4f4
16 changed files with 102 additions and 36 deletions

View File

@ -1,3 +1,4 @@
import "typings-global";
export declare class CflareAccount {
private authEmail;
private authKey;
@ -9,10 +10,10 @@ export declare class CflareAccount {
}): void;
getZoneId(domainName: string): any;
getRecord(domainNameArg: string, typeArg: string): any;
createRecord(): any;
createRecord(domainNameArg: string, typeArg: string, contentArg: string): any;
removeRecord(): any;
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): any;
listRecords(domainName: string): any;
listRecords(domainNameArg: string): any;
listZones(domainName?: string): any;
request(methodArg: string, routeArg: string, jsonArg?: any): any;
request(methodArg: string, routeArg: string, dataArg?: {}): any;
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
import "typings-global";

View File

@ -1,3 +1,4 @@
"use strict";
require("typings-global");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOltdfQ==
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSIsImZpbGUiOiJjZmxhcmUuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcclxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9jZmxhcmUucGx1Z2luc1wiKTsiXX0=

View File

@ -1,3 +1,4 @@
import "typings-global";
export declare let beautylog: any;
export declare let q: any;
export declare let request: any;

View File

@ -1,7 +1,7 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
require("typings-global");
exports.beautylog = require("beautylog");
exports.q = require("q");
exports.request = require("request");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDIiwiZmlsZSI6ImNmbGFyZS5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxyXG5leHBvcnQgbGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XHJcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xyXG5leHBvcnQgbGV0IHJlcXVlc3QgPSByZXF1aXJlKFwicmVxdWVzdFwiKTsiXX0=
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMiLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiO1xyXG5leHBvcnQgbGV0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XHJcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xyXG5leHBvcnQgbGV0IHJlcXVlc3QgPSByZXF1aXJlKFwicmVxdWVzdFwiKTsiXX0=

1
dist/index.d.ts vendored
View File

@ -1 +1,2 @@
import "typings-global";
export { CflareAccount } from "./cflare.classes.cflareaccount";

4
dist/index.js vendored
View File

@ -1,6 +1,6 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
require("typings-global");
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDNUMsNkNBQTRCLGdDQUFnQyxDQUFDO0FBQXJELHFFQUFxRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cclxuZXhwb3J0IHtDZmxhcmVBY2NvdW50fSBmcm9tIFwiLi9jZmxhcmUuY2xhc3Nlcy5jZmxhcmVhY2NvdW50XCI7Il19
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsNkNBQTRCLGdDQUFnQyxDQUFDO0FBQXJELHFFQUFxRCIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XHJcbmV4cG9ydCB7Q2ZsYXJlQWNjb3VudH0gZnJvbSBcIi4vY2ZsYXJlLmNsYXNzZXMuY2ZsYXJlYWNjb3VudFwiOyJdfQ==

View File

@ -21,12 +21,14 @@
},
"homepage": "https://github.com/pushrocks/cflare#readme",
"dependencies": {
"beautylog": "^5.0.0",
"beautylog": "^5.0.6",
"q": "^1.4.1",
"request": "^2.72.0"
"request": "^2.72.0",
"typings-global": "^1.0.3"
},
"devDependencies": {
"npmts": "^5.1.5",
"should": "^8.3.1"
"npmts": "^5.1.13",
"should": "^8.4.0",
"typings-test": "^1.0.1"
}
}

1
test/test.d.ts vendored
View File

@ -0,0 +1 @@
import "typings-test";

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/// <reference path="../ts/typings/main.d.ts" />
import "typings-test";
import cflare = require("../dist/index");
let should = require("should");
let nogit = require("../nogit/nogit.json");
@ -23,7 +23,7 @@ describe("cflare",function(){
});
describe(".getZoneId(domainName)",function(){
it("should get an Cloudflare Id for a domain string",function(done){
this.timeout(5000)
this.timeout(10000)
testCflareAccount.getZoneId("push.rocks")
.then((responseArg)=>{
console.log(responseArg);
@ -33,7 +33,7 @@ describe("cflare",function(){
});
describe(".listRecords(domainName)",function(){
it("should list all records for a specific Domain Name",function(done){
this.timeout(5000);
this.timeout(10000);
testCflareAccount.listRecords("push.rocks")
.then((responseArg) => {
console.log(responseArg);
@ -41,5 +41,24 @@ describe("cflare",function(){
});
});
})
describe(".createRecord",function(){
this.timeout(10000);
it("should create a valid record for a domain",function(done){
testCflareAccount.createRecord("bleu.de","A","127.0.0.1")
.then(function(responseArg){
console.log(responseArg);
done();
});
});
});
describe(".removeRecord",function(){
it("should remove a record from Cloudflare",function(done){
testCflareAccount.removeRecord()
.then(function(responseArg){
console.log(responseArg);
done();
})
});
});
})
});

View File

@ -1,4 +1,4 @@
/// <reference path="./typings/main.d.ts" />
import "typings-global";
import plugins = require("./cflare.plugins");
import helpers = require("./cflare.classes.helpers");
@ -41,21 +41,34 @@ export class CflareAccount {
})
return done.promise;
};
createRecord(){
createRecord(domainNameArg:string,typeArg:string,contentArg:string){
let done = plugins.q.defer();
this.getZoneId(domainNameArg)
.then((domainIdArg)=>{
let dataObject = {
name: domainNameArg,
type: typeArg,
content: contentArg
};
this.request("POST","/zones/" + domainIdArg + "/dns_records",dataObject)
.then(function(responseArg){
done.resolve(responseArg);
});
});
return done.promise;
};
removeRecord(){
removeRecord(domainNameArg:string,typeArg:string){
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){
listRecords(domainNameArg:string){
let done = plugins.q.defer();
this.getZoneId(domainName)
this.getZoneId(domainNameArg)
.then((domainIdArg)=>{
this.request("GET","/zones/" + domainIdArg + "/dns_records?per_page=100")
.then(function(responseArg){
@ -76,8 +89,9 @@ export class CflareAccount {
});
return done.promise;
};
request(methodArg:string,routeArg:string,jsonArg?){
request(methodArg:string,routeArg:string,dataArg = {}){
let done = plugins.q.defer();
let jsonArg:string = JSON.stringify(dataArg);
let options = {
method:methodArg,
url:"https://api.cloudflare.com/client/v4" + routeArg,
@ -86,7 +100,7 @@ export class CflareAccount {
"X-Auth-Email":this.authEmail,
"X-Auth-Key":this.authKey
},
json:jsonArg
body:jsonArg
};
plugins.request(options,function(err, res, body){
if (!err && res.statusCode == 200) {

View File

@ -1,2 +1,2 @@
/// <reference path="./typings/main.d.ts" />
import "typings-global";
import plugins = require("./cflare.plugins");

View File

@ -1,4 +1,4 @@
/// <reference path="./typings/main.d.ts" />
import "typings-global";
export let beautylog = require("beautylog");
export let q = require("q");
export let request = require("request");

View File

@ -1,2 +1,2 @@
/// <reference path="./typings/main.d.ts" />
import "typings-global";
export {CflareAccount} from "./cflare.classes.cflareaccount";