Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Sep 22, 2021
1 parent fce8c98 commit 9688013
Show file tree
Hide file tree
Showing 73 changed files with 182 additions and 290 deletions.
187 changes: 13 additions & 174 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ Last check at the point: [Dashboard Release for Canada and Ireland](https://chan
6. Support async batch get & delete & send (since version 3.1).
7. Chained calls and good code hints, easy to use</br>

<div align="center">
<img width="664" height="596" src="media/autocomplete.gif" />
</div>


## Installation (PHP 7.4 required since version 4.0)

**version 3.x for php >= 7.3 (branch 3.0)**
Expand Down Expand Up @@ -85,15 +80,11 @@ $nylas = new Client($options);

### Options Setting

You can modify options with these methods:
You can modify options with methods of `\Nylas\Utilities\Options`

```php
$nylas->Options()->
$nylas->Options()->setXxx();
```
<div align="center">
<img width="515" height="307" src="media/options.png" />
</div>


### Batch Request

Expand All @@ -104,12 +95,12 @@ $id = 'id_xxx';
$ids = ['id_xxx', 'id_yyy', ...];

// one per time
$dataA = $nylas->Contacts()->Contact()->getContact($id);
$dataB = $nylas->Contacts()->Contact()->deleteContact($id);
$dataA = $nylas->Contacts->Contact->getContact($id);
$dataB = $nylas->Contacts->Contact->deleteContact($id);

// batch request
$dataC = $nylas->Contacts()->Contact()->getContact($ids);
$dataD = $nylas->Contacts()->Contact()->deleteContact($ids);
$dataC = $nylas->Contacts->Contact->getContact($ids);
$dataD = $nylas->Contacts->Contact->deleteContact($ids);
```

For more detail about the batch request, you should have to read the source code.</br>
Expand Down Expand Up @@ -144,7 +135,7 @@ $params =
];

// generate the url that your user need be redirect to.
$url = $nylas->Authentication()->Hosted()->getOAuthAuthorizeUrl($params);
$url = $nylas->Authentication->Hosted->authenticateUser($params);
```

**Step 2: your user logs in:**</br>
Expand All @@ -154,11 +145,11 @@ Please implement the above 2 & 3 steps yourself.</br>
**Step 4: Get authorization token with access code:**

```php
$data = $nylas->Authentication()->Hosted()->postOAuthToken($params);
$data = $nylas->Authentication->Hosted->sendAuthorizationCode($params);

// save your token some where
// or update the client option
$nylas->Options()->setAccessToken("pass the token you got");
$nylas->Options->setAccessToken("pass the token you got");
```


Expand Down Expand Up @@ -241,171 +232,19 @@ $nylas->Options()->setAccessToken("pass the token you got");
4. Another way to run tests: `./tests/do.sh foo.php --filter fooMethod`, see `tests/do.sh`


## Supported Methods
## Methods & Parameters

The parameters that required by methods almost the same as nylas official api required.

For more detail, you can view the tests or the source code of validation rules for that method.

### [Accounts](https://docs.nylas.com/reference#accounts)

```php
$nylas->Accounts()->Account()->xxx();
$nylas->Accounts()->Manage()->xxx();
```


### [Authentication](https://docs.nylas.com/reference#authentication)
### Apis Of Accounts & Account Management & Application Management

```php
$nylas->Authentication()->Hosted()->xxx();
$nylas->Authentication()->Native()->xxx();
$nylas->Management->Account->xxx();
$nylas->Management->Application->xxx();
```


### [Calendars](https://docs.nylas.com/reference#calendars)

```php
$nylas->Calendars()->Calendar()->xxx();
```


### [Contacts](https://docs.nylas.com/reference#contacts-intro)

```php
$nylas->Contacts()->Contact()->xxx();
```

```php
// multiple contact pictures download
$params =
[
[
'id' => 'contact id',
'path' => 'this can be a file path, resource or stream handle',
],
[
'id' => 'xxxx',
'path' => dirname(__FILE__) . '/correct.png',
],
// ...
];

$nylas->Contacts()->Contact()->getContactPicture($params);
```


### [Deltas](https://docs.nylas.com/reference#deltas)

```php
$nylas->Deltas()->Delta()->xxx();
```


### [Draft](https://docs.nylas.com/reference#drafts)

```php
$nylas->Drafts()->Draft()->xxx();
$nylas->Drafts()->Sending()->xxx();
```


### [Events](https://docs.nylas.com/reference#events)

```php
$nylas->Events()->Event()->xxx();
```


### [Files](https://docs.nylas.com/reference#files)

```php
$nylas->Files()->File()->xxx();
```


```php
// multiple files download
$params =
[
[
'id' => 'file id',
'path' => 'this can be a file path, resource or stream handle',
],
[
'id' => 'xxxx',
'path' => dirname(__FILE__) . '/correct.png',
],
// ...
];

$nylas->Files()->File()->downloadFile($params);


// multiple files upload
$params =
[
[
'contents' => 'this can be a file path, resource or stream handle',
'filename' => 'your file name'
],
[
'contents' => dirname(__FILE__) . '/correct.png',
'filename' => 'test_correct.png'
],
// ...
];

$nylas->Files()->File()->uploadFile($params);
```


### [Folders](https://docs.nylas.com/reference#folders)

```php
$nylas->Folders()->Folder()->xxx();
```


### [Labels](https://docs.nylas.com/reference#labels)

```php
$nylas->Labels()->Label()->xxx();
```

### [Job-Statuses](https://docs.nylas.com/reference#job-statuses)

```php
$nylas->JobStatuses()->JobStatus()->xxx();
```


### [Messages](https://docs.nylas.com/reference#messages)

```php
$nylas->Messages()->Message()->xxx();
$nylas->Messages()->Search()->xxx();
$nylas->Messages()->Sending()->xxx();
$nylas->Messages()->Smart()->xxx();
```


### [Threads](https://docs.nylas.com/reference#threads)

```php
$nylas->Threads()->Search()->xxx();
$nylas->Threads()->Thread()->xxx();
$nylas->Threads()->Smart()->xxx();
```


### [Webhooks](https://docs.nylas.com/reference#webhooks)

```php
$nylas->Webhooks()->Webhook()->xxx();
```


## Contributing

For more usage demos, please view the tests.</br>
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @property Native Native
*
* @author lanlin
* @change 2021/07/21
* @change 2021/09/22
*/
class Abs
{
Expand Down
15 changes: 11 additions & 4 deletions src/Authentication/Hosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(Options $options)
*/
public function authenticateUser(array $params): string
{
$params['client_id'] = $this->options->getClientApps()['client_id'];
$params['client_id'] = $this->options->getClientId();

V::doValidate(V::keySet(
V::key('scopes', V::stringType()->notEmpty()),
Expand Down Expand Up @@ -80,12 +80,19 @@ public function sendAuthorizationCode(string $code): array
{
V::doValidate(V::stringType()->notEmpty(), $code);

$query = ['code' => $code, 'grant_type' => 'authorization_code'];
$query = \array_merge($query, $this->options->getClientApps());
$query = [
'code' => $code,
'grant_type' => 'authorization_code',
];

$client = [
'client_id' => $this->options->getClientId(),
'client_secret' => $this->options->getClientSecret(),
];

return $this->options
->getSync()
->setQuery($query)
->setQuery(\array_merge($query, $client))
->post(API::LIST['oAuthToken']);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Authentication/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(Options $options)
*/
public function sendAuthorization(array $params): array
{
$params['client_id'] = $this->options->getClientApps()['client_id'];
$params['client_id'] = $this->options->getClientId();

V::doValidate(V::keySet(
V::key('name', V::stringType()->notEmpty()),
Expand Down Expand Up @@ -83,9 +83,11 @@ public function exchangeTheToken(string $code): array
{
V::doValidate(V::stringType()->notEmpty(), $code);

$params = $this->options->getClientApps();

$params['code'] = $code;
$params = [
'code' => $code,
'client_id' => $this->options->getClientId(),
'client_secret' => $this->options->getClientSecret(),
];

return $this->options
->getSync()
Expand Down
2 changes: 1 addition & 1 deletion src/Calendars/Abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property Calendar Calendar
*
* @author lanlin
* @change 2021/07/21
* @change 2021/09/22
*/
class Abs
{
Expand Down
2 changes: 1 addition & 1 deletion src/Calendars/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/04/26
* @change 2021/09/22
*/
class Calendar
{
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @property JobStatuses\Abs JobStatuses
*
* @author lanlin
* @change 2021/07/20
* @change 2021/09/22
*/
class Client
{
Expand Down
2 changes: 1 addition & 1 deletion src/Contacts/Abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property Contact Contact
*
* @author lanlin
* @change 2021/07/21
* @change 2021/09/22
*/
class Abs
{
Expand Down
2 changes: 1 addition & 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/09/30
* @change 2021/09/22
*/
class Contact
{
Expand Down
2 changes: 1 addition & 1 deletion src/Deltas/Abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property Delta Delta
*
* @author lanlin
* @change 2021/07/21
* @change 2021/09/22
*/
class Abs
{
Expand Down
2 changes: 1 addition & 1 deletion src/Deltas/Delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* ----------------------------------------------------------------------------------
*
* @author lanlin
* @change 2020/09/30
* @change 2021/09/22
*/
class Delta
{
Expand Down
2 changes: 1 addition & 1 deletion src/Drafts/Abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @property Sending Sending
*
* @author lanlin
* @change 2021/07/21
* @change 2021/09/22
*/
class Abs
{
Expand Down
2 changes: 1 addition & 1 deletion 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/09/30
* @change 2021/09/22
*/
class Draft
{
Expand Down
Loading

0 comments on commit 9688013

Please sign in to comment.