You are here

protected function DummyAcquiaLiftHttpClient::getDataForURI in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 tests/acquia_lift.test_classes.inc \DummyAcquiaLiftHttpClient::getDataForURI()

Returns the expected data array for a given uri.

Parameters

string $uri: An absolute url for an API endpoint, e.g. http://example.com/owner-code/list-agents

Return value

array An array of data to be returned in the response.

1 call to DummyAcquiaLiftHttpClient::getDataForURI()
DummyAcquiaLiftHttpClient::get in tests/acquia_lift.test_classes.inc
Implements AcquiaLiftDrupalHttpClientInterface::get().

File

tests/acquia_lift.test_classes.inc, line 129
Provides test classes for Acquia Lift

Class

DummyAcquiaLiftHttpClient
Classes used for testing.

Code

protected function getDataForURI($uri, $headers = array()) {
  $parsed = parse_url($uri);
  $path_parts = explode('/', $parsed['path']);

  // The first element of the $path_parts array will be an empty string.
  $path_parts = array_slice($path_parts, 1);
  switch ($path_parts[0]) {
    case 'campaigns':
      if (isset($this->data['campaigns'])) {
        return $this->data['campaigns'];
      }
      if (isset($this->data['error'])) {
        return $this->data['error'];
      }
      return array();
    case 'report':
      $query_params = explode('&', $parsed['query']);
      $first_param = explode('=', reset($query_params));
      if ($first_param[0] !== 'campaign_id') {
        return array();
      }
      $agent_name = $first_param[1];
      return isset($this->data['reports'][$agent_name]) ? $this->data['reports'][$agent_name] : array();
    case 'ping':
      return array(
        'message' => 'pong!',
      );
      break;
  }
  return array();
}