-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from helpscout/list-users-by-mailbox
Can now list users in a given mailbox
- Loading branch information
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -823,6 +823,18 @@ Get users. | |
$users = $client->users()->list(); | ||
``` | ||
|
||
Narrow down the list of Users based on a set of filters. | ||
|
||
```php | ||
use HelpScout\Api\Users\UserFilters; | ||
|
||
$filters = (new UserFilters()) | ||
->withMailbox(1) | ||
->withEmail('[email protected]'); | ||
|
||
$users = $client->users()->list($filters); | ||
``` | ||
|
||
## Reports | ||
|
||
When running reports using the SDK, refer to the [developer docs](https://developer.helpscout.com/mailbox-api/) for the exact endpoint, parameters, and response formats. While most of the endpoints in this SDK are little more than pass-through methods to call the API, there are a few conveniences. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HelpScout\Api\Users; | ||
|
||
use HelpScout\Api\Assert\Assert; | ||
|
||
class UserFilters | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $mailbox; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $email; | ||
|
||
public function getParams(): array | ||
{ | ||
$params = [ | ||
'mailbox' => $this->mailbox, | ||
'email' => $this->email, | ||
]; | ||
|
||
// Filter out null values & empty strings | ||
return array_filter($params); | ||
} | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public function withMailbox(int $mailbox) | ||
{ | ||
Assert::greaterThan($mailbox, 0); | ||
|
||
$filters = clone $this; | ||
$filters->mailbox = $mailbox; | ||
|
||
return $filters; | ||
} | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public function withEmail(string $email) | ||
{ | ||
$filters = clone $this; | ||
$filters->email = $email; | ||
|
||
return $filters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HelpScout\Api\Tests\Users; | ||
|
||
use HelpScout\Api\Users\UserFilters; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UserFiltersTest extends TestCase | ||
{ | ||
public function testGetParamsDoesNotReturnNullValues() | ||
{ | ||
$filters = new UserFilters(); | ||
|
||
$this->assertSame([], $filters->getParams()); | ||
} | ||
|
||
public function testGetParams() | ||
{ | ||
$filters = (new UserFilters()) | ||
->withMailbox(1) | ||
->withEmail('[email protected]'); | ||
|
||
$this->assertSame([ | ||
'mailbox' => 1, | ||
'email' => '[email protected]', | ||
], $filters->getParams()); | ||
} | ||
} |