You are here

public function RestClient::getVersions in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 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

2 calls to RestClient::getVersions()
RestClient::getApiVersion in src/Rest/RestClient.php
Wrapper for config rest_api_version.version.
RestClient::setApiVersion in src/Rest/RestClient.php
Setter for config salesforce.settings rest_api_version and use_latest.

File

src/Rest/RestClient.php, line 606

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 = [];
  $id = $this
    ->getIdentity();
  if (!empty($id)) {
    $url = str_replace('v{version}/', '', $id['urls']['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;
  }
  else {
    return [];
  }
}