You are here

public function RestClient::getVersions in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 src/Rest/RestClient.php \Drupal\salesforce\Rest\RestClient::getVersions()
  2. 5.0.x src/Rest/RestClient.php \Drupal\salesforce\Rest\RestClient::getVersions()

Wrapper for "Versions" resource to list information about API releases.

Parameters

bool $reset: Whether to reset cache.

Return value

array Array of all available Salesforce versions, or empty array if version info is not available.

Throws

\GuzzleHttp\Exception\RequestException

Overrides RestClientInterface::getVersions

File

src/Rest/RestClient.php, line 359

Class

RestClient
Objects, properties, and methods to communicate with the Salesforce REST API.

Namespace

Drupal\salesforce\Rest

Code

public function getVersions($reset = FALSE) {
  if (!$reset && ($cache = $this->cache
    ->get('salesforce:versions'))) {
    return $cache->data;
  }
  $versions = [];
  if (!$this->authProvider) {
    return [];
  }
  try {
    $id = $this->authProvider
      ->getIdentity();
  } catch (IdentityNotFoundException $e) {
    return [];
  }
  $url = str_replace('v{version}/', '', $id
    ->getUrl('rest'));
  $response = new RestResponse($this
    ->httpRequest($url));
  foreach ($response->data as $version) {
    $versions[$version['version']] = $version;
  }
  $this->cache
    ->set('salesforce:versions', $versions, $this
    ->getRequestTime() + self::LONGTERM_CACHE_LIFETIME, [
    'salesforce',
  ]);
  return $versions;
}