Skip to content

Commit

Permalink
STAM-2460
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Nov 27, 2018
1 parent cd42261 commit a3b27a7
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 140 deletions.
5 changes: 4 additions & 1 deletion src/Accounts/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function getAccount(string $accessToken = null)

$header = ['Authorization' => $accessToken];

return $this->options->getRequest()->setHeaderParams($header)->get(API::LIST['account']);
return $this->options
->getRequest()
->setHeaderParams($header)
->get(API::LIST['account']);
}

// ------------------------------------------------------------------------------
Expand Down
5 changes: 1 addition & 4 deletions src/Accounts/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(Options $options)
* @return mixed
* @throws \Nylas\Exceptions\NylasException
*/
public function getAccountsList(array $params)
public function getAccountsList(array $params = [])
{
$rules = V::keySet(
V::key('limit', V::intType()::min(1), false),
Expand Down Expand Up @@ -81,7 +81,6 @@ public function getAccountsList(array $params)
*
* @param string $accountId
* @return mixed
* @throws \Nylas\Exceptions\NylasException
*/
public function getAccountInfo(string $accountId = null)
{
Expand All @@ -105,7 +104,6 @@ public function getAccountInfo(string $accountId = null)
*
* @param string $accountId
* @return mixed
* @throws \Nylas\Exceptions\NylasException
*/
public function reactiveAccount(string $accountId = null)
{
Expand All @@ -129,7 +127,6 @@ public function reactiveAccount(string $accountId = null)
*
* @param string $accountId
* @return mixed
* @throws \Nylas\Exceptions\NylasException
*/
public function cancelAccount(string $accountId = null)
{
Expand Down
20 changes: 15 additions & 5 deletions src/Authentication/Hosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ public function __construct(Options $options)
*/
public function getOAuthAuthorize(array $params)
{
$params['client_id'] = $this->options->getClientApps()['client_id'];

$rules = V::keySet(
V::key('login_hint', V::email()),
V::key('redirect_uri', V::url()),
V::key('client_id', V::stringType()::notEmpty()),
V::key('state', V::stringType()::length(1, 255), false)
);

Expand All @@ -57,8 +60,6 @@ public function getOAuthAuthorize(array $params)
throw new NylasException('invalid params');
}

$params['client_id'] = $this->options->getClientApps()['client_id'];

$query =
[
'scope' => 'email',
Expand All @@ -67,7 +68,10 @@ public function getOAuthAuthorize(array $params)

$query = array_merge($query, $params);

return $this->options->getRequest()->setQuery($query)->get(API::LIST['oAuthAuthorize']);
return $this->options
->getRequest()
->setQuery($query)
->get(API::LIST['oAuthAuthorize']);
}

// ------------------------------------------------------------------------------
Expand All @@ -93,7 +97,10 @@ public function postOAuthToken(string $code)
$query = ['grant_type' => 'authorization_code'];
$query = array_merge($query, $params);

return $this->options->getRequest()->setQuery($query)->post(API::LIST['oAuthToken']);
return $this->options
->getRequest()
->setQuery($query)
->post(API::LIST['oAuthToken']);
}

// ------------------------------------------------------------------------------
Expand All @@ -116,7 +123,10 @@ public function postOAuthRevoke(string $accessToken = null)

$header = ['Authorization' => $accessToken];

return $this->options->getRequest()->setHeaderParams($header)->post(API::LIST['oAuthRevoke']);
return $this->options
->getRequest()
->setHeaderParams($header)
->post(API::LIST['oAuthRevoke']);
}

// ------------------------------------------------------------------------------
Expand Down
15 changes: 11 additions & 4 deletions src/Authentication/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public function postConnectToken(string $code)

$params['code'] = $code;

return $this->options->getRequest()->setFormParams($params)->post(API::LIST['connectToken']);
return $this->options
->getRequest()
->setFormParams($params)
->post(API::LIST['connectToken']);
}

// ------------------------------------------------------------------------------
Expand All @@ -81,10 +84,13 @@ public function postConnectAuthorize(array $params)
{
$setting = $this->settingsRules($params);

$params['client_id'] = $this->options->getClientApps()['client_id'];

$rules = V::keySet(
V::key('name', V::stringType()::notEmpty()),
V::key('settings', $setting),
V::key('provider', V::in($this->providers)),
V::key('client_id', V::stringType()::notEmpty()),
V::key('email_address', V::email()),
V::key('reauth_account_id', V::stringType()::notEmpty(), false)
);
Expand All @@ -94,9 +100,10 @@ public function postConnectAuthorize(array $params)
throw new NylasException('invalid params');
}

$params['client_id'] = $this->options->getClientApps()['client_id'];

return $this->options->getRequest()->setFormParams($params)->post(API::LIST['connectAuthorize']);
return $this->options
->getRequest()
->setFormParams($params)
->post(API::LIST['connectAuthorize']);
}

// ------------------------------------------------------------------------------
Expand Down
12 changes: 7 additions & 5 deletions src/Calendars/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public function __construct(Options $options)
*/
public function getCalendarsList(array $params)
{
$params['access_token'] =
$params['access_token'] ?? $this->options->getAccessToken();

$rule = V::keySet(
V::key('view', V::in(['count', 'ids']), false),
V::key('limit', V::intType()::min(1), false),
V::key('offset', V::intType()::min(0), false),
V::key('access_token', V::stringType()::notEmpty())
);

$params['access_token'] =
$params['access_token'] ?? $this->options->getAccessToken();

if (!$rule->validate($params))
{
throw new NylasException('invalid params');
Expand All @@ -65,7 +65,8 @@ public function getCalendarsList(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($params)
->setHeaderParams($header)
->get(API::LIST['calendars']);
Expand Down Expand Up @@ -102,7 +103,8 @@ public function getCalendar(string $calendarId, string $accessToken = null)
$path = [$params['id']];
$header = ['Authorization' => $params['access_token']];

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setHeaderParams($header)
->get(API::LIST['oneCalendar']);
Expand Down
23 changes: 16 additions & 7 deletions src/Contacts/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function getContactsList(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($params)
->setHeaderParams($header)
->get(API::LIST['contacts']);
Expand Down Expand Up @@ -95,7 +96,8 @@ public function getContact(string $contactId, string $accessToken = null)
$path = [$params['id']];
$header = ['Authorization' => $params['access_token']];

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setHeaderParams($header)
->get(API::LIST['oneContact']);
Expand Down Expand Up @@ -126,7 +128,8 @@ public function addContact(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setFormParams($params)
->setHeaderParams($header)
->post(API::LIST['contacts']);
Expand Down Expand Up @@ -160,7 +163,8 @@ public function updateContact(array $params)

unset($params['id'], $params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setFormParams($params)
->setHeaderParams($header)
Expand Down Expand Up @@ -198,7 +202,8 @@ public function deleteContact(string $contactId, string $accessToken = null)
$path = [$params['id']];
$header = ['Authorization' => $params['access_token']];

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setHeaderParams($header)
->delete(API::LIST['oneContact']);
Expand All @@ -224,7 +229,10 @@ public function getContactGroups(string $accessToken = null)

$header = ['Authorization' => $accessToken];

return $this->options->getRequest()->setHeaderParams($header)->get(API::LIST['contactsGroups']);
return $this->options
->getRequest()
->setHeaderParams($header)
->get(API::LIST['contactsGroups']);
}

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -258,7 +266,8 @@ public function getContactPicture(string $contactId, string $accessToken = null)
$path = [$params['id']];
$header = ['Authorization' => $params['access_token']];

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setHeaderParams($header)
->get(API::LIST['contactPic']);
Expand Down
12 changes: 8 additions & 4 deletions src/Deltas/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function getLatestCursor(string $accessToken = null)

$header = ['Authorization' => $accessToken];

return $this->options->getRequest()
return $this->options
->getRequest()
->setHeaderParams($header)
->post(API::LIST['deltaLatestCursor']);
}
Expand Down Expand Up @@ -87,7 +88,8 @@ public function getSetOfDeltas(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($params)
->setHeaderParams($header)
->get(API::LIST['delta']);
Expand Down Expand Up @@ -121,7 +123,8 @@ public function longPollingDelta(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($params)
->setHeaderParams($header)
->get(API::LIST['deltaLongpoll']);
Expand Down Expand Up @@ -152,7 +155,8 @@ public function streamingDelta(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($params)
->setHeaderParams($header)
->get(API::LIST['deltaStreaming']);
Expand Down
30 changes: 14 additions & 16 deletions src/Drafts/Draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getDraftsList(string $anyEmail = null, string $accessToken = nul
{
$params = ['access_token' => $accessToken ?? $this->options->getAccessToken()];

if ($anyEmail) { $params['any_email'] = $anyEmail; }
!empty($anyEmail) AND $params['any_email'] = $anyEmail;

$rule = V::keySet(
V::key('access_token', V::stringType()::notEmpty()),
Expand All @@ -65,7 +65,8 @@ public function getDraftsList(string $anyEmail = null, string $accessToken = nul
$header = ['Authorization' => $params['access_token']];
$query = empty($emails) ? [] : ['any_email' => $emails];

return $this->options->getRequest()
return $this->options
->getRequest()
->setQuery($query)
->setHeaderParams($header)
->get(API::LIST['drafts']);
Expand Down Expand Up @@ -102,7 +103,8 @@ public function getDraft(string $draftId, string $accessToken = null)
$path = [$params['id']];
$header = ['Authorization' => $params['access_token']];

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setHeaderParams($header)
->get(API::LIST['oneDraft']);
Expand Down Expand Up @@ -133,7 +135,8 @@ public function addDraft(array $params)

unset($params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setFormParams($params)
->setHeaderParams($header)
->post(API::LIST['drafts']);
Expand Down Expand Up @@ -165,7 +168,8 @@ public function updateDraft(array $params)

unset($params['id'], $params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setFormParams($params)
->setHeaderParams($header)
Expand All @@ -177,20 +181,13 @@ public function updateDraft(array $params)
/**
* delete draft
*
* @param string $draftId
* @param string $version
* @param string $accessToken
* @param array $params
* @return mixed
* @throws \Nylas\Exceptions\NylasException
*/
public function deleteDraft(string $draftId, string $version, string $accessToken = null)
public function deleteDraft(array $params)
{
$params =
[
'id' => $draftId,
'version' => $version,
'access_token' => $accessToken ?? $this->options->getAccessToken(),
];
$params['access_token'] = $params['access_token'] ?? $this->options->getAccessToken();

$rule = V::keySet(
V::key('id', V::stringType()::notEmpty()),
Expand All @@ -208,7 +205,8 @@ public function deleteDraft(string $draftId, string $version, string $accessToke

unset($params['id'], $params['access_token']);

return $this->options->getRequest()
return $this->options
->getRequest()
->setPath($path)
->setFormParams($params)
->setHeaderParams($header)
Expand Down
Loading

0 comments on commit a3b27a7

Please sign in to comment.