1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace InShore\Bookwhen\Resources; |
6
|
|
|
|
7
|
|
|
use InShore\Bookwhen\Contracts\Resources\EventsContract; |
8
|
|
|
use InShore\Bookwhen\Responses\Events\ListResponse; |
9
|
|
|
use InShore\Bookwhen\Responses\Events\RetrieveResponse; |
10
|
|
|
use InShore\Bookwhen\ValueObjects\Transporter\Payload; |
11
|
|
|
|
12
|
|
|
final class Events implements EventsContract |
13
|
|
|
{ |
14
|
|
|
use Concerns\Transportable; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Returns a list of events that belong to the user's organization. |
18
|
|
|
* |
19
|
|
|
* @see https://api.bookwhen.com/v2#tag/Event/paths/~1events/get |
20
|
|
|
*/ |
21
|
1 |
|
public function list(array $parameters): ListResponse |
22
|
|
|
{ |
23
|
1 |
|
$payload = Payload::list('events', $parameters); |
24
|
|
|
|
25
|
|
|
/** @var array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $result */ |
26
|
1 |
|
$result = $this->transporter->requestObject($payload); |
27
|
|
|
|
28
|
1 |
|
return ListResponse::from($result); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns information about a specific event. |
33
|
|
|
* |
34
|
|
|
* @see https://api.bookwhen.com/v2#tag/Event/paths/~1events~1%7Bevent_id%7D/get |
35
|
|
|
*/ |
36
|
2 |
|
public function retrieve(string $eventId, array $parameters): RetrieveResponse |
37
|
|
|
{ |
38
|
2 |
|
$payload = Payload::retrieve('events', $eventId, $parameters); |
39
|
|
|
|
40
|
|
|
/** @var array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $result */ |
41
|
2 |
|
$result = $this->transporter->requestObject($payload); |
42
|
|
|
|
43
|
2 |
|
if (!array_key_exists('included', $result)) { |
44
|
1 |
|
return RetrieveResponse::from($result['data']); |
45
|
|
|
} else { |
46
|
1 |
|
return RetrieveResponse::from($result['data'], $result['included']); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|