1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kallencode\Wakatime; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Illuminate\Support\Traits\Macroable; |
8
|
|
|
|
9
|
|
|
class Wakatime |
10
|
|
|
{ |
11
|
|
|
use Macroable; |
12
|
|
|
|
13
|
|
|
protected $client; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Create a new Wakatime Instance. |
17
|
|
|
*/ |
18
|
|
|
public function __construct(WakatimeClient $client) |
19
|
|
|
{ |
20
|
|
|
$this->client = $client; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function setApiKey(string $apiKey) |
24
|
|
|
{ |
25
|
|
|
$this->client->setApiKey($apiKey); |
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getApiKey() : string |
31
|
|
|
{ |
32
|
|
|
return $this->client->getApiKey(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getBaseUrl() : string |
36
|
|
|
{ |
37
|
|
|
return $this->client->getBaseUrl(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function setBaseUrl(string $baseUrl) |
41
|
|
|
{ |
42
|
|
|
$this->client->setBaseUrl($baseUrl); |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Fetches the User's durations for the specified Date |
49
|
|
|
* |
50
|
|
|
* |
51
|
|
|
* @param DateTime $date |
52
|
|
|
* @param string $user |
53
|
|
|
* @param array $optionalQuery |
54
|
|
|
* project (optional) Only show duration for this project |
55
|
|
|
* branches (optional) Only show durations for these branches: |
56
|
|
|
* comma separated list of branch names |
57
|
|
|
* @return Collection |
58
|
|
|
*/ |
59
|
|
|
public function fetchUserDurations(DateTime $date, string $user = 'current', array $optionalQuery = []) : Collection |
60
|
|
|
{ |
61
|
|
|
$query = array_merge([ |
62
|
|
|
'date' => $date->format('Y-m-d'), $optionalQuery]); |
63
|
|
|
|
64
|
|
|
return $this->performRequest("users/{$user}/durations", $query, []); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function performRequest($resource, array $query = [], array $headers = []) |
69
|
|
|
{ |
70
|
|
|
return $this->client->performRequest($resource, $headers, $query); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|