Skip to content

Commit

Permalink
code cleanup update
Browse files Browse the repository at this point in the history
  • Loading branch information
detain committed Jun 24, 2017
1 parent 7ba9cbd commit 4c13cdd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/Ksplice.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*
* @access public
*/
class Ksplice
{
class Ksplice {
private $apiKey;
private $apiUsername;
private $urlBase = 'https://uptrack.api.ksplice.com';
Expand All @@ -43,8 +42,8 @@ class Ksplice
public function __construct($apiUsername, $apiKey) {
$this->apiUsername = $apiUsername;
$this->apiKey = $apiKey;
if (file_exists(__DIR__ . '/../../../../include/rendering/RESTClient.php'))
include_once(__DIR__ . '/../../../../include/rendering/RESTClient.php');
if (file_exists(__DIR__.'/../../../../include/rendering/RESTClient.php'))
include_once(__DIR__.'/../../../../include/rendering/RESTClient.php');
if (class_exists('\\RestClient'))
$this->restClient = new \RESTClient();
$this->headers = array(
Expand All @@ -59,7 +58,7 @@ public function __construct($apiUsername, $apiKey) {
* @return void
*/
public function request() {
$this->restClient->createRequest($this->urlBase . $this->url, $this->method, $this->inputs, $this->headers);
$this->restClient->createRequest($this->urlBase.$this->url, $this->method, $this->inputs, $this->headers);
$this->restClient->sendRequest();
$this->responseRaw = $this->restClient->getResponse();
$this->response = json_decode($this->responseRaw);
Expand Down Expand Up @@ -91,7 +90,7 @@ public function list_machines() {
* @return void
*/
public function describe_machine($uuid) {
$this->url = '/api/1/machine/' . $uuid . '/describe';
$this->url = '/api/1/machine/'.$uuid.'/describe';
$this->method = 'GET';
return $this->request();
}
Expand Down Expand Up @@ -121,19 +120,19 @@ public function ip_to_uuid($ipAddress) {
* @return void
*/
public function authorize_machine($uuid, $authorize = TRUE) {
$this->url = '/api/1/machine/' . $uuid . '/authorize';
$this->url = '/api/1/machine/'.$uuid.'/authorize';
$this->method = 'POST';
$this->inputs = json_encode(array('authorized' => $authorize));
$this->request();
if ($authorize == TRUE)
myadmin_log('licenses', 'info', "Authorize Ksplice ({$uuid}, {$authorize}) Response: " . json_encode($this->response), __LINE__, __FILE__);
myadmin_log('licenses', 'info', "Authorize Ksplice ({$uuid}, {$authorize}) Response: ".json_encode($this->response), __LINE__, __FILE__);
else
myadmin_log('licenses', 'info', "Deauthorize Ksplice ({$uuid}, {$authorize}) Response: " . json_encode($this->response), __LINE__, __FILE__);
myadmin_log('licenses', 'info', "Deauthorize Ksplice ({$uuid}, {$authorize}) Response: ".json_encode($this->response), __LINE__, __FILE__);
return $this->response;
}

/**
* @param $uuid
* @param string|boolean $uuid
*/
public function deauthorize_machine($uuid) {
return $this->authorize_machine($uuid, FALSE);
Expand All @@ -147,7 +146,7 @@ public function deauthorize_machine($uuid) {
* @return void
*/
public function change_group($uuid, $groupName = '') {
$this->url = '/api/1/machine/' . $uuid . '/group';
$this->url = '/api/1/machine/'.$uuid.'/group';
$this->method = 'POST';
$this->inputs = json_encode(array('group_name' => $groupName));
return $this->request();
Expand Down
8 changes: 4 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function_requirements('activate_ksplice');
activate_ksplice($license->get_ip(), $event['field1']);
$ksplice = new \Detain\MyAdminKsplice\Ksplice(KSPLICE_API_USERNAME, KSPLICE_API_KEY);
$uuid = $ksplice->ip_to_uuid($license->get_ip());
myadmin_log(self::$module, 'info', "Got UUID $uuid from IP " . $license->get_ip(), __LINE__, __FILE__);
myadmin_log(self::$module, 'info', "Got UUID $uuid from IP ".$license->get_ip(), __LINE__, __FILE__);
$ksplice->authorize_machine($uuid, TRUE);
myadmin_log(self::$module, 'info', 'Response: ' . $ksplice->responseRaw, __LINE__, __FILE__);
myadmin_log(self::$module, 'info', 'Response: ' . json_encode($ksplice->response), __LINE__, __FILE__);
myadmin_log(self::$module, 'info', 'Response: '.$ksplice->responseRaw, __LINE__, __FILE__);
myadmin_log(self::$module, 'info', 'Response: '.json_encode($ksplice->response), __LINE__, __FILE__);
$event->stopPropagation();
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public static function getSettings(GenericEvent $event) {
$settings = $event->getSubject();
$settings->add_text_setting(self::$module, 'KSplice', 'ksplice_apiUsername', 'Ksplice API Username:', 'Ksplice API Username', $settings->get_setting('KSPLICE_API_USERNAME'));
$settings->add_text_setting(self::$module, 'KSplice', 'ksplice_apiKey', 'Ksplice API Key:', 'Ksplice API Key', $settings->get_setting('KSPLICE_API_KEY'));
$settings->add_dropdown_setting(self::$module, 'KSplice', 'outofstock_licenses_ksplice', 'Out Of Stock Ksplice Licenses', 'Enable/Disable Sales Of This Type', $settings->get_setting('OUTOFSTOCK_LICENSES_KSPLICE'), array('0', '1'), array('No', 'Yes', ));
$settings->add_dropdown_setting(self::$module, 'KSplice', 'outofstock_licenses_ksplice', 'Out Of Stock Ksplice Licenses', 'Enable/Disable Sales Of This Type', $settings->get_setting('OUTOFSTOCK_LICENSES_KSPLICE'), array('0', '1'), array('No', 'Yes',));
}

}
2 changes: 1 addition & 1 deletion src/ksplice.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ function deactivate_ksplice($ipAddressUuid) {
} else
$uuid = $ipAddressUuid;
$response = $ksplice->deauthorize_machine($uuid);
myadmin_log('licenses', 'info', "Deactivate Ksplice ({$ipAddressUuid}) Response " . json_encode($response), __LINE__, __FILE__);
myadmin_log('licenses', 'info', "Deactivate Ksplice ({$ipAddressUuid}) Response ".json_encode($response), __LINE__, __FILE__);
}

0 comments on commit 4c13cdd

Please sign in to comment.