Skip to content

Commit

Permalink
Adding activity log and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
woganmay committed May 3, 2018
1 parent 1eb1d9e commit ab64dc6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
21 changes: 21 additions & 0 deletions docs/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
Services
========

Activity Logs
-------------

The endpoint returns all the activity logs, sorted by event time descending. The basic call to fetch the last 50 events::

$entries = $client->API->Admin->getActivityLog();

To apply some filters, pass in an array of filters::

$filters = [
"user" => 12345,
"start" => "2018-01-01 00:00:00",
"end" => "2018-04-01 15:00:00",
"limit" => 100,
"offset" => 0
];

$filteredEntries = $client->API->Admin->getActivityLog($filters);

The service will automatically parse ISO timestamps into the epoch format the API needs. Or you can pass in epoch times yourself.

DataSets
--------

Expand Down
3 changes: 2 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace WoganMay\DomoPHP;
use GuzzleHttp\Exception\ClientException;

/**
* DomoPHP Client.
Expand Down Expand Up @@ -80,6 +79,7 @@ class Client
public $User;
public $Group;
public $Page;
public $Admin;

/**
* Base URL to talk to the API.
Expand Down Expand Up @@ -127,6 +127,7 @@ public function __construct($client_id, $client_secret, $scopes = [])
$this->Group = new Services\Group($this);
$this->User = new Services\User($this);
$this->Page = new Services\Page($this);
$this->Admin = new Services\Admin($this);
}

/**
Expand Down
58 changes: 58 additions & 0 deletions src/Services/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace WoganMay\DomoPHP\Services;

/**
* DomoPHP Admin.
*
* Utility methods for working with the admin
*
* @author Wogan May <wogan.may@gmail.com>
* @link https://github.com/woganmay/domo-php
*/
class Admin
{
private $Client = null;

/**
* oAuth Client ID.
*
* The Client ID obtained from developer.domo.com
*
* @param \WoganMay\DomoPHP\Client $APIClient An instance of the API Client
*/
public function __construct(\WoganMay\DomoPHP\Client $APIClient)
{
$this->Client = $APIClient;
}

/**
* @param $input Convert ISO date to epoch (or leave epoch unchanged)
* @return false|int
*/
private function parseISOtoEpoch($input)
{
return (strpos($input, "-") === FALSE) ? $input : strtotime($input);
}

/**
* @param array $options Query options
* @return object
* @throws \Exception
*/
public function getActivityLog($options = [])
{
$options = array_merge([
"limit" => 50,
"offset" => 0
], $options);

// Parse start/end dates
if (isset($options['start'])) $options['start'] = $this->parseISOtoEpoch($options['start']);
if (isset($options['end'])) $options['end'] = $this->parseISOtoEpoch($options['end']);

$string = http_build_query($options);

return $this->Client->getJSON("/v1/audit?$string");
}
}

0 comments on commit ab64dc6

Please sign in to comment.