Skip to content

Commit

Permalink
fix get stream
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Dec 8, 2020
1 parent e357a82 commit 1484c73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
PHP bindings for the Nylas REST API (V2.1). https://docs.nylas.com/reference</br>
I'll try to keep up with [NyLas Changelog](https://changelog.nylas.com) in future updates.

Last check at the point: [Scheduler Updates](https://changelog.nylas.com/#entry-167291)
Last check at the point: [Dashboard Release for Canada and Ireland](https://changelog.nylas.com/#entry-176451)

**What's new?**</br>

Expand Down
6 changes: 3 additions & 3 deletions src/Request/AbsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/09/30
* @change 2020/12/08
*/
trait AbsBase
{
Expand Down Expand Up @@ -291,15 +291,15 @@ private function parseResponse(ResponseInterface $response, bool $headers = fals
$expc = 'application/json';
$code = $response->getStatusCode();
$type = $response->getHeader('Content-Type');
$data = $response->getBody()->getContents();

// when not json type
if (strpos(strtolower(current($type)), $expc) === false)
{
return $this->concatForInvalidJsonData($type, $code, $response->getBody());
return $this->concatForInvalidJsonData($type, $code, $data);
}

// decode json data
$data = $response->getBody()->getContents();
$temp = json_decode(trim(utf8_encode($data)), true, 512);
$errs = JSON_ERROR_NONE !== json_last_error();

Expand Down
10 changes: 4 additions & 6 deletions src/Request/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/06/22
* @change 2020/12/08
*/
class Sync
{
Expand Down Expand Up @@ -143,24 +143,22 @@ public function delete(string $api)
*
* @throws Exception
*
* @return \Psr\Http\Message\ResponseInterface
* @return \Psr\Http\Message\StreamInterface
*/
public function getStream(string $api): \Psr\Http\Message\ResponseInterface
public function getStream(string $api): \Psr\Http\Message\StreamInterface
{
$apiPath = $this->concatApiPath($api);
$options = $this->concatOptions();
$options = \array_merge($options, ['stream' => true]);

try
{
$response = $this->guzzle->get($apiPath, $options);
return $this->guzzle->get($apiPath, $options)->getBody();
}
catch (Exception $e)
{
throw new NylasException($e);
}

return $this->parseResponse($response, false);
}

// ------------------------------------------------------------------------------
Expand Down

0 comments on commit 1484c73

Please sign in to comment.