Skip to content

Commit

Permalink
Revert "Abstracts options calls into a setter function and adds tests."
Browse files Browse the repository at this point in the history
This reverts commit 3069a3f.
  • Loading branch information
typhonius committed Mar 4, 2020
1 parent 3069a3f commit 7283a72
Show file tree
Hide file tree
Showing 37 changed files with 247 additions and 433 deletions.
7 changes: 5 additions & 2 deletions src/Connector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ public static function factory(ConnectorInterface $connector)
/**
* @inheritdoc
*/
public function request(string $verb, string $path)
public function request(string $verb, string $path, array $options = [])
{
$options = $this->options;
// @TODO follow this up by removing $options from the parameters able
// to be passed into this function and instead solely relying on the
// addOption() method as this can then be tested.
$options = $this->options + $options;
$options['query'] = $this->query;

if (!empty($options['query']['filter']) && is_array($options['query']['filter'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Connector/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ interface ClientInterface
*
* @param string $verb
* @param string $path
* @param array $options
*
* @return mixed|StreamInterface
*/
public function request(string $verb, string $path);
public function request(string $verb, string $path, array $options = []);

/**
* @param string $verb
Expand Down
21 changes: 14 additions & 7 deletions src/Endpoints/Applications.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ public function get($applicationUuid)
public function rename($applicationUuid, $name)
{

$this->client->addOption('form_params', ['name' => $name]);
$options = [
'form_params' => [
'name' => $name,
],
];

return new OperationResponse(
$this->client->request(
'put',
"/applications/${applicationUuid}"
"/applications/${applicationUuid}",
$options
)
);
}
Expand Down Expand Up @@ -90,16 +95,18 @@ public function getAllTags($applicationUuid)
public function createTag($applicationUuid, $name, $color)
{

$params = [
'name' => $name,
'color' => $color,
$options = [
'form_params' => [
'name' => $name,
'color' => $color,
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request(
'post',
"/applications/${applicationUuid}/tags"
"/applications/${applicationUuid}/tags",
$options
)
);
}
Expand Down
21 changes: 14 additions & 7 deletions src/Endpoints/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ public function getAll($applicationUuid)
public function switch($environmentUuid, $branch)
{

$this->client->addOption('form_params', ['branch' => $branch]);
$options = [
'form_params' => [
'branch' => $branch,
],
];

return new OperationResponse(
$this->client->request(
'post',
"/environments/${environmentUuid}/code/actions/switch"
"/environments/${environmentUuid}/code/actions/switch",
$options
)
);
}
Expand All @@ -59,16 +64,18 @@ public function switch($environmentUuid, $branch)
public function deploy($environmentFromUuid, $environmentToUuid, $commitMessage = null)
{

$params = [
'source' => $environmentFromUuid,
'message' => $commitMessage,
$options = [
'form_params' => [
'source' => $environmentFromUuid,
'message' => $commitMessage,
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request(
'post',
"/environments/${environmentToUuid}/code"
"/environments/${environmentToUuid}/code",
$options
)
);
}
Expand Down
30 changes: 16 additions & 14 deletions src/Endpoints/Crons.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ public function get($environmentUuid, $cronId)
public function create($environmentUuid, $command, $frequency, $label, $serverId = null)
{

$params = [
'command' => $command,
'frequency' => $frequency,
'label' => $label,
'server_id' => $serverId
$options = [
'form_params' => [
'command' => $command,
'frequency' => $frequency,
'label' => $label,
'server_id' => $serverId
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request('post', "/environments/${environmentUuid}/crons")
$this->client->request('post', "/environments/${environmentUuid}/crons", $options)
);
}

Expand All @@ -87,16 +88,17 @@ public function create($environmentUuid, $command, $frequency, $label, $serverId
public function update($environmentUuid, $cronId, $command, $frequency, $label, $serverId = null)
{

$params = [
'command' => $command,
'frequency' => $frequency,
'label' => $label,
'server_id' => $serverId
$options = [
'form_params' => [
'command' => $command,
'frequency' => $frequency,
'label' => $label,
'server_id' => $serverId
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request('post', "/environments/${environmentUuid}/crons/${cronId}")
$this->client->request('post', "/environments/${environmentUuid}/crons/${cronId}", $options)
);
}

Expand Down
20 changes: 12 additions & 8 deletions src/Endpoints/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ public function getAll($applicationUuid)
*/
public function create($applicationUuid, $name)
{

$this->client->addOption('form_params', ['name' => $name]);
$options = [
'form_params' => [
'name' => $name,
],
];

return new OperationResponse(
$this->client->request('post', "/applications/${applicationUuid}/databases")
$this->client->request('post', "/applications/${applicationUuid}/databases", $options)
);
}

Expand Down Expand Up @@ -90,14 +93,15 @@ public function truncate($applicationUuid, $name)
*/
public function copy($environmentFromUuid, $dbName, $environmentToUuid)
{
$params = [
'name' => $dbName,
'source' => $environmentFromUuid,
$options = [
'form_params' => [
'name' => $dbName,
'source' => $environmentFromUuid,
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request('post', "/environments/${environmentToUuid}/databases")
$this->client->request('post', "/environments/${environmentToUuid}/databases", $options)
);
}
}
17 changes: 13 additions & 4 deletions src/Endpoints/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ public function get($environmentUuid, $domain)
public function create($environmentUuid, $hostname)
{

$this->client->addOption('form_params', ['hostname' => $hostname]);
$options = [
'form_params' => [
'hostname' => $hostname,
],
];

return new OperationResponse(
$this->client->request('post', "/environments/${environmentUuid}/domains")
$this->client->request('post', "/environments/${environmentUuid}/domains", $options)
);
}

Expand Down Expand Up @@ -89,12 +93,17 @@ public function delete($environmentUuid, $domain)
public function purge($environmentUuid, array $domains)
{

$this->client->addOption('form_params', ['domains' => $domains]);
$options = [
'form_params' => [
'domains' => $domains,
],
];

return new OperationResponse(
$this->client->request(
'post',
"/environments/${environmentUuid}/domains/actions/clear-varnish"
"/environments/${environmentUuid}/domains/actions/clear-varnish",
$options
)
);
}
Expand Down
48 changes: 33 additions & 15 deletions src/Endpoints/Environments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ class Environments extends CloudApiBase implements CloudApiInterface
*/
public function copyFiles($environmentUuidFrom, $environmentUuidTo)
{

$this->client->addOption('form_params', ['source' => $environmentUuidFrom]);
$options = [
'form_params' => [
'source' => $environmentUuidFrom,
],
];

return new OperationResponse(
$this->client->request('post', "/environments/${environmentUuidTo}/files")
$this->client->request('post', "/environments/${environmentUuidTo}/files", $options)
);
}

Expand Down Expand Up @@ -73,12 +76,15 @@ public function getAll($applicationUuid)
public function update($environmentUuid, array $config)
{

$this->client->addOption('form_params', $config);
$options = [
'form_params' => $config,
];

return new OperationResponse(
$this->client->request(
'put',
"/environments/${environmentUuid}"
"/environments/${environmentUuid}",
$options
)
);
}
Expand All @@ -93,12 +99,17 @@ public function update($environmentUuid, array $config)
public function rename($environmentUuid, $label)
{

$this->client->addOption('form_params', ['label' => $label]);
$options = [
'form_params' => [
'label' => $label,
],
];

return new OperationResponse(
$this->client->request(
'post',
"/environments/${environmentUuid}/actions/change-label"
"/environments/${environmentUuid}/actions/change-label",
$options
)
);
}
Expand All @@ -125,12 +136,17 @@ public function enableLiveDev($environmentUuid)
public function disableLiveDev($environmentUuid)
{

$this->client->addOption('form_params', ['discard' => 1]);
$options = [
'form_params' => [
'discard' => 1,
],
];

return new OperationResponse(
$this->client->request(
'post',
"/environments/${environmentUuid}/livedev/actions/disable"
"/environments/${environmentUuid}/livedev/actions/disable",
$options
)
);
}
Expand Down Expand Up @@ -178,17 +194,19 @@ public function disableProductionMode($environmentUuid)
*/
public function create($applicationUuid, $label, $branch, array $databases)
{
$params = [
'label' => $label,
'branch' => $branch,
'databases' => $databases,
$options = [
'form_params' => [
'label' => $label,
'branch' => $branch,
'databases' => $databases,
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request(
'post',
"/applications/${applicationUuid}/environments"
"/applications/${applicationUuid}/environments",
$options
)
);
}
Expand Down
16 changes: 9 additions & 7 deletions src/Endpoints/IdentityProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ public function enable($idpUuid)
public function update($idpUuid, $label, $entityId, $ssoUrl, $certificate)
{

$params = [
'label' => $label,
'entity_id' => $entityId,
'sso_url' => $ssoUrl,
'certificate' => $certificate,
$options = [
'form_params' => [
'label' => $label,
'entity_id' => $entityId,
'sso_url' => $ssoUrl,
'certificate' => $certificate,
],
];
$this->client->addOption('form_params', $params);

return new OperationResponse(
$this->client->request(
'put',
"/identity-providers/${idpUuid}"
"/identity-providers/${idpUuid}",
$options
)
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Endpoints/Ides.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ public function get($ideUuid)
public function create($applicationUuid, $name)
{

$this->client->addOption('form_params', ['name' => $name]);
$options = [
'form_params' => [
'name' => $name,
],
];

return new OperationResponse(
$this->client->request('post', "/applications/${applicationUuid}/ides")
$this->client->request('post', "/applications/${applicationUuid}/ides", $options)
);
}

Expand Down
Loading

0 comments on commit 7283a72

Please sign in to comment.