You are here

public function AcquiaLiftAPI::saveGoal in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 includes/AcquiaLiftAPI.inc \AcquiaLiftAPI::saveGoal()

Saves a goal for an agent.

Parameters

$agent_name: The agent the goal belongs to.

$goal_name: The name of the goal.

array $data: Array containing further information about the goal.

File

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

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function saveGoal($agent_name, $goal_name, $data = array()) {
  $url = $this
    ->generateEndpoint("/agent-api/{$agent_name}/goals/{$goal_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,
    'goalname' => $goal_name,
  );
  $success_msg = 'The goal {goalname} was pushed to the Acquia Lift campaign {agent}';
  $fail_msg = 'Could not save the goal {goalname} 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);
  }
}