cloudflare/ts/cflare.classes.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-04-27 00:20:27 +00:00
/// <reference path="./typings/main.d.ts" />
import plugins = require("./cflare.plugins");
import helpers = require("./cflare.classes.helpers");
class cflare {
private authEmail:string;
private authKey:string;
2016-04-27 01:08:14 +00:00
private authCheck(){
return (this.authEmail && this.authKey); //check if auth is available
}
2016-04-27 00:20:27 +00:00
constructor(){
};
2016-04-27 01:08:14 +00:00
auth(optionsArg:{email:string,key:string}){
this.authEmail = optionsArg.email;
this.authKey = optionsArg.key;
}
createRecord(){
let done = plugins.q.defer();
return done.promise;
};
removeRecord(){
let done = plugins.q.defer();
return done.promise;
};
listRecords(domainName:string){
2016-04-27 01:08:14 +00:00
let done = plugins.q.defer();
2016-04-27 01:08:14 +00:00
return done.promise;
}
listDomains(){
let done = plugins.q.defer();
this.request("GET","/zones")
.then(function(responseArg){
});
2016-04-27 01:08:14 +00:00
return done.promise;
};
request(methodArg:string,routeArg:string){
2016-04-27 01:08:14 +00:00
let done = plugins.q.defer();
let options = {
method:methodArg,
url:"https://api.cloudflare.com/client/v4" + routeArg,
headers:{
"Content-Type":"application/json",
"X-Auth-Email":this.authEmail,
"X-Auth-Key":this.authKey
}
}
plugins.request(options,function(err, res, body){
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);
} else {
console.log(err);
console.log(res);
done.reject(err);
};
});
2016-04-27 01:08:14 +00:00
return done.promise;
}
2016-04-27 00:20:27 +00:00
};