Merge pull request #93 from exportsmedia/feature-get-dns-record-id
Add get DNS record ID
This commit is contained in:
@@ -125,6 +125,15 @@ class DNS implements API
|
|||||||
return $this->body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
|
||||||
|
{
|
||||||
|
$records = $this->listRecords($zoneID, $type, $name);
|
||||||
|
if (isset($records->result{0}->id)) {
|
||||||
|
return $records->result{0}->id;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
|
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
|
||||||
|
|||||||
@@ -86,6 +86,25 @@ class DNSTest extends TestCase
|
|||||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetRecordID()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordId.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/dns_records')
|
||||||
|
);
|
||||||
|
|
||||||
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
|
$result = $dns->getRecordID('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com');
|
||||||
|
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpdateDNSRecord()
|
public function testUpdateDNSRecord()
|
||||||
{
|
{
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ class UARulesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20
|
'per_page' => 20
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
|
|||||||
29
tests/Fixtures/Endpoints/getRecordId.json
Normal file
29
tests/Fixtures/Endpoints/getRecordId.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
||||||
|
"type": "A",
|
||||||
|
"name": "example.com",
|
||||||
|
"content": "198.51.100.4",
|
||||||
|
"proxiable": true,
|
||||||
|
"proxied": false,
|
||||||
|
"ttl": {},
|
||||||
|
"locked": false,
|
||||||
|
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"zone_name": "example.com",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total_pages": 1,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user