Art-of-WiFi / UniFi-API-client

A PHP API client class to interact with Ubiquiti's UniFi Controller API
MIT License
1.09k stars 217 forks source link

Suggestion for adding method to provide data from /insights/filtering/watchlist #211

Closed wisouder closed 4 months ago

wisouder commented 5 months ago

I made the following as a suggestion if you find useful.

/**
 ****
 * Fetch filtering watchlist
 *
 * @param int $start optional, Unix timestamp in milliseconds
 * @param int $end   optional, Unix timestamp in milliseconds
 * @return array returns an array of watchlist clients and their corresponding traffic, threat blocks, ad blocks, and traffic rules enforced
 *         additionally you will get an array of fingerprint data that could be used to identify the type of client
 */
public function list_insights_filtering_watchlist($start = null, $end = null)
{
    $end     = empty($end) ? time() * 1000 : intval($end);
    $start   = empty($start) ? $end - (7 * 24 * 3600 * 1000) : intval($start);
    $attribs = [
    ];
    $payload = ['start' => $start, 'end' => $end];
    return $this->fetch_results('/v2/api/site/' . $this->site . '/insights/filtering/watchlist?start=' . $start . '&end=' . $end);
}
malle-pietje commented 5 months ago

Thanks for contributing. Since the logic isn't very complex and the usage is for a very specific use-case, I suggest creating an example file instead that leverages the custom_api_request() method. If you can create one, I'll add it with the next release.

I'm trying to avoid the class from growing too large, instead I try to encourage developers to use the above method for "simple" routes.

wisouder commented 5 months ago

Thank you for the quick response! I will review the custom_api_request() and respond!