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