From 5585786d6f9024a37070fe36cf5023593a8e839d Mon Sep 17 00:00:00 2001 From: Chris Reinhardt Date: Thu, 29 Apr 2021 14:37:33 -0400 Subject: [PATCH 1/2] Add getPath method. --- src/CRUD.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/CRUD.php b/src/CRUD.php index 1386272..b35eb6e 100644 --- a/src/CRUD.php +++ b/src/CRUD.php @@ -22,9 +22,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) @@ -59,6 +69,20 @@ public function get($object, $field, $id) return json_decode($request->getBody(), true); } + public function getPath($path) + { + $url = $this->getApiBaseUrl() . $path; + $client = new Client(); + + $request = $client->request('GET', $url, [ + 'headers' => [ + 'Authorization' => "OAuth {$this->access_token}", + ] + ]); + + return $request->getBody()->getContents(); + } + public function create($object, array $data) { $url = "{$this->getApiUrl()}/sobjects/{$object}/"; From c2515a965f4a4bb1adb447b4b0e3ab118f3e68bf Mon Sep 17 00:00:00 2001 From: Chris Reinhardt Date: Fri, 30 Apr 2021 17:45:37 -0400 Subject: [PATCH 2/2] Change to stream appoarch. --- src/CRUD.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CRUD.php b/src/CRUD.php index b35eb6e..ecacc9c 100644 --- a/src/CRUD.php +++ b/src/CRUD.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client; use bjsmasth\Salesforce\Exception\Salesforce as SalesforceException; +use Psr\Http\Message\StreamInterface; class CRUD { @@ -69,8 +70,7 @@ public function get($object, $field, $id) return json_decode($request->getBody(), true); } - public function getPath($path) - { + public function streamPath($path) : StreamInterface { $url = $this->getApiBaseUrl() . $path; $client = new Client(); @@ -80,7 +80,7 @@ public function getPath($path) ] ]); - return $request->getBody()->getContents(); + return $request->getBody(); } public function create($object, array $data)