Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
feat(zone): add a zone
Browse files Browse the repository at this point in the history
  • Loading branch information
terinjokes committed May 9, 2016
1 parent 3beab80 commit 4b911d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ Saves the modifications to the `Zone` object.
properties at once. This method executes the modifications in series, but if an
error occurs, there are no guarantees which properties would have been applied.

#### `addZone(z, [jumpstart, [options]]): Promise<Zone>`

* z: `Zone` object
* jumpstart: `true` to automatically fetch existing DNS records
(default). `false` to disable this behavior.
* options: *see Request Options*
* *API Reference*: [Create a zone](https://api.cloudflare.com/#zone-create-a-zone)

Add a zone to an account or organization.

#### `deleteZone(z, [options]): Promise<{id: string}>`

* z: `Zone` object or string zone id
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = prototypal({
browseZones: zones.browse,
readZone: zones.read,
editZone: zones.edit,
addZone: zones.add,
deleteZone: zones.delete,
deleteCache: purge.delete,
browseDNS: dns.browse,
Expand Down
18 changes: 18 additions & 0 deletions lib/zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ function edit(z, options) {
return sendPatched.call(this);
}

function add(z, jumpstart, options) {
options = options || {};

var body = z.toJSON({useAliases: true});

if (jumpstart === false) {
body.jump_start = false; // eslint-disable-line camelcase
}

options.method = 'POST';
options.body = JSON.stringify(body);

return this._got('zones', options).then(function (response) {
return Zone.create(response.body.result);
});
}

function remove(z, options) {
var zid = Zone.is(z) ? z.id : z;
var uri = join('zones', zid);
Expand All @@ -130,5 +147,6 @@ function remove(z, options) {
module.exports.browse = browse;
module.exports.read = read;
module.exports.edit = edit;
module.exports.add = add;
module.exports.delete = remove;
module.exports.Zone = Zone;
22 changes: 22 additions & 0 deletions test/zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,25 @@ test('edit paused and vanity name servers', async t => {
t.true(zone.paused);
t.deepEqual(zone.vanityNameservers, ['ns1.example.com', 'ns2.example.com']);
});

test('add zone', async t => {
let z = Zone.create({
name: 'example.com'
});

nock('https://api.cloudflare.com')
.post('/client/v4/zones', {
name: 'example.com',
jump_start: false
})
.reply(200, {
result: {
id: '8',
name: 'example.com'
}
});

let zone = await t.context.cf.addZone(z, false);
t.true(Zone.is(zone));
t.true(zone.id === '8');
});

0 comments on commit 4b911d3

Please sign in to comment.