From 5394ec3cc829b608b9a7e15af20a2d1c057af61f Mon Sep 17 00:00:00 2001 From: Phil Young Date: Tue, 15 Jun 2021 13:55:41 +0100 Subject: [PATCH] Add Cuystom Hostname Fallback Origin Retrieval I would like to surface this endpoint via the SDK --- src/Endpoints/CustomHostnames.php | 12 +++++++++++ tests/Endpoints/CustomHostnamesTest.php | 20 +++++++++++++++++++ .../getCustomHostnameFallbackOrigin.json | 18 +++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/Fixtures/Endpoints/getCustomHostnameFallbackOrigin.json diff --git a/src/Endpoints/CustomHostnames.php b/src/Endpoints/CustomHostnames.php index a7f09b0..ea0e6df 100644 --- a/src/Endpoints/CustomHostnames.php +++ b/src/Endpoints/CustomHostnames.php @@ -169,4 +169,16 @@ class CustomHostnames implements API $this->body = json_decode($zone->getBody()); return $this->body; } + + /** + * @param string $zoneID + * @return \stdClass + */ + public function getFallbackOrigin(string $zoneID): \stdClass + { + $zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/fallback_origin'); + $this->body = json_decode($zone->getBody()); + + return $this->body->result; + } } diff --git a/tests/Endpoints/CustomHostnamesTest.php b/tests/Endpoints/CustomHostnamesTest.php index 7298d86..f2cd2b0 100644 --- a/tests/Endpoints/CustomHostnamesTest.php +++ b/tests/Endpoints/CustomHostnamesTest.php @@ -158,4 +158,24 @@ class CustomHostnamesTest extends TestCase $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id); $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id); } + + public function testGetHostnameFallbackOrigin() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getCustomHostnameFallbackOrigin.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/fallback_origin') + ); + + $zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock); + $result = $zones->getFallbackOrigin('023e105f4ecef8ad9ca31a8372d0c353'); + + $this->assertObjectHasAttribute('origin', $result); + $this->assertObjectHasAttribute('status', $result); + } } diff --git a/tests/Fixtures/Endpoints/getCustomHostnameFallbackOrigin.json b/tests/Fixtures/Endpoints/getCustomHostnameFallbackOrigin.json new file mode 100644 index 0000000..66a9fac --- /dev/null +++ b/tests/Fixtures/Endpoints/getCustomHostnameFallbackOrigin.json @@ -0,0 +1,18 @@ +{ + "success": true, + "errors": [ + {} + ], + "messages": [ + {} + ], + "result": { + "origin": "fallback.example.com", + "status": "pending_deployment", + "errors": [ + "DNS records are not setup correctly. Origin should be a proxied A/AAAA/CNAME dns record" + ], + "created_at": "2019-10-28T18:11:23.37411Z", + "updated_at": "2020-03-16T18:11:23.531995Z" + } +}