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
30 changes: 14 additions & 16 deletions src/Wheniwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Wheniwork

private $api_token;
private $api_endpoint = 'https://api.wheniwork.com/2';
private $api_headers = [];
private $api_headers = array();
private $verify_ssl = false;

/**
Expand All @@ -39,7 +39,7 @@ class Wheniwork
* @param string $api_token The user WhenIWork API token
* @param array $options Allows you to set the `headers` and the `endpoint`
*/
function __construct($api_token = null, $options = [])
function __construct($api_token = null, $options = array())
{
$this->api_token = $api_token;

Expand Down Expand Up @@ -133,7 +133,7 @@ public function getHeaders()
* @param array $headers Array of custom headers to be passed
* @return array Object of json decoded API response.
*/
public function get($method, $params = [], $headers = [])
public function get($method, $params = array(), $headers = array())
{
return $this->makeRequest($method, self::METHOD_GET, $params, $headers);
}
Expand All @@ -146,7 +146,7 @@ public function get($method, $params = [], $headers = [])
* @param array $headers Array of custom headers to be passed
* @return array Object of json decoded API response.
*/
public function post($method, $params = [], $headers = [])
public function post($method, $params = array(), $headers = array())
{
return $this->makeRequest($method, self::METHOD_POST, $params, $headers);
}
Expand All @@ -159,7 +159,7 @@ public function post($method, $params = [], $headers = [])
* @param array $headers Array of custom headers to be passed
* @return array Object of json decoded API response.
*/
public function create($method, $params = [], $headers = [])
public function create($method, $params = array(), $headers = array())
{
return $this->post($method, $params, $headers);
}
Expand All @@ -172,7 +172,7 @@ public function create($method, $params = [], $headers = [])
* @param array $headers Array of custom headers to be passed
* @return array Object of json decoded API response.
*/
public function update($method, $params = [], $headers = [])
public function update($method, $params = array(), $headers = array())
{
return $this->makeRequest($method, self::METHOD_PUT, $params, $headers);
}
Expand All @@ -185,12 +185,11 @@ public function update($method, $params = [], $headers = [])
* @param array $headers Array of custom headers to be passed
* @return array Object of json decoded API response.
*/
public function delete($method, $params = [], $headers = [])
public function delete($method, $params = array(), $headers = array())
{
return $this->makeRequest($method, self::METHOD_DELETE, $params, $headers);
}


/**
* Performs the underlying HTTP request. Exciting stuff happening here. Not really.
*
Expand All @@ -200,7 +199,7 @@ public function delete($method, $params = [], $headers = [])
* @param array $headers Assoc array of custom headers to be passed
* @return array Assoc array of decoded result
*/
private function makeRequest($method, $request, $params = [], $headers = [])
private function makeRequest($method, $request, $params = array(), $headers = array())
{
$url = $this->getEndpoint() . '/' . $method;

Expand All @@ -219,7 +218,7 @@ private function makeRequest($method, $request, $params = [], $headers = [])
$headers['W-Token'] = $this->api_token;
}

$headers_data = [];
$headers_data = array();
foreach ($headers as $k => $v) {
$headers_data[] = $k . ': ' . $v;
}
Expand All @@ -232,7 +231,7 @@ private function makeRequest($method, $request, $params = [], $headers = [])
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);

if (in_array($request, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH])) {
if (in_array($request, array(self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH))) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
}

Expand All @@ -242,7 +241,6 @@ private function makeRequest($method, $request, $params = [], $headers = [])
return $result ? json_decode($result) : false;
}


/**
* Login helper using developer key and credentials to get back a login response
*
Expand All @@ -253,14 +251,14 @@ private function makeRequest($method, $request, $params = [], $headers = [])
*/
public static function login($key, $email, $password)
{
$params = [
$params = array(
"username" => $email,
"password" => $password,
];
);

$headers = [
$headers = array(
'W-Key' => $key
];
);

$login = new static();
$response = $login->makeRequest("login", self::METHOD_POST, $params, $headers);
Expand Down