Skip to content

Commit

Permalink
API browser version 1.0.23
Browse files Browse the repository at this point in the history
- changed inclusion of the UniFi API client and Kint classes to leverage composer autoloading
  • Loading branch information
malle-pietje committed Oct 4, 2017
1 parent 6d681ae commit 41042f0
Show file tree
Hide file tree
Showing 130 changed files with 13,332 additions and 230 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": {
"art-of-wifi/unifi-api-client": "^1.1",
"kint-php/kint": "2.2"
}
}
124 changes: 124 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* the currently supported data collections/API endpoints in the README.md file
* - this tool currently supports versions 4.x and 5.x of the UniFi Controller software
*
* VERSION: 1.0.21
* VERSION: 1.0.23
*
* ------------------------------------------------------------------------------------
*
Expand All @@ -20,7 +20,8 @@
* with this package in the file LICENSE.md
*
*/
define('API_BROWSER_VERSION', '1.0.21');
define('API_BROWSER_VERSION', '1.0.23');
define('API_CLASS_VERSION', get_client_version());

/**
* check whether the PHP curl module is available
Expand Down Expand Up @@ -83,15 +84,14 @@
}

/**
* load the UniFi API client class
* load the UniFi API client and Kint classes using composer autoloader
*/
require_once('phpapi/class.unifi.php');
require('vendor/autoload.php');

/**
* load the Kint class and set relevant options
* set relevant Kint options
* more info on Kint usage: http://kint-php.github.io/kint/
*/
require_once('kint/kint.php');
Kint::$display_called_from = false;

/**
Expand Down Expand Up @@ -238,7 +238,7 @@
* create a new instance of the API client class and log in to the UniFi controller
* - if an error occurs during the login process, an alert is displayed on the page
*/
$unifidata = new UnifiApi($controller['user'], $controller['password'], $controller['url'], $site_id);
$unifidata = new UniFi_API\Client($controller['user'], $controller['password'], $controller['url'], $site_id);
$set_debug_mode = $unifidata->set_debug(trim($debug));
$loginresults = $unifidata->login();

Expand Down Expand Up @@ -552,6 +552,28 @@ function sites_sort($site_a, $site_b)
{
return strcmp($site_a->desc, $site_b->desc);
}

/**
* function which returns the version of the included API client class by
* extracting it from the composer.lock file
*/
function get_client_version()
{
if (is_readable('composer.lock')) {
$composer_lock = file_get_contents('composer.lock');
$json_decoded = json_decode($composer_lock, true);

if (isset($json_decoded['packages'])) {
foreach ($json_decoded['packages'] as $package) {
if($package['name'] === 'art-of-wifi/unifi-api-client') {
return substr($package['version'], 1);
}
}
}
}

return 'unknown';
}
?>
<!DOCTYPE html>
<html>
Expand Down
Loading

0 comments on commit 41042f0

Please sign in to comment.