public function ALProfilesAPI::getSegments in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 acquia_lift_profiles/includes/acquia_lift_profiles.classes.inc \ALProfilesAPI::getSegments()
Fetches the available Segment IDs from Acquia Lift Profiles
Return value
array An array of segment IDs that can be used for targeting.
File
- acquia_lift_profiles/
includes/ acquia_lift_profiles.classes.inc, line 304 - Provides an agent type for Acquia Lift Profiles
Class
- ALProfilesAPI
- @file Provides an agent type for Acquia Lift Profiles
Code
public function getSegments() {
// First get our Authorization header.
$headers = array(
'Accept' => 'application/json',
);
$url = $this
->generateEndpoint('segments');
$params = array();
if (!empty($this->customerSite)) {
$params['customerSite'] = $this->customerSite;
}
$auth_header = $this
->getAuthHeader('GET', $url, $params, $headers);
$headers += array(
'Authorization' => $auth_header,
);
$querystring = empty($this->customerSite) ? '' : '?customerSite=' . rawurlencode($this->customerSite);
$response = $this
->httpClient()
->get($url . $querystring, $headers);
if ($response->code != 200 || !isset($response->data)) {
if ($response->code != 200) {
$vars = array(
'rest_api_status' => $response->code,
'rest_api_status_line' => $response->status_message,
);
$fail_msg_template = 'Could not get segments from Acquia Lift Profiles "{rest_api_status} {rest_api_status_line}"';
$this
->logger()
->log(PersonalizeLogLevel::ERROR, $fail_msg_template, $vars);
$fail_msg = str_replace(array(
'{rest_api_status}',
'{rest_api_status_line}',
), array(
$vars['rest_api_status'],
$vars['rest_api_status_line'],
), $fail_msg_template);
throw new ALProfilesException($fail_msg);
}
return array();
}
$data = json_decode($response->data, TRUE);
if (is_array($data)) {
$segments = array_values(array_filter($data));
return $segments;
}
return array();
}