SalesforceIdentity.php in Salesforce Suite 8.4
File
src/Rest/SalesforceIdentity.php
View source
<?php
namespace Drupal\salesforce\Rest;
use OAuth\Common\Http\Exception\TokenResponseException;
class SalesforceIdentity implements SalesforceIdentityInterface {
protected $data;
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;
}
public static function create(array $data) {
return new static(json_encode($data));
}
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;
}
}