1 | <?php |
||
2 | |||
3 | namespace Resova\Endpoints; |
||
4 | |||
5 | use Resova\Client; |
||
6 | use Resova\Interfaces\AvailabilityInterface; |
||
7 | use Resova\Interfaces\QueryInterface; |
||
8 | use Resova\Models\Instance; |
||
9 | use Resova\Models\InstancePricing; |
||
10 | use Resova\Models\Pricing; |
||
11 | |||
12 | /** |
||
13 | * Availability represents the time slots (instances) and spaces |
||
14 | * that are available or occupied on a given Item. |
||
15 | * |
||
16 | * @package Resova\Endpoints |
||
17 | */ |
||
18 | class Availability extends Client implements AvailabilityInterface |
||
19 | { |
||
20 | /** |
||
21 | * Retrieve daily availability |
||
22 | * Retrieve the instances for items across a date range. |
||
23 | * |
||
24 | * @param string $start_date The start date for the availability range |
||
25 | * @param string $end_date The end date for the availability range. |
||
26 | * @param array $item_ids Limit the availability results by item ids |
||
27 | * @param int $item_id Limit the availability results to a single item |
||
28 | * |
||
29 | * @return \Resova\Interfaces\QueryInterface |
||
30 | */ |
||
31 | 1 | public function calendar(string $start_date, string $end_date, array $item_ids = [], int $item_id = null): QueryInterface |
|
32 | { |
||
33 | // Default parameters |
||
34 | $params = [ |
||
35 | 1 | 'start_date' => $start_date, |
|
36 | 1 | 'end_date' => $end_date, |
|
37 | ]; |
||
38 | |||
39 | // Optional: Limit the availability results by item ids |
||
40 | 1 | if (!empty($item_ids)) { |
|
41 | 1 | $params['item_ids'] = implode(',', $item_ids); |
|
42 | } |
||
43 | |||
44 | // Filter by ID |
||
45 | 1 | if (!empty($item_id)) { |
|
46 | 1 | $params['item_id'] = implode(',', $item_ids); |
|
47 | } |
||
48 | |||
49 | // Set HTTP params |
||
50 | 1 | $this->type = 'get'; |
|
51 | 1 | $this->endpoint = '/availability/calendar' . '?' . http_build_query($params); |
|
52 | 1 | $this->response = \Resova\Models\Availability::class; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
53 | |||
54 | 1 | return $this; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * Retrieve an instance |
||
59 | * Retrieve the details of a specific instance. |
||
60 | * |
||
61 | * @param string $instance_id The Instance Id |
||
62 | * |
||
63 | * @return \Resova\Interfaces\QueryInterface |
||
64 | */ |
||
65 | public function instance(string $instance_id): QueryInterface |
||
66 | { |
||
67 | // Set HTTP params |
||
68 | $this->type = 'get'; |
||
69 | $this->endpoint = '/availability/instance/' . $instance_id; |
||
70 | $this->response = Instance::class; |
||
0 ignored issues
–
show
|
|||
71 | |||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Retrieve instance pricing |
||
77 | * Retrieve the pricing for an instance for the quantities passed. |
||
78 | * |
||
79 | * @param string $instance_id |
||
80 | * @param \Resova\Models\Pricing $pricing |
||
81 | * |
||
82 | * @return \Resova\Interfaces\QueryInterface |
||
83 | */ |
||
84 | public function instancePricing(string $instance_id, Pricing $pricing): QueryInterface |
||
85 | { |
||
86 | $pricing->setRequired([ |
||
87 | 'quantities' |
||
88 | ]); |
||
89 | |||
90 | // Set HTTP params |
||
91 | $this->type = 'post'; |
||
92 | $this->endpoint = '/availability/instance/' . $instance_id . '/pricing'; |
||
93 | $this->params = $pricing; |
||
94 | $this->response = InstancePricing::class; |
||
0 ignored issues
–
show
|
|||
95 | |||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | } |
||
100 |