Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Rename API invocation methods to explicitly include API
Browse files Browse the repository at this point in the history
Separate API invocations more clearly from possible other invocations. Refs #22
  • Loading branch information
curry684 committed Jan 15, 2017
1 parent 6893cba commit 9e90488
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/DirectAdmin/Context/AdminContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function createReseller($username, $password, $email, $domain, $package =
*/
public function getAdmins()
{
return BaseObject::toObjectArray($this->invokeGet('SHOW_ADMINS'), Admin::class, $this);
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ADMINS'), Admin::class, $this);
}

/**
Expand All @@ -85,7 +85,7 @@ public function getAllAccounts()
*/
public function getAllUsers()
{
return BaseObject::toObjectArray($this->invokeGet('SHOW_ALL_USERS'), User::class, $this);
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_ALL_USERS'), User::class, $this);
}

/**
Expand All @@ -107,7 +107,7 @@ public function getReseller($username)
*/
public function getResellers()
{
return BaseObject::toObjectArray($this->invokeGet('SHOW_RESELLERS'), Reseller::class, $this);
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_RESELLERS'), Reseller::class, $this);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/DirectAdmin/Context/BaseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ protected function getConnection()
* @param array $query Optional query parameters
* @return array The parsed and validated response
*/
public function invokeGet($command, $query = [])
public function invokeApiGet($command, $query = [])
{
return $this->connection->invoke('GET', $command, ['query' => $query]);
return $this->connection->invokeApi('GET', $command, ['query' => $query]);
}

/**
Expand All @@ -61,8 +61,8 @@ public function invokeGet($command, $query = [])
* @param array $postParameters Optional form parameters
* @return array The parsed and validated response
*/
public function invokePost($command, $postParameters = [])
public function invokeApiPost($command, $postParameters = [])
{
return $this->connection->invoke('POST', $command, ['form_params' => $postParameters]);
return $this->connection->invokeApi('POST', $command, ['form_params' => $postParameters]);
}
}
10 changes: 5 additions & 5 deletions src/DirectAdmin/Context/ResellerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function createUser($username, $password, $email, $domain, $ip, $package
*/
protected function createAccount($username, $password, $email, $options, $endpoint, $returnType)
{
$this->invokePost($endpoint, array_merge($options, [
$this->invokeApiPost($endpoint, array_merge($options, [
'action' => 'create',
'add' => 'Submit',
'email' => $email,
Expand Down Expand Up @@ -86,7 +86,7 @@ public function deleteAccounts(array $usernames)
foreach (array_values($usernames) as $idx => $username) {
$options["select{$idx}"] = $username;
}
$this->invokePost('SELECT_USERS', $options);
$this->invokeApiPost('SELECT_USERS', $options);
}

/**
Expand Down Expand Up @@ -121,7 +121,7 @@ public function suspendAccounts(array $usernames, $suspend = true)
foreach (array_values($usernames) as $idx => $username) {
$options['select' . $idx] = $username;
}
$this->invokePost('SELECT_USERS', $options);
$this->invokeApiPost('SELECT_USERS', $options);
}

/**
Expand All @@ -141,7 +141,7 @@ public function unsuspendAccounts(array $usernames)
*/
public function getIPs()
{
return $this->invokeGet('SHOW_RESELLER_IPS');
return $this->invokeApiGet('SHOW_RESELLER_IPS');
}

/**
Expand All @@ -163,7 +163,7 @@ public function getUser($username)
*/
public function getUsers()
{
return BaseObject::toObjectArray($this->invokeGet('SHOW_USERS'), User::class, $this);
return BaseObject::toObjectArray($this->invokeApiGet('SHOW_USERS'), User::class, $this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DirectAdmin/Context/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getType()
public function getContextUser()
{
if (!isset($this->user)) {
$this->user = User::fromConfig($this->invokeGet('SHOW_USER_CONFIG'), $this);
$this->user = User::fromConfig($this->invokeApiGet('SHOW_USER_CONFIG'), $this);
}
return $this->user;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DirectAdmin/DirectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getUsername()
* @return array The unvalidated response
* @throws DirectAdminException If anything went wrong on the network level
*/
public function invoke($method, $command, $options = [])
public function invokeApi($method, $command, $options = [])
{
$result = $this->rawRequest($method, '/CMD_API_' . $command, $options);
if (!empty($result['error'])) {
Expand Down
6 changes: 3 additions & 3 deletions src/DirectAdmin/Objects/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function create(User $user, $name, $username, $password)
} else {
$options += ['userlist' => $username];
}
$user->getContext()->invokePost('DATABASES', $options);
$user->getContext()->invokeApiPost('DATABASES', $options);
return new self($name, $user, $user->getContext());
}

Expand All @@ -71,7 +71,7 @@ public static function create(User $user, $name, $username, $password)
*/
public function delete()
{
$this->getContext()->invokePost('DATABASES', [
$this->getContext()->invokeApiPost('DATABASES', [
'action' => 'delete',
'select0' => $this->getDatabaseName(),
]);
Expand All @@ -84,7 +84,7 @@ public function delete()
public function getAccessHosts()
{
return $this->getCache(self::CACHE_ACCESS_HOSTS, function () {
$accessHosts = $this->getContext()->invokeGet('DATABASES', [
$accessHosts = $this->getContext()->invokeApiGet('DATABASES', [
'action' => 'accesshosts',
'db' => $this->getDatabaseName(),
]);
Expand Down
4 changes: 2 additions & 2 deletions src/DirectAdmin/Objects/Database/AccessHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($host, Database $database)
*/
public static function create(Database $database, $host)
{
$database->getContext()->invokePost('DATABASES', [
$database->getContext()->invokeApiPost('DATABASES', [
'action' => 'accesshosts',
'create' => 'yes',
'db' => $database->getDatabaseName(),
Expand All @@ -52,7 +52,7 @@ public static function create(Database $database, $host)
*/
public function delete()
{
$this->getContext()->invokePost('DATABASES', [
$this->getContext()->invokeApiPost('DATABASES', [
'action' => 'accesshosts',
'delete' => 'yes',
'db' => $this->database->getDatabaseName(),
Expand Down
20 changes: 10 additions & 10 deletions src/DirectAdmin/Objects/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public static function create(User $user, $domainName, $bandwidthLimit = null, $
'php' => Conversion::onOff($php, $user->hasPHP()),
'cgi' => Conversion::onOff($cgi, $user->hasCGI()),
];
$user->getContext()->invokePost('DOMAIN', $options);
$config = $user->getContext()->invokeGet('ADDITIONAL_DOMAINS');
$user->getContext()->invokeApiPost('DOMAIN', $options);
$config = $user->getContext()->invokeApiGet('ADDITIONAL_DOMAINS');
return new self($domainName, $user->getContext(), $config[$domainName]);
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public function createPointer($domain, $alias = false)
} else {
$list = &$this->pointers;
}
$this->getContext()->invokePost('DOMAIN_POINTER', $parameters);
$this->getContext()->invokeApiPost('DOMAIN_POINTER', $parameters);
$list[] = $domain;
$list = array_unique($list);
}
Expand All @@ -160,7 +160,7 @@ public function createSubdomain($prefix)
*/
public function delete()
{
$this->getContext()->invokePost('DOMAIN', [
$this->getContext()->invokeApiPost('DOMAIN', [
'delete' => true,
'confirmed' => true,
'select0' => $this->domainName,
Expand Down Expand Up @@ -197,7 +197,7 @@ public function getBandwidthLimit()
*/
public function getCatchall()
{
$value = $this->getContext()->invokeGet('EMAIL_CATCH_ALL', ['domain' => $this->domainName]);
$value = $this->getContext()->invokeApiGet('EMAIL_CATCH_ALL', ['domain' => $this->domainName]);
return isset($value['value']) ? $value['value'] : null;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public function getDomainNames()
public function getForwarders()
{
return $this->getCache(self::CACHE_FORWARDERS, function () {
$forwarders = $this->getContext()->invokeGet('EMAIL_FORWARDERS', [
$forwarders = $this->getContext()->invokeApiGet('EMAIL_FORWARDERS', [
'domain' => $this->getDomainName(),
]);
return DomainObject::toDomainObjectArray($forwarders, Forwarder::class, $this);
Expand All @@ -250,7 +250,7 @@ public function getForwarders()
public function getMailboxes()
{
return $this->getCache(self::CACHE_MAILBOXES, function () {
$boxes = $this->getContext()->invokeGet('POP', [
$boxes = $this->getContext()->invokeApiGet('POP', [
'domain' => $this->getDomainName(),
'action' => 'full_list',
]);
Expand Down Expand Up @@ -280,7 +280,7 @@ public function getPointers()
public function getSubdomains()
{
return $this->getCache(self::CACHE_SUBDOMAINS, function () {
$subs = $this->getContext()->invokeGet('SUBDOMAINS', ['domain' => $this->getDomainName()]);
$subs = $this->getContext()->invokeApiGet('SUBDOMAINS', ['domain' => $this->getDomainName()]);
$subs = array_combine($subs, $subs);
return DomainObject::toDomainObjectArray($subs, Subdomain::class, $this);
});
Expand All @@ -297,7 +297,7 @@ public function getSubdomains()
*/
public function invokePost($command, $action, $parameters = [], $clearCache = true)
{
$response = $this->getContext()->invokePost($command, array_merge([
$response = $this->getContext()->invokeApiPost($command, array_merge([
'action' => $action,
'domain' => $this->domainName,
], $parameters));
Expand All @@ -314,7 +314,7 @@ public function setCatchall($newValue)
{
$parameters = array_merge(['domain' => $this->domainName, 'update' => 'Update'],
(empty($newValue) || $newValue[0] == ':') ? ['catch' => $newValue] : ['catch' => 'address', 'value' => $newValue]);
$this->getContext()->invokePost('EMAIL_CATCH_ALL', $parameters);
$this->getContext()->invokeApiPost('EMAIL_CATCH_ALL', $parameters);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DirectAdmin/Objects/Email/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getMailsSent()
protected function getData($key)
{
return $this->getCacheItem(self::CACHE_DATA, $key, function () {
$result = $this->getContext()->invokeGet('POP', [
$result = $this->getContext()->invokeApiGet('POP', [
'domain' => $this->getDomainName(),
'action' => 'full_list',
]);
Expand Down
2 changes: 1 addition & 1 deletion src/DirectAdmin/Objects/Users/Reseller.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getUser($username)
*/
public function getUsers()
{
return BaseObject::toObjectArray($this->getContext()->invokeGet('SHOW_USERS', ['reseller' => $this->getUsername()]),
return BaseObject::toObjectArray($this->getContext()->invokeApiGet('SHOW_USERS', ['reseller' => $this->getUsername()]),
User::class, $this->getContext());
}

Expand Down
10 changes: 5 additions & 5 deletions src/DirectAdmin/Objects/Users/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function getDatabases()
{
return $this->getCache(self::CACHE_DATABASES, function () {
$databases = [];
foreach ($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) {
foreach ($this->getSelfManagedContext()->invokeApiGet('DATABASES') as $fullName) {
list($user, $db) = explode('_', $fullName, 2);
if ($this->getUsername() != $user) {
throw new DirectAdminException('Username incorrect on database ' . $fullName);
Expand Down Expand Up @@ -238,7 +238,7 @@ public function getDomains()
if (!$this->isSelfManaged()) {
$this->domains = $this->impersonate()->getDomains();
} else {
$this->domains = BaseObject::toRichObjectArray($this->getContext()->invokeGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext());
$this->domains = BaseObject::toRichObjectArray($this->getContext()->invokeApiGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext());
}
}
return $this->domains;
Expand Down Expand Up @@ -297,7 +297,7 @@ public function impersonate()
*/
public function modifyConfig(array $newConfig)
{
$this->getContext()->invokePost('MODIFY_USER', array_merge(
$this->getContext()->invokeApiPost('MODIFY_USER', array_merge(
$this->loadConfig(),
Conversion::processUnlimitedOptions($newConfig),
['action' => 'customize', 'user' => $this->getUsername()]
Expand Down Expand Up @@ -382,7 +382,7 @@ private function getConfig($item)
private function getUsage($item)
{
return $this->getCacheItem(self::CACHE_USAGE, $item, function () {
return $this->getContext()->invokeGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]);
return $this->getContext()->invokeApiGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]);
});
}

Expand Down Expand Up @@ -417,6 +417,6 @@ protected function isSelfManaged()
*/
private function loadConfig()
{
return $this->getContext()->invokeGet('SHOW_USER_CONFIG', ['user' => $this->getUsername()]);
return $this->getContext()->invokeApiGet('SHOW_USER_CONFIG', ['user' => $this->getUsername()]);
}
}
2 changes: 1 addition & 1 deletion tests/DirectAdmin/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testInvalidPassword()
public function testInvalidCall()
{
$admin = DirectAdmin::connectAdmin(DIRECTADMIN_URL, MASTER_ADMIN_USERNAME, MASTER_ADMIN_PASSWORD);
$admin->invokeGet('INVALID_COMMAND');
$admin->invokeApiGet('INVALID_COMMAND');
}

/**
Expand Down

0 comments on commit 9e90488

Please sign in to comment.