1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Guapa\TimeChimp; |
4
|
|
|
|
5
|
|
|
class ExpensesRequest extends AbstractRequest |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Get all expenses by date range. |
9
|
|
|
* |
10
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customersid/get-expenses-by-date-range |
11
|
|
|
* |
12
|
|
|
* @param \DateTime|string $start |
13
|
|
|
* @param \DateTime|string $end |
14
|
|
|
* |
15
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
16
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
17
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
18
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
19
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
20
|
|
|
*/ |
21
|
|
|
public function getByDateRange($start, $end): \Psr\Http\Message\ResponseInterface |
22
|
|
|
{ |
23
|
|
|
if (! $start instanceof \DateTime) { |
24
|
|
|
$start = new \DateTime($start); |
25
|
|
|
} |
26
|
|
|
$start = $start->format('Y-m-d'); |
27
|
|
|
|
28
|
|
|
if (! $end instanceof \DateTime) { |
29
|
|
|
$end = new \DateTime($end); |
30
|
|
|
} |
31
|
|
|
$end = $end->format('Y-m-d'); |
32
|
|
|
|
33
|
|
|
return $this->execute('get', "expenses/daterange/{$start}/{$end}"); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get all expenses for a single project. |
38
|
|
|
* |
39
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expensesdaterangestartdateenddate/get-expenses-by-project |
40
|
|
|
* |
41
|
|
|
* @param mixed $projectId |
42
|
|
|
* |
43
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
44
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
45
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
46
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
47
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
48
|
|
|
*/ |
49
|
|
|
public function forProject($projectId): \Psr\Http\Message\ResponseInterface |
50
|
|
|
{ |
51
|
|
|
return $this->execute('get', "expenses/project/{$projectId}"); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get a single expense. |
56
|
|
|
* |
57
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expensesid/get-expense |
58
|
|
|
* |
59
|
|
|
* @param mixed $id |
60
|
|
|
* |
61
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
62
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
63
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
64
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
65
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
66
|
|
|
*/ |
67
|
|
|
public function get($id): \Psr\Http\Message\ResponseInterface |
68
|
|
|
{ |
69
|
|
|
return $this->execute('get', "expenses/{$id}"); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get all expenses. |
74
|
|
|
* |
75
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expenses/get-expenses |
76
|
|
|
* |
77
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
78
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
79
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
80
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
81
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
82
|
|
|
*/ |
83
|
|
|
public function getAll(): \Psr\Http\Message\ResponseInterface |
84
|
|
|
{ |
85
|
|
|
return $this->execute('get', 'expenses'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Update an expense. |
90
|
|
|
* |
91
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expenses/update-expense |
92
|
|
|
* |
93
|
|
|
* @param array $parameters |
94
|
|
|
* |
95
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
96
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
97
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
98
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
99
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
100
|
|
|
*/ |
101
|
|
|
public function update(array $parameters): \Psr\Http\Message\ResponseInterface |
102
|
|
|
{ |
103
|
|
|
if (! isset($parameters['json'])) { |
104
|
|
|
$parameters = [ |
105
|
|
|
'json' => $parameters, |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->execute('put', 'expenses', $parameters); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Create an expense. |
114
|
|
|
* |
115
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expenses/create-new-expense |
116
|
|
|
* |
117
|
|
|
* @param array $parameters |
118
|
|
|
* |
119
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
120
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
121
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
122
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
123
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
124
|
|
|
*/ |
125
|
|
|
public function create(array $parameters): \Psr\Http\Message\ResponseInterface |
126
|
|
|
{ |
127
|
|
|
if (! isset($parameters['json'])) { |
128
|
|
|
$parameters = [ |
129
|
|
|
'json' => $parameters, |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $this->execute('post', 'expenses', $parameters); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Delete an expense. |
138
|
|
|
* |
139
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/expenses/v1expenses/delete-expense |
140
|
|
|
* |
141
|
|
|
* @param mixed $id |
142
|
|
|
* |
143
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
144
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
145
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
146
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
147
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
148
|
|
|
*/ |
149
|
|
|
public function delete($id): \Psr\Http\Message\ResponseInterface |
150
|
|
|
{ |
151
|
|
|
return $this->execute('delete', "expenses/{$id}"); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|