public function DataApi::getSegments in Acquia Lift Connector 8
Fetches the available Segment IDs from Acquia Lift
Return value
array An array of segment IDs that can be used for targeting.
Overrides DataApiInterface::getSegments
File
- src/
Service/ Api/ DataApi.php, line 177 - Contains \Drupal\acquia_lift\Service\Api\DataApi.
Class
Namespace
Drupal\acquia_lift\Service\ApiCode
public function getSegments() {
// First get our Authorization header.
$headers = [
'Accept' => 'application/json',
];
$url = $this
->generateEndpoint('segments');
$auth_header = $this
->getAuthHeader('GET', $url, [], $headers);
$headers += [
'Authorization' => $auth_header,
];
$request = new Request('GET', $url, $headers);
$response = $this->httpClient
->send($request);
$data = $response
->getBody();
if (empty($data)) {
return [];
}
$data = json_decode($data, TRUE);
if (is_array($data)) {
$segments = array_values(array_filter($data));
return $segments;
}
return [];
}