Skip to content

Commit

Permalink
Merge pull request #4 from ctriv/add-getpath
Browse files Browse the repository at this point in the history
Add getPath method.
  • Loading branch information
adrian-enspired authored May 3, 2021
2 parents 584271a + c2515a9 commit 423a84b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use bjsmasth\Salesforce\Exception\Salesforce as SalesforceException;
use Psr\Http\Message\StreamInterface;

class CRUD
{
Expand All @@ -22,9 +23,19 @@ public function __construct()
$this->access_token = $_SESSION['salesforce']['access_token'];
}

public function getApiBaseUrl()
{
return $this->instance_url;
}

public function getApiPath()
{
return "/services/data/" . self::API_VERSION;
}

public function getApiUrl()
{
return "{$this->instance_url}/services/data/" . self::API_VERSION;
return $this->getApiBaseUrl() . $this->getApiPath();
}

public function query($query)
Expand Down Expand Up @@ -59,6 +70,19 @@ public function get($object, $field, $id)
return json_decode($request->getBody(), true);
}

public function streamPath($path) : StreamInterface {
$url = $this->getApiBaseUrl() . $path;
$client = new Client();

$request = $client->request('GET', $url, [
'headers' => [
'Authorization' => "OAuth {$this->access_token}",
]
]);

return $request->getBody();
}

public function create($object, array $data)
{
$url = "{$this->getApiUrl()}/sobjects/{$object}/";
Expand Down

0 comments on commit 423a84b

Please sign in to comment.