cloudflare/ts/cloudflare.classes.zonemanager.ts

33 lines
980 B
TypeScript
Raw Permalink Normal View History

2019-07-18 09:51:56 +00:00
import * as plugins from './cloudflare.plugins';
2020-02-28 14:24:36 +00:00
import * as interfaces from './interfaces';
2019-07-18 09:51:56 +00:00
import { CloudflareAccount } from './cloudflare.classes.account';
2020-02-28 14:24:36 +00:00
import { CloudflareZone } from './cloudflare.classes.zone';
2019-07-18 09:51:56 +00:00
export class ZoneManager {
2019-07-18 12:44:45 +00:00
public cfAccount: CloudflareAccount;
2019-07-18 09:51:56 +00:00
public zoneName: string;
constructor(cfAccountArg: CloudflareAccount) {
this.cfAccount = cfAccountArg;
}
2020-02-10 11:26:13 +00:00
2020-02-28 14:24:36 +00:00
public async getZones(zoneName: string) {
let requestRoute = `/zones?per_page=50`;
// may be optionally filtered by domain name
if (zoneName) {
requestRoute = `${requestRoute}&name=${zoneName}`;
}
const response: any = await this.cfAccount.request('GET', requestRoute);
const apiObjects: interfaces.ICflareZone[] = response.result;
const cloudflareZoneArray = [];
for (const apiObject of apiObjects) {
cloudflareZoneArray.push(CloudflareZone.createFromApiObject(apiObject));
}
return cloudflareZoneArray;
}
2019-07-18 09:51:56 +00:00
}