Skip to content

Commit

Permalink
add view support for some api & update check point about nylas changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Sep 30, 2020
1 parent cf1f508 commit 6004fde
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 38 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: [Service Accounts Now Supported for EWS Mail](https://changelog.nylas.com/#entry-166883)
Last check at the point: [Scheduler Updates](https://changelog.nylas.com/#entry-167291)

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

Expand Down
4 changes: 2 additions & 2 deletions src/Calendars/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Calendar
{
Expand Down Expand Up @@ -50,7 +50,7 @@ public function getCalendarsList(array $params = []): array
$accessToken = $this->options->getAccessToken();

$rule = V::keySet(
V::keyOptional('view', V::in(['count', 'ids'])),
V::keyOptional('view', V::in(['ids', 'count'])),
V::keyOptional('limit', V::intType()->min(1)),
V::keyOptional('offset', V::intType()->min(0))
);
Expand Down
3 changes: 2 additions & 1 deletion src/Contacts/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @see https://docs.nylas.com/reference#contact-limitations
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Contact
{
Expand Down Expand Up @@ -296,6 +296,7 @@ private function pictureRules(): V
private function getBaseRules(): V
{
return V::keySet(
V::keyOptional('view', V::in(['ids', 'count'])),
V::keyOptional('limit', V::intType()->min(1)),
V::keyOptional('offset', V::intType()->min(0)),
V::keyOptional('email', V::email()),
Expand Down
4 changes: 2 additions & 2 deletions src/Deltas/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Delta
{
Expand Down Expand Up @@ -153,7 +153,7 @@ private function getBaseRules(): array
[
V::key('cursor', V::stringType()->notEmpty()),

V::keyOptional('view', V::stringType()->notEmpty()),
V::keyOptional('view', V::equals('expanded')),
V::keyOptional('exclude_types', V::in($types)),
V::keyOptional('include_types', V::in($types)),
];
Expand Down
49 changes: 38 additions & 11 deletions src/Drafts/Draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @info include inline image <img src="cid:file_id">
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Draft
{
Expand Down Expand Up @@ -43,29 +43,29 @@ public function __construct(Options $options)
/**
* get drafts list
*
* @param mixed $anyEmail string|string[]
* @param mixed $anyEmail string|string[]
* @param string $view ids|count
*
* @return array
*/
public function getDraftsList($anyEmail = null): array
public function getDraftsList($anyEmail = null, ?string $view = null): array
{
$params =['access_token' => $this->options->getAccessToken()];

if (!empty($anyEmail))
{
$params['any_email'] = Helper::fooToArray($anyEmail);
}
$params = [
'view' => $view,
'any_email' => Helper::fooToArray($anyEmail),
'access_token' => $this->options->getAccessToken(),
];

$rule = V::keySet(
V::key('access_token', V::stringType()->notEmpty()),
V::keyOptional('view', V::in(['ids', 'count'])),
V::keyOptional('any_email', V::simpleArray(V::email()))
);

V::doValidate($rule, $params);

$emails = \implode(',', ($params['any_email'] ?? []));
$query = $this->getListQuery($params);
$header = ['Authorization' => $params['access_token']];
$query = empty($emails) ? [] : ['any_email' => $emails];

return $this->options
->getSync()
Expand Down Expand Up @@ -269,6 +269,33 @@ private function getUpdateRules(): array

// ------------------------------------------------------------------------------

/**
* get list query conditions
*
* @param array $params
*
* @return array
*/
private function getListQuery(array $params): array
{
$query = [];
$emails = \implode(',', $params['any_email']);

if (!empty($params['view']))
{
$query['view'] = $params['view'];
}

if (!empty($emails))
{
$query['any_email'] = $emails;
}

return $query;
}

// ------------------------------------------------------------------------------

/**
* draft base validate rules
*
Expand Down
3 changes: 2 additions & 1 deletion src/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @see https://docs.nylas.com/reference#event-limitations
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Event
{
Expand Down Expand Up @@ -51,6 +51,7 @@ public function getEventsList(array $params = []): array
{
$rules = $this->getBaseRules();

$rules[] = V::keyOptional('view', V::in(['ids', 'count']));
$accessToken = $this->options->getAccessToken();

V::doValidate(V::keySet(...$rules), $params);
Expand Down
4 changes: 2 additions & 2 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class File
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public function getFilesList(array $params = []): array
$accessToken = $this->options->getAccessToken();

$rule = V::keySet(
V::keyOptional('view', V::in(['count', 'ids'])),
V::keyOptional('view', V::in(['ids', 'count'])),
V::keyOptional('filename', V::stringType()->notEmpty()),
V::keyOptional('message_id', V::stringType()->notEmpty()),
V::keyOptional('content_type', V::stringType()->notEmpty())
Expand Down
22 changes: 16 additions & 6 deletions src/Folders/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Folder
{
Expand Down Expand Up @@ -41,22 +41,32 @@ public function __construct(Options $options)
/**
* get folders list
*
* @param string $view ids|count
*
* @return array
*/
public function getFoldersList(): array
public function getFoldersList(?string $view = null): array
{
Helper::checkProviderUnit($this->options, false);

$rule = V::stringType()->notEmpty();
$params = [
'view' => $view,
'access_token' => $this->options->getAccessToken(),
];

$accessToken = $this->options->getAccessToken();
$rule = V::keySet(
V::key('access_token', V::stringType()->notEmpty()),
V::keyOptional('view', V::in(['ids', 'count'])),
);

V::doValidate($rule, $accessToken);
V::doValidate($rule, $params);

$header = ['Authorization' => $accessToken];
$header = ['Authorization' => $params['access_token']];
$query = empty($params['view']) ? [] : ['view' => $params['view']];

return $this->options
->getSync()
->setQuery($query)
->setHeaderParams($header)
->get(API::LIST['folders']);
}
Expand Down
22 changes: 16 additions & 6 deletions src/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Label
{
Expand Down Expand Up @@ -41,22 +41,32 @@ public function __construct(Options $options)
/**
* get labels list
*
* @param string $view ids|count
*
* @return array
*/
public function getLabelsList(): array
public function getLabelsList(?string $view = null): array
{
Helper::checkProviderUnit($this->options, true);

$accessToken = $this->options->getAccessToken();
$params = [
'view' => $view,
'access_token' => $this->options->getAccessToken(),
];

$rule = V::stringType()->notEmpty();
$rule = V::keySet(
V::key('access_token', V::stringType()->notEmpty()),
V::keyOptional('view', V::in(['ids', 'count'])),
);

V::doValidate($rule, $accessToken);
V::doValidate($rule, $params);

$header = ['Authorization' => $accessToken];
$header = ['Authorization' => $params['access_token']];
$query = empty($params['view']) ? [] : ['view' => $params['view']];

return $this->options
->getSync()
->setQuery($query)
->setHeaderParams($header)
->get(API::LIST['labels']);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Messages/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @info include inline image <img src="cid:file_id">
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class Message
{
Expand Down Expand Up @@ -149,10 +149,11 @@ public function updateMessage(array $params): array
* get message info
*
* @param mixed $messageId string|string[]
* @param bool $expanded true|false
*
* @return array
*/
public function getMessage($messageId): array
public function getMessage($messageId, bool $expanded = false): array
{
$messageId = Helper::fooToArray($messageId);
$accessToken = $this->options->getAccessToken();
Expand All @@ -165,12 +166,14 @@ public function getMessage($messageId): array
$queues = [];
$target = API::LIST['oneMessage'];
$header = ['Authorization' => $accessToken];
$query = $expanded ? ['view' => 'expanded'] : [];

foreach ($messageId as $id)
{
$request = $this->options
->getAsync()
->setPath($id)
->setQuery($query)
->setHeaderParams($header);

$queues[] = static function () use ($request, $target)
Expand Down
7 changes: 5 additions & 2 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/21
* @change 2020/09/30
*/
trait AbsBase
{
Expand Down Expand Up @@ -104,7 +104,10 @@ public function setQuery(array $query) : self
{
$query = Helper::boolToString($query);

$this->queryParams = ['query' => $query];
if (!empty($query))
{
$this->queryParams = ['query' => $query];
}

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
* @see https://changelog.nylas.com/
* @see https://docs.nylas.com/reference#api-changelog
*
* @version 2.1 (2020/04/27)
* @version 2.1 (2020/09/30)
*
* @author lanlin
* @change 2020/04/26
* @change 2020/09/30
*/
class API
{
Expand Down

0 comments on commit 6004fde

Please sign in to comment.