You are here

public function AcquiaLiftAPI::hasAutoTargetingRule in Acquia Lift Connector 7

Returns whether or not a targeting rule exists for the given agent.

Parameters

$agent_name: The name of the agent to check.

Return value

bool TRUE if the specified agent has a targeting rule set up, FALSE otherwise.

File

includes/acquia_lift.classes.inc, line 987
Provides an agent type for Acquia Lift

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function hasAutoTargetingRule($agent_name) {
  $rule_name = $agent_name . '-auto-targeting';
  $url = $this
    ->generateEndpoint("/transforms-list");
  $response = $this
    ->httpClient()
    ->get($url, array(
    'Accept' => 'application/json',
  ));
  if ($response->code != 200) {
    $this
      ->handleBadResponse($response->code, 'Problem retrieving auto-targeting rules');
    return FALSE;
  }
  $response = json_decode($response->data, TRUE);
  if (!isset($response['data']) || !isset($response['data']['transforms'])) {
    return FALSE;
  }
  foreach ($response['data']['transforms'] as $rule) {
    if ($rule['code'] == $rule_name) {
      return TRUE;
    }
  }
  return FALSE;
}