You are here

public function AcquiaLiftAPI::saveAutoTargetingRule in Acquia Lift Connector 7

Saves a targeting rule with automatic features to Acquia Lift for a particular agent.

Parameters

$agent_name: The name of the agent the rule is for.

$auto_features: The list of automatic targeting features to use.

File

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

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function saveAutoTargetingRule($agent_name, $auto_features) {
  $rule_name = $agent_name . '-auto-targeting';
  $url = $this
    ->generateEndpoint("/transform-rule");
  foreach ($auto_features as &$feature) {
    $feature = '#' . $feature;
  }
  $body = array(
    'code' => $rule_name,
    'status' => 1,
    'agents' => array(
      $agent_name,
    ),
    'when' => array(),
    'apply' => array(
      'feature' => implode(',', $auto_features),
    ),
  );
  $response = $this
    ->httpClient()
    ->post($url, array(
    'Content-Type' => 'application/json; charset=utf-8',
    'Accept' => 'application/json',
  ), $body);
  $vars = array(
    'agent' => $agent_name,
  );
  $success_msg = 'The targeting rule for campaign {agent} was saved successfully';
  $fail_msg = 'The targeting rule could not be saved for campaign {agent}';
  if ($response->code == 200) {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::INFO, $success_msg, $vars);
  }
  else {
    $this
      ->handleBadResponse($response->code, $fail_msg, $vars);
  }
}