danielstokes/copper-bee

v0.3.4 2018-05-18 13:53 UTC

README

This is just a client that has multiple version of the rest api baked in, mainly to have static analysis hint in your code from phpstorm.

Install:

composer require danielstokes/copper-bee

Example:

//if you store this, be sure to encrypt it where it rests
$cache = json_decode(file_get_contents('salesforce.token.cache'));

//populate fields from cache, we could leave this blank, the client will refresh this same objects properties
$token = new \CopperBee\Salesforce\Token;
$token->instanceUrl = $cache->instanceUrl;
$token->accessToken = $cache->accessToken;
$token->tokenType   = $cache->tokenType;
$token->signature   = $cache->signature;
$token->id          = $cache->id;
$token->issuedAt    = $cache->issuedAt;
        
$config = new \CopperBee\Salesforce\Config;
//load config from environment
$config->instance      = getenv('SF_INSTANCE');
$config->clientId      = getenv('SF_CLIENT_ID');
$config->clientSecret  = getenv('SF_CLIENT_SECRET');
$config->user          = getenv('SF_USER');
$config->pass          = getenv('SF_PASS');
$config->securityToken = getenv('SF_SEC_TOKEN');

$api = new \CopperBee\Salesforce\Api($this->config, $this->token);
$apiVersion43 = $version->getVersion43();
$queryEndpoint = $apiVersion43->getQueryEndpoint();

$results = $queryEndpoint->query(\CopperBee\Salesforce\Endpoints\Query::compile('SELECT Id FROM Account WHERE Name = ? LIMIT 1', ['test']));

$results = $queryEndpoint->query(\CopperBee\Salesforce\Endpoints\Query::compile('SELECT Id FROM Account WHERE Name = $0 LIMIT 1', ['test']));

$results = $queryEndpoint->query(\CopperBee\Salesforce\Endpoints\Query::compile('SELECT Id FROM Account WHERE Name = :name LIMIT 1', ['name' => 'test']));

$results = $queryEndpoint->query(\CopperBee\Salesforce\Endpoints\Query::compile('SELECT Id FROM Account WHERE Name = @name LIMIT 1', ['name' => 'test']));

//consume the data...yum yum