diff --git a/src/Endpoints/Accounts.php b/src/Endpoints/Accounts.php new file mode 100644 index 0000000..4d4d80a --- /dev/null +++ b/src/Endpoints/Accounts.php @@ -0,0 +1,75 @@ +adapter = $adapter; + } + + public function listAccounts( + int $page = 1, + int $perPage = 20, + string $direction = '' + ): \stdClass { + $query = [ + 'page' => $page, + 'per_page' => $perPage + ]; + + if (!empty($direction)) { + $query['direction'] = $direction; + } + + $user = $this->adapter->get('accounts', $query); + $this->body = json_decode($user->getBody()); + + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; + } + + public function getDomains(string $accountID): array + { + $response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains'); + + $this->body = json_decode($response->getBody()); + + return $this->body->result; + } + + public function getDomainDetails(string $accountID, string $domainName): \stdClass + { + $response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains/' . $domainName); + + $this->body = json_decode($response->getBody()); + + return $this->body->result; + } + + public function lockDomain(string $accountID, string $domainName): \stdClass + { + $response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => true]); + $this->body = json_decode($response->getBody()); + return $this->body; + } + + public function unlockDomain(string $accountID, string $domainName): \stdClass + { + $response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => false]); + $this->body = json_decode($response->getBody()); + return $this->body; + } +} diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index 03773c2..19390b1 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -58,6 +58,30 @@ class Zones implements API return false; } + public function pause(string $zoneID): bool + { + $user = $this->adapter->patch('zones/' . $zoneID, ['paused' => true]); + $this->body = json_decode($user->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + + public function unpause(string $zoneID): bool + { + $user = $this->adapter->patch('zones/' . $zoneID, ['paused' => false]); + $this->body = json_decode($user->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + public function getZoneById( string $zoneId ): \stdClass { diff --git a/tests/Endpoints/AccountsTest.php b/tests/Endpoints/AccountsTest.php new file mode 100644 index 0000000..db2b1be --- /dev/null +++ b/tests/Endpoints/AccountsTest.php @@ -0,0 +1,37 @@ +getPsr7JsonResponseForFixture('Endpoints/listAccounts.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('accounts'), + $this->equalTo([ + 'page' => 1, + 'per_page' => 20, + 'direction' => 'desc', + ]) + ); + + $accounts = new \Cloudflare\API\Endpoints\Accounts($mock); + $result = $accounts->listAccounts(1, 20, 'desc'); + + $this->assertObjectHasAttribute('result', $result); + $this->assertObjectHasAttribute('result_info', $result); + + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id); + $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id); + } +} diff --git a/tests/Fixtures/Endpoints/listAccounts.json b/tests/Fixtures/Endpoints/listAccounts.json new file mode 100644 index 0000000..0e6275a --- /dev/null +++ b/tests/Fixtures/Endpoints/listAccounts.json @@ -0,0 +1,20 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "023e105f4ecef8ad9ca31a8372d0c353", + "name": "Example Account", + "settings": { + "enforce_twofactor": true + } + } + ], + "result_info": { + "page": 1, + "per_page": 20, + "count": 1, + "total_count": 2000 + } +}