1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acquia\LiftClient\Manager; |
4
|
|
|
|
5
|
|
|
use Acquia\LiftClient\Entity\Slot; |
6
|
|
|
use GuzzleHttp\Psr7\Request; |
7
|
|
|
|
8
|
|
|
class SlotManager extends ManagerBase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* {@inheritdoc} |
12
|
|
|
*/ |
13
|
|
|
protected $queryParameters = [ |
14
|
|
|
'visible_on_page' => null, |
15
|
|
|
'status' => null, |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get a list of slots. |
20
|
|
|
* |
21
|
|
|
* Example of how to structure the $options parameter: |
22
|
|
|
* <code> |
23
|
|
|
* $options = [ |
24
|
|
|
* 'visible_on_page' => 'http://localhost/blog/*', |
25
|
|
|
* 'status' => 'enabled', |
26
|
|
|
* ]; |
27
|
|
|
* </code> |
28
|
|
|
* |
29
|
6 |
|
* @see http://docs.decision-api.acquia.com/#slots_get |
30
|
|
|
* |
31
|
|
|
* @param array $options |
32
|
6 |
|
* |
33
|
4 |
|
* @throws \GuzzleHttp\Exception\RequestException |
34
|
4 |
|
* |
35
|
|
|
* @return \Acquia\LiftClient\Entity\Slot[] |
36
|
6 |
|
*/ |
37
|
6 |
View Code Duplication |
public function query($options = []) |
38
|
6 |
|
{ |
39
|
|
|
$url = '/slots'; |
40
|
|
|
$url .= $this->getQueryString($options); |
41
|
6 |
|
|
42
|
6 |
|
// Now make the request. |
43
|
|
|
$request = new Request('GET', $url); |
44
|
|
|
$data = $this->getResponseJson($request); |
45
|
3 |
|
|
46
|
3 |
|
// Get them as Slot objects |
47
|
3 |
|
$slots = []; |
48
|
2 |
|
foreach ($data as $dataItem) { |
49
|
|
|
$slots[] = new Slot($dataItem); |
50
|
3 |
|
} |
51
|
|
|
|
52
|
|
|
return $slots; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get a specific slot. |
57
|
|
|
* |
58
|
|
|
* Example of how to structure the $options parameter: |
59
|
|
|
* |
60
|
|
|
* @see http://docs.decision-api.acquia.com/#slots__slotId__get |
61
|
|
|
* |
62
|
|
|
* @param array $id |
63
|
|
|
* |
64
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
65
|
|
|
* |
66
|
6 |
|
* @return \Acquia\LiftClient\Entity\Slot |
67
|
|
|
*/ |
68
|
6 |
View Code Duplication |
public function get($id) |
69
|
|
|
{ |
70
|
|
|
$url = "/slots/{$id}"; |
71
|
6 |
|
|
72
|
6 |
|
// Now make the request. |
73
|
|
|
$request = new Request('GET', $url); |
74
|
3 |
|
$data = $this->getResponseJson($request); |
75
|
|
|
|
76
|
|
|
return new Slot($data); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Add a slot. |
81
|
|
|
* |
82
|
|
|
* @param \Acquia\LiftClient\Entity\Slot $slot |
83
|
|
|
* |
84
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
85
|
|
|
* |
86
|
6 |
|
* @return \Acquia\LiftClient\Entity\Slot |
87
|
|
|
*/ |
88
|
6 |
View Code Duplication |
public function add(Slot $slot) |
89
|
6 |
|
{ |
90
|
6 |
|
$body = $slot->json(); |
91
|
6 |
|
$url = '/slots'; |
92
|
|
|
$request = new Request('POST', $url, [], $body); |
93
|
3 |
|
$data = $this->getResponseJson($request); |
94
|
|
|
|
95
|
|
|
return new Slot($data); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Deletes a slot by ID. |
100
|
|
|
* |
101
|
|
|
* @param string $id |
102
|
|
|
* |
103
|
|
|
* @throws \GuzzleHttp\Exception\RequestException |
104
|
|
|
* |
105
|
6 |
|
* @return bool |
106
|
|
|
*/ |
107
|
6 |
|
public function delete($id) |
108
|
6 |
|
{ |
109
|
|
|
$url = "/slots/{$id}"; |
110
|
3 |
|
$this->client->delete($url); |
111
|
|
|
|
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|