Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/Wheniwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* Daniel Olfelt <daniel@thisclicks.com>
*
* @author Daniel Olfelt <daniel@thisclicks.com>
* @version 0.1
* @author Conner McCall <conner@wheniwork.com>
* @version 0.2
*/
class Wheniwork
{
/**
* Library Version
*/
const VERSION = '0.1';
const VERSION = '0.2';

/**
* HTTP Methods
Expand All @@ -32,6 +33,7 @@ class Wheniwork
private $api_endpoint = 'https://api.wheniwork.com/2';
private $api_headers = [];
private $verify_ssl = false;
private $user_agent = 'WhenIWork-PHP';

/**
* Create a new instance
Expand All @@ -43,12 +45,17 @@ function __construct($api_token = null, $options = [])
{
$this->api_token = $api_token;

$this->user_agent = $this->user_agent . '/' . static::VERSION;

if (!empty($options['endpoint'])) {
$this->setEndpoint($options['endpoint']);
}
if (!empty($options['headers'])) {
$this->setHeaders($options['headers'], true);
}
if (!empty($options['user_agent'])) {
$this->setUserAgent($options['user_agent'], true);
}
}

/**
Expand All @@ -64,6 +71,19 @@ public function setToken($api_token)
return $this;
}

/**
* Set the user agent for all requests
*
* @param string $user_agent The user agent sent with each request
* @return Wheniwork
*/
public function setUserAgent($user_agent)
{
$this->user_agent = $user_agent;

return $this;
}

/**
* Get the user token to save for future requests
*
Expand Down Expand Up @@ -210,7 +230,7 @@ private function makeRequest($method, $request, $params = [], $headers = [])

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'WhenIWork-PHP/' . static::VERSION);
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);

$headers += $this->getHeaders();

Expand Down