Zones endpoints.
This commit is contained in:
159
.idea/workspace.xml
generated
159
.idea/workspace.xml
generated
@@ -2,18 +2,9 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c4689db7-00da-4fe5-bfe8-a51d28f5f0b5" name="Default" comment="">
|
||||
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Endpoints/EndpointException.php" />
|
||||
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/Endpoints/Zones.php" />
|
||||
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/tests/Endpoints/ZonesTest.php" />
|
||||
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/cloudflare-php.iml" afterPath="$PROJECT_DIR$/.idea/cloudflare-php.iml" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/php.xml" afterPath="$PROJECT_DIR$/.idea/php.xml" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Adapter/Guzzle.php" afterPath="$PROJECT_DIR$/src/Adapter/Guzzle.php" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Endpoints/User.php" afterPath="$PROJECT_DIR$/src/Endpoints/User.php" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Adapter/GuzzleTest.php" afterPath="$PROJECT_DIR$/tests/Adapter/GuzzleTest.php" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Endpoints/UserTest.php" afterPath="$PROJECT_DIR$/tests/Endpoints/UserTest.php" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Endpoints/Zones.php" afterPath="$PROJECT_DIR$/src/Endpoints/Zones.php" />
|
||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Endpoints/ZonesTest.php" afterPath="$PROJECT_DIR$/tests/Endpoints/ZonesTest.php" />
|
||||
</list>
|
||||
<ignored path="cloudflare-php.iws" />
|
||||
<ignored path=".idea/workspace.xml" />
|
||||
@@ -33,7 +24,60 @@
|
||||
<favorites_list name="cloudflare-php" />
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300" />
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file leaf-file-name="UserTest.php" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/tests/Endpoints/UserTest.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="835">
|
||||
<caret line="131" column="0" lean-forward="false" selection-start-line="131" selection-start-column="0" selection-end-line="131" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="ZonesTest.php" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/tests/Endpoints/ZonesTest.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="779">
|
||||
<caret line="333" column="35" lean-forward="false" selection-start-line="333" selection-start-column="35" selection-end-line="333" selection-end-column="35" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="Zones.php" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/Endpoints/Zones.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="111" column="36" lean-forward="false" selection-start-line="111" selection-start-column="36" selection-end-line="111" selection-end-column="36" />
|
||||
<folding>
|
||||
<element signature="e#127#162#0#PHP" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="Guzzle.php" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Guzzle.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="482">
|
||||
<caret line="98" column="5" lean-forward="true" selection-start-line="98" selection-start-column="5" selection-end-line="98" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="Adapter.php" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Adapter.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="879">
|
||||
<caret line="73" column="20" lean-forward="false" selection-start-line="73" selection-start-column="20" selection-end-line="73" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FindInProjectRecents">
|
||||
<findStrings>
|
||||
@@ -73,10 +117,10 @@
|
||||
<option value="$PROJECT_DIR$/src/Endpoints/EndpointException.php" />
|
||||
<option value="$PROJECT_DIR$/src/Endpoints/User.php" />
|
||||
<option value="$PROJECT_DIR$/tests/Adapter/GuzzleTest.php" />
|
||||
<option value="$PROJECT_DIR$/src/Adapter/Guzzle.php" />
|
||||
<option value="$PROJECT_DIR$/tests/Endpoints/UserTest.php" />
|
||||
<option value="$PROJECT_DIR$/tests/Endpoints/ZonesTest.php" />
|
||||
<option value="$PROJECT_DIR$/src/Endpoints/Zones.php" />
|
||||
<option value="$PROJECT_DIR$/src/Adapter/Guzzle.php" />
|
||||
<option value="$PROJECT_DIR$/tests/Endpoints/ZonesTest.php" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -86,6 +130,9 @@
|
||||
<detection-done>true</detection-done>
|
||||
<sorting>DEFINITION_ORDER</sorting>
|
||||
</component>
|
||||
<component name="PhpServers">
|
||||
<servers />
|
||||
</component>
|
||||
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" interpreter_name="PHP 7.1">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
|
||||
@@ -273,7 +320,7 @@
|
||||
<component name="PropertiesComponent">
|
||||
<property name="last_opened_file_path" value="/usr/local/Cellar/php71/7.1.0-beta.1_2/bin/php" />
|
||||
<property name="nodejs_interpreter_path" value="/usr/local/bin/node" />
|
||||
<property name="settings.editor.selected.configurable" value="reference.webide.settings.project.settings.php" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.sourceCode.PHP" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="js-jscs-nodeInterpreter" value="/usr/local/bin/node" />
|
||||
<property name="php.override.implement.member.chooser.php.doc" value="INHERIT" />
|
||||
@@ -387,7 +434,7 @@
|
||||
<workItem from="1494067284208" duration="783000" />
|
||||
<workItem from="1494118037959" duration="133000" />
|
||||
<workItem from="1494733352913" duration="14000" />
|
||||
<workItem from="1496751055934" duration="9942000" />
|
||||
<workItem from="1496751055934" duration="18854000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Initial commit, WIP.">
|
||||
<created>1484351548066</created>
|
||||
@@ -400,12 +447,13 @@
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="46702000" />
|
||||
<option name="totallyTimeSpent" value="55614000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="0" y="0" width="1920" height="1080" extended-state="0" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24427083" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24427083" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
|
||||
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||
@@ -562,7 +610,6 @@
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/vendor/phpunit/phpunit/src/Framework/TestCase.php" />
|
||||
<entry file="file://$PROJECT_DIR$/vendor/phpunit/phpunit/src/Framework/Assert.php" />
|
||||
<entry file="file://$PROJECT_DIR$/vendor/guzzlehttp/guzzle/src/Client.php" />
|
||||
<entry file="file://$PROJECT_DIR$/src/API.php" />
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Response.php" />
|
||||
@@ -686,14 +733,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Guzzle.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="834">
|
||||
<caret line="123" column="54" lean-forward="true" selection-start-line="123" selection-start-column="54" selection-end-line="123" selection-end-column="54" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/JSONException.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
@@ -734,14 +773,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Adapter.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="498">
|
||||
<caret line="46" column="20" lean-forward="false" selection-start-line="46" selection-start-column="20" selection-end-line="46" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="jar://$APPLICATION_HOME_DIR$/plugins/php/lib/php.jar!/stubs/standard/_types.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="390">
|
||||
@@ -750,34 +781,60 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Endpoints/Zones.php">
|
||||
<entry file="file://$PROJECT_DIR$/src/Endpoints/User.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="650">
|
||||
<caret line="31" column="53" lean-forward="false" selection-start-line="31" selection-start-column="53" selection-end-line="31" selection-end-column="53" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/tests/Endpoints/ZonesTest.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1365">
|
||||
<caret line="96" column="92" lean-forward="false" selection-start-line="96" selection-start-column="92" selection-end-line="96" selection-end-column="92" />
|
||||
<state relative-caret-position="585">
|
||||
<caret line="32" column="0" lean-forward="false" selection-start-line="32" selection-start-column="0" selection-end-line="32" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/tests/Endpoints/UserTest.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="774">
|
||||
<caret line="128" column="8" lean-forward="true" selection-start-line="128" selection-start-column="8" selection-end-line="130" selection-end-column="113" />
|
||||
<state relative-caret-position="835">
|
||||
<caret line="131" column="0" lean-forward="false" selection-start-line="131" selection-start-column="0" selection-end-line="131" selection-end-column="0" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Endpoints/User.php">
|
||||
<entry file="file://$PROJECT_DIR$/vendor/phpunit/phpunit/src/Framework/Assert.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="606">
|
||||
<caret line="32" column="0" lean-forward="true" selection-start-line="32" selection-start-column="0" selection-end-line="32" selection-end-column="0" />
|
||||
<state relative-caret-position="336">
|
||||
<caret line="502" column="27" lean-forward="false" selection-start-line="502" selection-start-column="27" selection-end-line="502" selection-end-column="27" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Endpoints/Zones.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="111" column="36" lean-forward="false" selection-start-line="111" selection-start-column="36" selection-end-line="111" selection-end-column="36" />
|
||||
<folding>
|
||||
<element signature="e#127#162#0#PHP" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Adapter.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="879">
|
||||
<caret line="73" column="20" lean-forward="false" selection-start-line="73" selection-start-column="20" selection-end-line="73" selection-end-column="20" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/Adapter/Guzzle.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="482">
|
||||
<caret line="98" column="5" lean-forward="true" selection-start-line="98" selection-start-column="5" selection-end-line="98" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/tests/Endpoints/ZonesTest.php">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="779">
|
||||
<caret line="333" column="35" lean-forward="false" selection-start-line="333" selection-start-column="35" selection-end-line="333" selection-end-column="35" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
|
||||
class Zones implements API
|
||||
{
|
||||
@@ -22,7 +23,7 @@ class Zones implements API
|
||||
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
|
||||
{
|
||||
$options = [
|
||||
'name' => $name,
|
||||
'name' => $name,
|
||||
'jumpstart' => $jumpstart
|
||||
];
|
||||
|
||||
@@ -36,4 +37,108 @@ class Zones implements API
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
}
|
||||
|
||||
public function activationCheck(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function listZones(
|
||||
string $name = "",
|
||||
string $status = "",
|
||||
int $page = 1,
|
||||
int $perPage = 20,
|
||||
string $order = "",
|
||||
string $direction = "",
|
||||
string $match = "all"
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage,
|
||||
'match' => $match
|
||||
];
|
||||
|
||||
if (!empty($name)) {
|
||||
$options['name'] = $name;
|
||||
}
|
||||
|
||||
if (!empty($status)) {
|
||||
$options['status'] = $status;
|
||||
}
|
||||
|
||||
if (!empty($order)) {
|
||||
$options['order'] = $order;
|
||||
}
|
||||
|
||||
if (!empty($direction)) {
|
||||
$options['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('zones', [], $options);
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->result = $body->result;
|
||||
$result->result_info = $body->result_info;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getZoneID(string $name = ""): string
|
||||
{
|
||||
$zones = $this->listZones($name);
|
||||
|
||||
if (sizeof($zones) < 1) {
|
||||
throw new EndpointException("Could not find zones with specified name.");
|
||||
}
|
||||
|
||||
return $zones->result[0]->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge Everything
|
||||
* @param string $zoneID
|
||||
* @return bool
|
||||
*/
|
||||
public function purgeAll(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function purge(string $zoneID, array $files = [], array $tags = []): bool
|
||||
{
|
||||
if (empty($files) && empty($tags)) {
|
||||
throw new Exception("No files or tags to purge.");
|
||||
}
|
||||
|
||||
$options = [
|
||||
'files' => $files,
|
||||
'tags' => $tags
|
||||
];
|
||||
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -100,4 +100,237 @@ class ZonesTest extends PHPUnit_Framework_TestCase
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823");
|
||||
}
|
||||
|
||||
public function testActivationTest()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('put')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('put')
|
||||
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testListZones()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "example.com",
|
||||
"development_mode": 7200,
|
||||
"original_name_servers": [
|
||||
"ns1.originaldnshost.com",
|
||||
"ns2.originaldnshost.com"
|
||||
],
|
||||
"original_registrar": "GoDaddy",
|
||||
"original_dnshost": "NameCheap",
|
||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||
"name_servers": [
|
||||
"tony.ns.cloudflare.com",
|
||||
"woz.ns.cloudflare.com"
|
||||
],
|
||||
"owner": {
|
||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||
"email": "user@example.com",
|
||||
"owner_type": "user"
|
||||
},
|
||||
"permissions": [
|
||||
"#zone:read",
|
||||
"#zone:edit"
|
||||
],
|
||||
"plan": {
|
||||
"id": "e592fd9519420ba7405e1307bff33214",
|
||||
"name": "Pro Plan",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"frequency": "monthly",
|
||||
"legacy_id": "pro",
|
||||
"is_subscribed": true,
|
||||
"can_subscribe": true
|
||||
},
|
||||
"plan_pending": {
|
||||
"id": "e592fd9519420ba7405e1307bff33214",
|
||||
"name": "Pro Plan",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"frequency": "monthly",
|
||||
"legacy_id": "pro",
|
||||
"is_subscribed": true,
|
||||
"can_subscribe": true
|
||||
},
|
||||
"status": "active",
|
||||
"paused": false,
|
||||
"type": "full"
|
||||
}
|
||||
],
|
||||
"result_info": {
|
||||
"page": 1,
|
||||
"per_page": 20,
|
||||
"count": 1,
|
||||
"total_count": 2000
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('zones'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'name' => 'example.com',
|
||||
'status' => 'active',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc'
|
||||
]
|
||||
));
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
|
||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
}
|
||||
|
||||
public function testGetZoneID()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "example.com",
|
||||
"development_mode": 7200,
|
||||
"original_name_servers": [
|
||||
"ns1.originaldnshost.com",
|
||||
"ns2.originaldnshost.com"
|
||||
],
|
||||
"original_registrar": "GoDaddy",
|
||||
"original_dnshost": "NameCheap",
|
||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||
"name_servers": [
|
||||
"tony.ns.cloudflare.com",
|
||||
"woz.ns.cloudflare.com"
|
||||
],
|
||||
"owner": {
|
||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||
"email": "user@example.com",
|
||||
"owner_type": "user"
|
||||
},
|
||||
"permissions": [
|
||||
"#zone:read",
|
||||
"#zone:edit"
|
||||
],
|
||||
"plan": {
|
||||
"id": "e592fd9519420ba7405e1307bff33214",
|
||||
"name": "Pro Plan",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"frequency": "monthly",
|
||||
"legacy_id": "pro",
|
||||
"is_subscribed": true,
|
||||
"can_subscribe": true
|
||||
},
|
||||
"plan_pending": {
|
||||
"id": "e592fd9519420ba7405e1307bff33214",
|
||||
"name": "Pro Plan",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"frequency": "monthly",
|
||||
"legacy_id": "pro",
|
||||
"is_subscribed": true,
|
||||
"can_subscribe": true
|
||||
},
|
||||
"status": "active",
|
||||
"paused": false,
|
||||
"type": "full"
|
||||
}
|
||||
],
|
||||
"result_info": {
|
||||
"page": 1,
|
||||
"per_page": 20,
|
||||
"count": 1,
|
||||
"total_count": 2000
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('zones'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'name' => 'example.com',
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all'
|
||||
]
|
||||
));
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->getZoneID("example.com");
|
||||
|
||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
|
||||
}
|
||||
|
||||
public function testPurgeAll()
|
||||
{
|
||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with($this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo(["purge_everything" => true])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->purgeAll("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user