TimeRequest::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Guapa\TimeChimp;
4
5
class TimeRequest extends AbstractRequest
6
{
7
    /**
8
     * Get all times entries by date range.
9
     *
10
     * @see https://timechimp.docs.apiary.io/#reference/time/v1timedaterangestartdateenddate/get-time-entries-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', "time/daterange/{$start}/{$end}");
34
    }
35
36
    /**
37
     * Get all time entries for a project.
38
     *
39
     * @see https://timechimp.docs.apiary.io/#reference/time/v1timeprojectprojectid/get-time-entries-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', "time/project/{$projectId}");
52
    }
53
54
    /**
55
     * Get a single time entry.
56
     *
57
     * @see https://timechimp.docs.apiary.io/#reference/time/v1timeid/get-time-entry
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', "time/{$id}");
70
    }
71
72
    /**
73
     * Get all time entries.
74
     *
75
     * @see https://timechimp.docs.apiary.io/#reference/time/v1time/get-time-entries
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', 'time');
86
    }
87
88
    /**
89
     * Update a time entry.
90
     *
91
     * @see https://timechimp.docs.apiary.io/#reference/time/v1time/update-time-entry
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', 'time', $parameters);
110
    }
111
112
    /**
113
     * Create a time entry.
114
     *
115
     * @see https://timechimp.docs.apiary.io/#reference/time/v1time/create-new-time-entry
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', 'time', $parameters);
134
    }
135
136
    /**
137
     * Delete a time entry.
138
     *
139
     * @see https://timechimp.docs.apiary.io/#reference/time/v1time/delete-time-entry
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', "time/{$id}");
152
    }
153
154
    /**
155
     * Start a timer.
156
     *
157
     * @see https://timechimp.docs.apiary.io/#reference/time/v1timestarttimerid/post
158
     *
159
     * @param mixed $id
160
     *
161
     * @return \Psr\Http\Message\ResponseInterface
162
     * @throws \Guapa\TimeChimp\Exceptions\ClientException
163
     * @throws \Guapa\TimeChimp\Exceptions\NotFoundException
164
     * @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException
165
     * @throws \GuzzleHttp\Exception\GuzzleException
166
     */
167
    public function startTimer($id): \Psr\Http\Message\ResponseInterface
168
    {
169
        return $this->execute('post', "time/starttimer/{$id}");
170
    }
171
172
    /**
173
     * Stop a timer.
174
     *
175
     * @see https://timechimp.docs.apiary.io/#reference/time/v1timestoptimerid/post
176
     *
177
     * @param mixed $id
178
     *
179
     * @return \Psr\Http\Message\ResponseInterface
180
     * @throws \Guapa\TimeChimp\Exceptions\ClientException
181
     * @throws \Guapa\TimeChimp\Exceptions\NotFoundException
182
     * @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException
183
     * @throws \GuzzleHttp\Exception\GuzzleException
184
     */
185
    public function stopTimer($id): \Psr\Http\Message\ResponseInterface
186
    {
187
        return $this->execute('post', "time/stoptimer/{$id}");
188
    }
189
}
190