Skip to content

Commit

Permalink
API client class v1.1.89
Browse files Browse the repository at this point in the history
- added `create_tag()`, `set_tagged_devices()`, `get_tag()`, and `delete_tag()` methods to manage tags, contributed by @brenard, #205
  • Loading branch information
malle-pietje committed Feb 11, 2024
1 parent 7e60ce3 commit 007117c
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @package UniFi_Controller_API_Client_Class
* @author Art of WiFi <info@artofwifi.net>
* @version Release: 1.1.88
* @version Release: 1.1.89
* @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
Expand All @@ -25,7 +25,7 @@ class Client
*
* NOTE: do **not** modify the values below, instead use the constructor or the getter and setter functions/methods
*/
const CLASS_VERSION = '1.1.88';
const CLASS_VERSION = '1.1.89';
protected string $baseurl = 'https://127.0.0.1:8443';
protected string $user = '';
protected string $password = '';
Expand Down Expand Up @@ -227,7 +227,7 @@ public function login()
/**
* check the HTTP response code
*/
if ($http_code >= 200 ) {
if ($http_code >= 200) {
$this->is_logged_in = true;

return $this->is_logged_in;
Expand Down Expand Up @@ -1511,6 +1511,74 @@ public function list_tags()
return $this->fetch_results('/api/s/' . $this->site . '/rest/tag');
}

/**
* Create (device) tag (using REST)
*
* NOTES: this endpoint was introduced with controller versions 5.5.X
*
* @param string $name required, the tag name to add
* @param array|null $devices_macs optional, array of the MAC address(es) of the device(s) to tag with the new tag
* @return bool return true on success
*/
public function create_tag(string $name, array $devices_macs = null): bool
{
$payload = ['name' => $name];

if (is_array($devices_macs)) {
$payload['member_table'] = $devices_macs;
}

return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/tag', $payload);
}

/**
* Set tagged devices (using REST)
*
* NOTES: this endpoint was introduced with controller versions 5.5.X
*
* @param array $devices_macs required, array of the MAC address(es) of the device(s) to tag
* @param string $tag_id required, the _id value of the tag to set
* @return bool return true on success
*/
public function set_tagged_devices(array $devices_macs, string $tag_id): bool
{
$this->curl_method = 'PUT';

$payload = ['member_table' => $devices_macs];

return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/tag/' . $tag_id, $payload);
}

/**
* Get (device) tag (using REST)
*
* NOTES: this endpoint was introduced with controller versions 5.5.X
*
* @param string $tag_id required, the _id value of the tag to retrieve
* @return array|bool containing matching tag objects
*/
public function get_tag(string $tag_id)
{
$this->curl_method = 'GET';

return $this->fetch_results('/api/s/' . $this->site . '/rest/tag/' . $tag_id);
}

/**
* Delete (device) tag (using REST)
*
* NOTES: this endpoint was introduced with controller versions 5.5.X
*
* @param string $tag_id required, the _id value of the tag to set
* @return bool return true on success
*/
public function delete_tag(string $tag_id): bool
{
$this->curl_method = 'DELETE';

return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/tag/' . $tag_id);
}

/**
* Fetch rogue/neighboring access points
*
Expand All @@ -1520,6 +1588,7 @@ public function list_tags()
public function list_rogueaps(int $within = 24)
{
$payload = ['within' => $within];

return $this->fetch_results('/api/s/' . $this->site . '/stat/rogueap', $payload);
}

Expand Down

0 comments on commit 007117c

Please sign in to comment.