Skip to content

Commit 2030e29

Browse files
authored
Merge pull request cloudflare#182 from phily245/181-add-support-for-custom-hostname-fallback-origin-retrieval
Add Custom Hostname Fallback Origin Retrieval
2 parents 1e58a65 + 5394ec3 commit 2030e29

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/Endpoints/CustomHostnames.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,16 @@ public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
169169
$this->body = json_decode($zone->getBody());
170170
return $this->body;
171171
}
172+
173+
/**
174+
* @param string $zoneID
175+
* @return \stdClass
176+
*/
177+
public function getFallbackOrigin(string $zoneID): \stdClass
178+
{
179+
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/fallback_origin');
180+
$this->body = json_decode($zone->getBody());
181+
182+
return $this->body->result;
183+
}
172184
}

tests/Endpoints/CustomHostnamesTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,24 @@ public function testDeleteHostname()
158158
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
159159
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id);
160160
}
161+
162+
public function testGetHostnameFallbackOrigin()
163+
{
164+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCustomHostnameFallbackOrigin.json');
165+
166+
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
167+
$mock->method('get')->willReturn($response);
168+
169+
$mock->expects($this->once())
170+
->method('get')
171+
->with(
172+
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/fallback_origin')
173+
);
174+
175+
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
176+
$result = $zones->getFallbackOrigin('023e105f4ecef8ad9ca31a8372d0c353');
177+
178+
$this->assertObjectHasAttribute('origin', $result);
179+
$this->assertObjectHasAttribute('status', $result);
180+
}
161181
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"success": true,
3+
"errors": [
4+
{}
5+
],
6+
"messages": [
7+
{}
8+
],
9+
"result": {
10+
"origin": "fallback.example.com",
11+
"status": "pending_deployment",
12+
"errors": [
13+
"DNS records are not setup correctly. Origin should be a proxied A/AAAA/CNAME dns record"
14+
],
15+
"created_at": "2019-10-28T18:11:23.37411Z",
16+
"updated_at": "2020-03-16T18:11:23.531995Z"
17+
}
18+
}

0 commit comments

Comments
 (0)