1 | <?php |
||
18 | class Lift extends Client |
||
19 | { |
||
20 | /** |
||
21 | * @var \NickVeenhof\Hmac\KeyInterface A sample key |
||
22 | */ |
||
23 | protected $authKey; |
||
24 | |||
25 | /** |
||
26 | * @var string The account we are using |
||
27 | */ |
||
28 | protected $accountId; |
||
29 | |||
30 | /** |
||
31 | * @var string The site identifier we are using |
||
32 | */ |
||
33 | protected $siteId; |
||
34 | |||
35 | /** |
||
36 | * Overrides \GuzzleHttp\Client::__construct(). |
||
37 | * |
||
38 | * @param string $account_id The Lift Web Account Identifier. Eg.: MYACCOUNT |
||
39 | * @param string $site_id The Lift Web Site Identifier. Eg.: my-drupal-site |
||
40 | * @param string $public_key The Lift Web Public Key. Not all API keys have |
||
41 | * the same permissions so be mindful which key |
||
42 | * you are using |
||
43 | * @param string $secret_key The Lift Web Secret Key belonging to the Public |
||
44 | * Key |
||
45 | * @param array $config |
||
46 | */ |
||
47 | 99 | public function __construct( |
|
48 | $account_id, |
||
49 | $site_id, |
||
50 | $public_key, |
||
51 | $secret_key, |
||
52 | array $config = [] |
||
53 | ) { |
||
54 | // "base_url" parameter changed to "base_uri" in Guzzle6, so the following line |
||
55 | // is there to make sure it does not disrupt previous configuration. |
||
56 | 99 | if (!isset($config['base_uri']) && isset($config['base_url'])) { |
|
57 | $config['base_uri'] = $config['base_url']; |
||
58 | } |
||
59 | |||
60 | // Setting up the headers. |
||
61 | 99 | $config['headers']['Content-Type'] = 'application/json'; |
|
62 | |||
63 | // A key consists of your UUID and a MIME base64 encoded shared secret. |
||
64 | 99 | $this->authKey = new Key($public_key, $secret_key); |
|
65 | |||
66 | 99 | $this->accountId = $account_id; |
|
67 | 99 | $this->siteId = $site_id; |
|
68 | |||
69 | // Set our default HandlerStack if nothing is provided |
||
70 | 99 | if (!isset($config['handler'])) { |
|
71 | $config['handler'] = HandlerStack::create(); |
||
72 | } |
||
73 | |||
74 | // Add our Account and Site identifiers. |
||
75 | 99 | $config['handler']->push($this->addLiftAccountAndSiteId()); |
|
76 | |||
77 | 99 | if (isset($config['auth_middleware'])) { |
|
78 | 99 | if ($config['auth_middleware'] !== false) { |
|
79 | 33 | $config['handler']->push($config['auth_middleware']); |
|
80 | } |
||
81 | 66 | } else { |
|
82 | $middleware = new HmacAuthMiddleware($this->authKey, 'Decision'); |
||
83 | $config['handler']->push($middleware); |
||
84 | } |
||
85 | |||
86 | 99 | parent::__construct($config); |
|
87 | 99 | } |
|
88 | |||
89 | 99 | public function addLiftAccountAndSiteId() |
|
117 | |||
118 | /** |
||
119 | * Pings the service to ensure that it is available. |
||
120 | * |
||
121 | * @return \Psr\Http\Message\ResponseInterface |
||
122 | * |
||
123 | * @throws \GuzzleHttp\Exception\RequestException |
||
124 | */ |
||
125 | 3 | public function ping() |
|
132 | |||
133 | /** |
||
134 | * Get the Slot Manager. |
||
135 | * |
||
136 | * @return \Acquia\LiftClient\Manager\SlotManager |
||
137 | */ |
||
138 | 24 | public function getSlotManager() |
|
142 | |||
143 | /** |
||
144 | * Get the Slot Manager. |
||
145 | * |
||
146 | * @return \Acquia\LiftClient\Manager\GoalManager |
||
147 | */ |
||
148 | 27 | public function getGoalManager() |
|
152 | |||
153 | /** |
||
154 | * Get the Segment Manager. |
||
155 | * |
||
156 | * @return \Acquia\LiftClient\Manager\SegmentManager |
||
157 | */ |
||
158 | 6 | public function getSegmentManager() |
|
162 | |||
163 | /** |
||
164 | * Get the Rules Manager. |
||
165 | * |
||
166 | * @return \Acquia\LiftClient\Manager\RuleManager |
||
167 | */ |
||
168 | 24 | public function getRuleManager() |
|
172 | |||
173 | /** |
||
174 | * Get the Capture Manager. |
||
175 | * |
||
176 | * @return \Acquia\LiftClient\Manager\CaptureManager |
||
177 | */ |
||
178 | 9 | public function getCaptureManager() |
|
182 | |||
183 | /** |
||
184 | * Get the Decide Manager. |
||
185 | * |
||
186 | * @return \Acquia\LiftClient\Manager\DecideManager |
||
187 | */ |
||
188 | 6 | public function getDecideManager() |
|
192 | |||
193 | /** |
||
194 | * Make the given Request and return as JSON Decoded PHP object. |
||
195 | * |
||
196 | * @param RequestInterface $request |
||
197 | * |
||
198 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
199 | * PHP type. Values true, false and |
||
200 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
||
201 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
||
202 | * <i>json</i> cannot be decoded or if the encoded |
||
203 | * data is deeper than the recursion limit |
||
204 | * |
||
205 | * @throws \GuzzleHttp\Exception\RequestException |
||
206 | */ |
||
207 | 81 | public function getResponseJson(RequestInterface $request) |
|
214 | } |
||
215 |