You are here

public function AcquiaLiftAPI::getExistingAgents in Acquia Lift Connector 7

Retrieves a list of existing agents from Acquia Lift.

Return value

array An associative array whose keys are agent names and values are objects representing agents.

Throws

AcquiaLiftException

1 call to AcquiaLiftAPI::getExistingAgents()
AcquiaLiftAPI::ensureUniqueAgentName in includes/acquia_lift.classes.inc
Returns a unique agent name based on the name passed in.

File

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

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function getExistingAgents() {
  $url = $this
    ->generateEndpoint("/list-agents");
  $response = $this
    ->httpClient()
    ->get($url, array(
    'Accept' => 'application/json',
  ));
  if ($response->code == 200) {
    $response = json_decode($response->data, TRUE);
    if (!isset($response['data']['agents'])) {
      return array();
    }
    $existing_agents = array();
    foreach ($response['data']['agents'] as $agent) {
      $existing_agents[$agent['code']] = $agent;
    }
    return $existing_agents;
  }
  else {
    $this
      ->handleBadResponse($response->code, 'Error retrieving agent list from Acquia Lift');
  }
  return array();
}