class RestClient in Salesforce Suite 8.3
Same name in this branch
- 8.3 src/Rest/RestClient.php \Drupal\salesforce\Rest\RestClient
- 8.3 modules/salesforce_encrypt/src/Rest/RestClient.php \Drupal\salesforce_encrypt\Rest\RestClient
Objects, properties, and methods to communicate with the Salesforce REST API.
Hierarchy
- class \Drupal\salesforce\Rest\RestClient implements RestClientInterface
- class \Drupal\salesforce_encrypt\Rest\RestClient implements EncryptedRestClientInterface uses StringTranslationTrait
Expanded class hierarchy of RestClient
Deprecated
salesforce_encrypt is deprecated and will be removed in 8.x-4.0. Please see change record https://www.drupal.org/node/3034230 for additional information.
2 files declare their use of RestClient
- RestClientTest.php in modules/
salesforce_encrypt/ tests/ src/ Unit/ RestClientTest.php - SalesforceEncryptServiceProvider.php in modules/
salesforce_encrypt/ src/ SalesforceEncryptServiceProvider.php
File
- modules/
salesforce_encrypt/ src/ Rest/ RestClient.php, line 25
Namespace
Drupal\salesforce_encrypt\RestView source
class RestClient extends SalesforceRestClient implements EncryptedRestClientInterface {
use StringTranslationTrait;
/**
* Encryption service.
*
* @var \Drupal\encrypt\EncryptServiceInterface
*/
protected $encryption;
/**
* Encryption profile manager.
*
* @var \Drupal\encrypt\EncryptionProfileManagerInterface
*/
protected $encryptionProfileManager;
/**
* The active encryption profile id.
*
* @var string
*/
protected $encryptionProfileId;
/**
* The encryption profile to use when encrypting and decrypting data.
*
* @var \Drupal\encrypt\EncryptionProfileInterface
*/
protected $encryptionProfile;
/**
* Construct a new Encrypted Rest Client.
*
* @param \GuzzleHttp\ClientInterface $http_client
* The GuzzleHttp Client.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache service.
* @param \Drupal\Component\Serialization\Json $json
* The JSON serializer service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The Time service.
* @param \Drupal\encrypt\EncryptServiceInterface $encryption
* The encryption service.
* @param \Drupal\encrypt\EncryptionProfileManagerInterface $encryptionProfileManager
* The Encryption profile manager service.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend service.
*
* @deprecated salesforce_encrypt is deprecated and will be removed in 8.x-4.0. Please see change record https://www.drupal.org/node/3034230 for additional information.
*/
public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, StateInterface $state, CacheBackendInterface $cache, Json $json, TimeInterface $time, EncryptServiceInterface $encryption, EncryptionProfileManagerInterface $encryptionProfileManager, LockBackendInterface $lock) {
parent::__construct($http_client, $config_factory, $state, $cache, $json, $time);
$this->encryption = $encryption;
$this->encryptionProfileId = $this->state
->get('salesforce_encrypt.profile');
$this->encryptionProfileManager = $encryptionProfileManager;
$this->encryptionProfile = NULL;
$this->lock = $lock;
}
/**
* {@inheritdoc}
*/
public function enableEncryption(EncryptionProfileInterface $profile) {
if ($ret = $this
->setEncryption($profile)) {
$this->state
->resetCache();
}
return $ret;
}
/**
* {@inheritdoc}
*/
public function disableEncryption() {
if ($ret = $this
->setEncryption()) {
$this->state
->resetCache();
}
return $ret;
}
/**
* {@inheritdoc}
*/
public function hookEncryptionProfileDelete(EncryptionProfileInterface $profile) {
if ($this->encryptionProfileId == $profile
->id()) {
$this
->disableEncryption();
}
}
/**
* Set the given encryption profile as active.
*
* If given profile is null, decrypt and disable encryption.
*
* @param \Drupal\encrypt\EncryptionProfileInterface|null $profile
* The encryption profile. If null, encryption will be disabled.
*/
protected function setEncryption(EncryptionProfileInterface $profile = NULL) {
if (!$this->lock
->acquire('salesforce_encrypt')) {
throw new \RuntimeException('Unable to acquire lock.');
}
$access_token = $this
->getAccessToken();
$refresh_token = $this
->getRefreshToken();
$identity = $this
->getIdentity();
$consumerKey = $this
->getConsumerKey();
$consumerSecret = $this
->getConsumerSecret();
$this->encryptionProfileId = $profile == NULL ? NULL : $profile
->id();
$this->encryptionProfile = $profile;
$this->state
->set('salesforce_encrypt.profile', $this->encryptionProfileId);
$this
->setAccessToken($access_token);
$this
->setRefreshToken($refresh_token);
$this
->setIdentity($identity);
$this
->setConsumerKey($consumerKey);
$this
->setConsumerSecret($consumerSecret);
$this->lock
->release('salesforce_encrypt');
}
/**
* {@inheritdoc}
*/
public function getEncryptionProfile() {
if ($this->encryptionProfile) {
return $this->encryptionProfile;
}
elseif (empty($this->encryptionProfileId)) {
return NULL;
}
else {
$this->encryptionProfile = $this->encryptionProfileManager
->getEncryptionProfile($this->encryptionProfileId);
if (empty($this->encryptionProfile)) {
throw new EntityNotFoundException([
'id' => $this->encryptionProfileId,
], 'encryption_profile');
}
return $this->encryptionProfile;
}
}
/**
* Deprecated, use doGetEncryptionProfile.
*
* @deprecated use ::doGetEncryptionProfile().
*/
protected function _getEncryptionProfile() {
return $this
->doGetEncryptionProfile();
}
/**
* Exception-handling wrapper around getEncryptionProfile().
*
* GetEncryptionProfile() will throw an EntityNotFoundException exception
* if it has an encryption profile ID but cannot load it. In this wrapper
* we handle that exception by setting a helpful error message and allow
* execution to proceed.
*
* @return \Drupal\encrypt\EncryptionProfileInterface|null
* The encryption profile if it can be loaded, otherwise NULL.
*/
protected function doGetEncryptionProfile() {
try {
$profile = $this
->getEncryptionProfile();
} catch (EntityNotFoundException $e) {
drupal_set_message($this
->t('Error while loading encryption profile. You will need to <a href=":encrypt">assign a new encryption profile</a>, then <a href=":oauth">re-authenticate to Salesforce</a>.', [
':encrypt' => Url::fromRoute('salesforce_encrypt.settings')
->toString(),
':oauth' => Url::fromRoute('salesforce.authorize')
->toString(),
]), 'error');
}
return $profile;
}
/**
* {@inheritdoc}
*/
public function encrypt($value) {
if (empty($this
->doGetEncryptionProfile())) {
return $value;
}
else {
return $this->encryption
->encrypt($value, $this
->doGetEncryptionProfile());
}
}
/**
* {@inheritdoc}
*/
public function decrypt($value) {
if (empty($this
->doGetEncryptionProfile()) || empty($value) || mb_strlen($value) === 0) {
return $value;
}
else {
return $this->encryption
->decrypt($value, $this
->doGetEncryptionProfile());
}
}
/**
* {@inheritdoc}
*/
public function getAccessToken() {
return $this
->decrypt(parent::getAccessToken());
}
/**
* {@inheritdoc}
*/
public function setAccessToken($token) {
return parent::setAccessToken($this
->encrypt($token));
}
/**
* {@inheritdoc}
*/
public function getRefreshToken() {
return $this
->decrypt(parent::getRefreshToken());
}
/**
* {@inheritdoc}
*/
public function setRefreshToken($token) {
return parent::setRefreshToken($this
->encrypt($token));
}
/**
* {@inheritdoc}
*/
public function setIdentity($data) {
if (is_array($data)) {
$data = serialize($data);
}
return parent::setIdentity($this
->encrypt($data));
}
/**
* {@inheritdoc}
*/
public function getIdentity() {
$data = $this
->decrypt(parent::getIdentity());
if (!empty($data) && !is_array($data)) {
$data = unserialize($data);
}
return $data;
}
/**
* {@inheritdoc}
*/
public function getConsumerKey() {
return $this
->decrypt(parent::getConsumerKey());
}
/**
* {@inheritdoc}
*/
public function setConsumerKey($value) {
return parent::setConsumerKey($this
->encrypt($value));
}
/**
* {@inheritdoc}
*/
public function getConsumerSecret() {
return $this
->decrypt(parent::getConsumerSecret());
}
/**
* {@inheritdoc}
*/
public function setConsumerSecret($value) {
return parent::setConsumerSecret($this
->encrypt($value));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RestClient:: |
protected | property | The cache service. | |
RestClient:: |
protected | property | Config factory service. | |
RestClient:: |
protected | property | Encryption service. | |
RestClient:: |
protected | property | The encryption profile to use when encrypting and decrypting data. | |
RestClient:: |
protected | property | The active encryption profile id. | |
RestClient:: |
protected | property | Encryption profile manager. | |
RestClient:: |
protected | property | GuzzleHttp client. | |
RestClient:: |
protected | property | ||
RestClient:: |
protected | property | Salesforce immutable config object. Useful for gets. | |
RestClient:: |
protected | property | The JSON serializer service. | |
RestClient:: |
protected | property | Salesforce mutable config object. Useful for sets. | |
RestClient:: |
public | property | Response object. | |
RestClient:: |
protected | property | The state service. | |
RestClient:: |
private | property | Token storage. | |
RestClient:: |
protected | property | Salesforce API URL. | |
RestClient:: |
public | function |
Make a call to the Salesforce REST API. Overrides RestClientInterface:: |
1 |
RestClient:: |
protected | function | Private helper to issue an SF API request. | |
RestClient:: |
constant | |||
RestClient:: |
public | function |
Decrypts a value using active encryption profile, or return the same value. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
public | function |
Decrypt and re-save sensitive salesforce config values. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
protected | function | Exception-handling wrapper around getEncryptionProfile(). | |
RestClient:: |
public | function |
Encrypts all sensitive salesforce config values. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
public | function |
Encrypts a value using the active encryption profile, or return plaintext. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
public | function |
Get the access token. Overrides RestClient:: |
|
RestClient:: |
public | function |
Get the API end point for a given type of the API. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Get the api usage, as returned in the most recent API request header. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Wrapper for config rest_api_version.version. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Helper to build the redirect URL for OAUTH workflow. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Get Salesforce oauth login endpoint. (OAuth step 1) Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Get Salesforce oauth token endpoint. (OAuth step 2) Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Consumer key getter. Overrides RestClient:: |
|
RestClient:: |
public | function |
Comsumer secret getter. Overrides RestClient:: |
|
RestClient:: |
public | function |
Retrieves objects deleted within the given timeframe. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Returns the EncryptionProfileInterface assigned to Salesforce Encrypt. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
protected | function | Extract normalized error information from a RequestException. | |
RestClient:: |
public | function |
Getter for a single, named HTTP client option. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Getter for HTTP client options. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Return the Salesforce identity, which is stored in a variable. Overrides RestClient:: |
|
RestClient:: |
public | function |
Get the SF instance URL. Useful for linking to objects. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Login url getter. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Utility function to determine object type for given SFID. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Given a DeveloperName and SObject Name, return SFID of the RecordType. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Retrieve all record types for this org. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Get refresh token. Overrides RestClient:: |
|
RestClient:: |
protected | function | Returns REQUEST_TIME. | |
RestClient:: |
public | function |
Return a list of SFIDs for the given object for the given timeframe. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Wrapper for "Versions" resource to list information about API releases. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Helper callback for OAuth handshake, and refreshToken() Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
If the given profile is our active one, disable encryption. Overrides EncryptedRestClientInterface:: |
|
RestClient:: |
protected | function | Make the HTTP request. Wrapper around drupal_http_request(). | |
RestClient:: |
public | function |
Return raw response content from given URL. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Retrieve and store the Salesforce identity given an ID url. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Determine if this SF instance is fully configured. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Return a list of available resources for the configured API version. Overrides RestClientInterface:: |
1 |
RestClient:: |
constant | |||
RestClient:: |
public | function |
Create a new object of the given type. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Delete a Salesforce object. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Retrieve all the metadata for an object. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Return a fullly loaded Salesforce object. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Return a full loaded Salesforce object from External ID. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Available objects and their metadata for your organization's data. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Update an existing object. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Create new records or update existing records. Overrides RestClientInterface:: |
1 |
RestClient:: |
public | function |
Use SOQL to get objects based on query string. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Same as ::query(), but also returns deleted or archived records. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Given a select query result, fetch the next results set, if it exists. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Refresh access token based on the refresh token. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the access token. Overrides RestClient:: |
|
RestClient:: |
public | function |
Setter for config salesforce.settings rest_api_version and use_latest. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Consumer key setter. Overrides RestClient:: |
|
RestClient:: |
public | function |
Consumer key setter. Overrides RestClient:: |
|
RestClient:: |
protected | function | Set the given encryption profile as active. | |
RestClient:: |
public | function |
Set a single Guzzle HTTP client option. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set options for Guzzle HTTP client. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the Salesforce identity, which is stored in a variable. Overrides RestClient:: |
|
RestClient:: |
public | function |
Set the SF instance URL. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Login url setter. Overrides RestClientInterface:: |
|
RestClient:: |
public | function |
Set the refresh token. Overrides RestClient:: |
|
RestClient:: |
private | function | Storage helper. | |
RestClient:: |
protected | function | Helper to extract API Usage info from response header and write to state. | |
RestClient:: |
protected | function | Deprecated, use doGetEncryptionProfile. | |
RestClient:: |
public | function |
Construct a new Encrypted Rest Client. Overrides RestClient:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |