Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zone edit method #225

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Endpoints/Zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,30 @@ public function deleteZone(string $identifier): bool

return false;
}

/**
* Edit zone
*/
public function editZone(string $zoneID, array $vanityNameServers = null, string $planId = null, string $type = null): \stdClass
{
$options = [];

if (!empty($vanityNameServers)) {
$options['vanity_name_servers'] = $vanityNameServers;
}

if (!empty($planId)) {
$plan = new \stdClass;
$plan->id = $planId;
$options['plan'] = $plan;
}

if (!empty($type)) {
$options['type'] = $type;
}

$user = $this->adapter->patch('zones/' . $zoneID, $options);
$this->body = json_decode($user->getBody());
return $this->body->result;
}
}
35 changes: 35 additions & 0 deletions tests/Endpoints/ZonesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,39 @@ public function testChangeDevelopmentMode()
$this->assertTrue($result);
$this->assertEquals('development_mode', $zones->getBody()->result->id);
}

public function testEditZone()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/editZone.json');

$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);

$zoneId = '023e105f4ecef8ad9ca31a8372d0c353';
$nameServers = ['tony.ns.cloudflare.com', 'woz.ns.cloudflare.com'];
$type = 'full';
$planId = 'e592fd9519420ba7405e1307bff33214';

$plan = new \stdClass;
$plan->id = $planId;

$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/' . $zoneId),
$this->equalTo([
'vanity_name_servers' => $nameServers,
'plan' => $plan,
'type' => $type
])
);

$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->editZone($zoneId, $nameServers, $planId, $type);

$this->assertObjectHasAttribute('id', $result);
$this->assertEquals($nameServers, $result->name_servers);
$this->assertEquals($planId, $result->plan->id);
$this->assertEquals($type, $result->type);
}
}
59 changes: 59 additions & 0 deletions tests/Fixtures/Endpoints/editZone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"name": "example.com",
"development_mode": 7200,
"original_name_servers": [
"ns1.originaldnshost.com",
"ns2.originaldnshost.com"
],
"original_registrar": "GoDaddy",
"original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"activated_on": "2014-01-02T00:01:00.12345Z",
"owner": {
"id": {},
"email": {},
"type": "user"
},
"account": {
"id": "01a7362d577a6c3019a474fd6f485823",
"name": "Demo Account"
},
"permissions": [
"#zone:read",
"#zone:edit"
],
"plan": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"plan_pending": {
"id": "e592fd9519420ba7405e1307bff33214",
"name": "Pro Plan",
"price": 20,
"currency": "USD",
"frequency": "monthly",
"legacy_id": "pro",
"is_subscribed": true,
"can_subscribe": true
},
"status": "active",
"paused": false,
"type": "full",
"name_servers": [
"tony.ns.cloudflare.com",
"woz.ns.cloudflare.com"
]
}
}