Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/Endpoints/DNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public function getRecordDetails(string $zoneID, string $recordID): \stdClass
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)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider following code snippets:

Since the package requires php-7.0 version it can use this code:

return $records->result{0}->id ?? false;

return $records->result{0}->id;
}
return false;
}

public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
Expand Down
19 changes: 19 additions & 0 deletions tests/Endpoints/DNSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ public function testGetDNSRecordDetails()
$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()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
Expand Down
8 changes: 4 additions & 4 deletions tests/Endpoints/UARulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function testListRules()
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([
'page' => 1,
'per_page' => 20
])
$this->equalTo([
'page' => 1,
'per_page' => 20
])
);

$zones = new \Cloudflare\API\Endpoints\UARules($mock);
Expand Down
29 changes: 29 additions & 0 deletions tests/Fixtures/Endpoints/getRecordId.json
Original file line number Diff line number Diff line change
@@ -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
}
}