-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- updated README to reflect support for 7.X - `get_last_error_message()` now always returns a string which is empty if no message is available - applied PR #151 in slightly different way for consistency with other similar code sections, contributed by @banakito - changed default argument values in several methods/functions from null to an empty string
- Loading branch information
1 parent
4fe1780
commit cbe89d9
Showing
2 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* | ||
* @package UniFi_Controller_API_Client_Class | ||
* @author Art of WiFi <[email protected]> | ||
* @version Release: 1.1.78 | ||
* @version Release: 1.1.79 | ||
* @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md | ||
* @example This directory in the package repository contains a collection of examples: | ||
* https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples | ||
|
@@ -26,7 +26,7 @@ class Client | |
* NOTE: | ||
* do not modify the values here, instead use the constructor or the getter and setter functions/methods | ||
*/ | ||
const CLASS_VERSION = '1.1.78'; | ||
const CLASS_VERSION = '1.1.79'; | ||
protected $baseurl = 'https://127.0.0.1:8443'; | ||
protected $user = ''; | ||
protected $password = ''; | ||
|
@@ -38,7 +38,7 @@ class Client | |
protected $exec_retries = 0; | ||
protected $cookies = ''; | ||
protected $last_results_raw = null; | ||
protected $last_error_message = null; | ||
protected $last_error_message = ''; | ||
protected $curl_ssl_verify_peer = false; | ||
protected $curl_ssl_verify_host = false; | ||
protected $curl_http_version = CURL_HTTP_VERSION_NONE; | ||
|
@@ -428,7 +428,7 @@ public function create_user($mac, $user_group_id, $name = null, $note = null, $i | |
* the existing note for the client-device is removed and "noted" attribute set to false | ||
* @return bool returns true upon success | ||
*/ | ||
public function set_sta_note($user_id, $note = null) | ||
public function set_sta_note($user_id, $note = '') | ||
{ | ||
$payload = ['note' => $note]; | ||
return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload); | ||
|
@@ -442,7 +442,7 @@ public function set_sta_note($user_id, $note = null) | |
* the existing name for the client device is removed | ||
* @return bool returns true upon success | ||
*/ | ||
public function set_sta_name($user_id, $name = null) | ||
public function set_sta_name($user_id, $name = '') | ||
{ | ||
$payload = ['name' => $name]; | ||
return $this->fetch_results_boolean('/api/s/' . $this->site . '/upd/user/' . trim($user_id), $payload); | ||
|
@@ -1706,15 +1706,16 @@ public function invite_admin( | |
$device_adopt = false, | ||
$device_restart = false | ||
) { | ||
$email_valid = filter_var(trim($email), FILTER_VALIDATE_EMAIL); | ||
$email = trim($email); | ||
$email_valid = filter_var($email, FILTER_VALIDATE_EMAIL); | ||
if (!$email_valid) { | ||
trigger_error('The email address provided is invalid!'); | ||
return false; | ||
} | ||
|
||
$payload = [ | ||
'name' => trim($name), | ||
'email' => trim($email), | ||
'email' => $email, | ||
'for_sso' => $enable_sso, | ||
'cmd' => 'invite-admin', | ||
'role' => 'admin', | ||
|
@@ -1895,10 +1896,10 @@ public function stat_payment($within = null) | |
* @param string $note optional, note to attach to the hotspot operator | ||
* @return bool true upon success | ||
*/ | ||
public function create_hotspotop($name, $x_password, $note = null) | ||
public function create_hotspotop($name, $x_password, $note = '') | ||
{ | ||
$payload = ['name' => $name, 'x_password' => $x_password]; | ||
if (is_string($note)) { | ||
if (!empty($note)) { | ||
$payload['note'] = trim($note); | ||
} | ||
|
||
|
@@ -1934,7 +1935,7 @@ public function create_voucher( | |
$minutes, | ||
$count = 1, | ||
$quota = 0, | ||
$note = null, | ||
$note = '', | ||
$up = null, | ||
$down = null, | ||
$megabytes = null | ||
|
@@ -1946,7 +1947,7 @@ public function create_voucher( | |
'quota' => intval($quota), | ||
]; | ||
|
||
if (is_string($note)) { | ||
if (!empty($note)) { | ||
$payload['note'] = trim($note); | ||
} | ||
|
||
|
@@ -2575,7 +2576,7 @@ public function delete_network($network_id) | |
* @return array containing wireless networks and their settings, or an array containing a single wireless network | ||
* when using the <wlan_id> parameter | ||
*/ | ||
public function list_wlanconf($wlan_id = null) | ||
public function list_wlanconf($wlan_id = '') | ||
{ | ||
return $this->fetch_results('/api/s/' . $this->site . '/rest/wlanconf/' . trim($wlan_id)); | ||
} | ||
|
@@ -2676,12 +2677,12 @@ public function set_wlansettings_base($wlan_id, $payload) | |
* @param string $name optional, SSID | ||
* @return bool true on success | ||
*/ | ||
public function set_wlansettings($wlan_id, $x_passphrase, $name = null) | ||
public function set_wlansettings($wlan_id, $x_passphrase, $name = '') | ||
{ | ||
$payload = []; | ||
$payload['x_passphrase'] = trim($x_passphrase); | ||
|
||
if (is_string($name)) { | ||
if (!empty($name)) { | ||
$payload['name'] = trim($name); | ||
} | ||
|
||
|
@@ -2804,7 +2805,7 @@ public function count_alarms($archived = null) | |
* by default all alarms are archived | ||
* @return bool true on success | ||
*/ | ||
public function archive_alarm($alarm_id = null) | ||
public function archive_alarm($alarm_id = '') | ||
{ | ||
$payload = ['cmd' => 'archive-all-alarms']; | ||
if (!empty($alarm_id)) { | ||
|
@@ -3364,7 +3365,7 @@ public function get_debug() | |
* | ||
* @param boolean $return_json true returns the results in "pretty printed" json format, | ||
* false returns PHP stdClass Object format (default) | ||
* @return false|string|null the raw results as returned by the controller API | ||
* @return false|string|object|null the raw results as returned by the controller API | ||
*/ | ||
public function get_last_results_raw($return_json = false) | ||
{ | ||
|
@@ -3382,16 +3383,12 @@ public function get_last_results_raw($return_json = false) | |
/** | ||
* Get last error message | ||
* | ||
* @return object|bool the error message of the last method called in PHP stdClass Object format, returns false if | ||
* unavailable | ||
* @return string the error message of the last method called in PHP stdClass Object format, an empty string when | ||
* none available | ||
*/ | ||
public function get_last_error_message() | ||
{ | ||
if (!is_null($this->last_error_message)) { | ||
return $this->last_error_message; | ||
} | ||
|
||
return false; | ||
return $this->last_error_message; | ||
} | ||
|
||
/** | ||
|
@@ -3655,7 +3652,7 @@ protected function fetch_results($path, $payload = null, $boolean = false, $logi | |
|
||
if (isset($response->meta->rc)) { | ||
if ($response->meta->rc === 'ok') { | ||
$this->last_error_message = null; | ||
$this->last_error_message = ''; | ||
if (is_array($response->data) && !$boolean) { | ||
return $response->data; | ||
} | ||
|