You are here

class SalesforceIdentity in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Rest/SalesforceIdentity.php \Drupal\salesforce\Rest\SalesforceIdentity

Hierarchy

Expanded class hierarchy of SalesforceIdentity

2 files declare their use of SalesforceIdentity
SalesforceAuthProviderPluginBase.php in src/SalesforceAuthProviderPluginBase.php
SalesforceAuthTokenStorage.php in src/Storage/SalesforceAuthTokenStorage.php

File

src/Rest/SalesforceIdentity.php, line 7

Namespace

Drupal\salesforce\Rest
View source
class SalesforceIdentity implements SalesforceIdentityInterface {
  protected $data;

  /**
   * Handle the identity response from Salesforce.
   *
   * @param string $responseBody
   *   JSON identity response from Salesforce.
   *
   * @throws \OAuth\Common\Http\Exception\TokenResponseException
   *   If responseBody cannot be parsed, or contains an error.
   */
  public function __construct($responseBody) {
    $data = json_decode($responseBody, TRUE);
    if (NULL === $data || !is_array($data)) {
      throw new TokenResponseException('Unable to parse response.');
    }
    elseif (isset($data['error'])) {
      throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
    }
    $this->data = $data;
  }

  /**
   * Static creation method.
   *
   * @param array $data
   *   Data array.
   *
   * @return \Drupal\salesforce\Rest\SalesforceIdentity
   *   New identity.
   *
   * @throws \OAuth\Common\Http\Exception\TokenResponseException
   */
  public static function create(array $data) {
    return new static(json_encode($data));
  }

  /**
   * {@inheritdoc}
   */
  public function getUrl($api_type, $api_version = NULL) {
    if (empty($this->data['urls'][$api_type])) {
      return '';
    }
    $url = $this->data['urls'][$api_type];
    return $api_version ? str_replace('{version}', $api_version, $url) : $url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SalesforceIdentity::$data protected property
SalesforceIdentity::create public static function Static creation method.
SalesforceIdentity::getUrl public function Given API type and optional API version, return the API url. Overrides SalesforceIdentityInterface::getUrl
SalesforceIdentity::__construct public function Handle the identity response from Salesforce.