You are here

public function AcquiaLiftAPI::saveDecision in Acquia Lift Connector 7

Saves a decision for an agent.

Parameters

$agent_name: The name of the agent the decision belongs to.

$point: The name of the decision point that the decision belongs to.

$decision_name: The name of the decision to save.

File

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

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function saveDecision($agent_name, $point_name, $decision_name, $data = array()) {
  $url = $this
    ->generateEndpoint("/agent-api/{$agent_name}/points/{$point_name}/decisions/{$decision_name}");
  $response = $this
    ->httpClient()
    ->put($url, array(
    'Content-Type' => 'application/json; charset=utf-8',
    'Accept' => 'application/json',
  ), $data);
  $data = json_decode($response->data, TRUE);
  $vars = array(
    'agent' => $agent_name,
    'decpoint' => $point_name,
    'decname' => $decision_name,
  );
  $success_msg = 'The decision {decname} for point {decpoint} was pushed to the Acquia Lift campaign {agent}';
  $fail_msg = 'Could not save decision {decname} for point {decpoint} to the Acquia Lift campaign {agent}';
  if ($response->code == 200 && $data['status'] == 'ok') {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::INFO, $success_msg, $vars);
  }
  else {
    $this
      ->handleBadResponse($response->code, $fail_msg, $vars);
  }
}