-
Notifications
You must be signed in to change notification settings - Fork 263
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 #276 from Tremmors/master
Add in user specific ticket endpoints.
- Loading branch information
Showing
3 changed files
with
172 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace Zendesk\API\Resources\Core; | ||
|
||
use Zendesk\API\Exceptions\MissingParametersException; | ||
use Zendesk\API\Exceptions\ResponseException; | ||
use Zendesk\API\Http; | ||
use Zendesk\API\Resources\ResourceAbstract; | ||
use Zendesk\API\Traits\Utility\InstantiatorTrait; | ||
|
||
/** | ||
* The UserTickets class exposes methods to retrieve tickets created, cc'ed to, or | ||
* assigned to a user | ||
*/ | ||
class UserTickets extends ResourceAbstract | ||
{ | ||
use InstantiatorTrait; | ||
|
||
/** | ||
* Wrapper for common GET requests | ||
* | ||
* @param $route | ||
* @param array $params | ||
* | ||
* @return \stdClass | null | ||
* @throws ResponseException | ||
* @throws \Exception | ||
*/ | ||
private function sendGetRequest($route, array $params = []) | ||
{ | ||
$response = Http::send( | ||
$this->client, | ||
$this->getRoute($route, $params), | ||
['queryParams' => $params] | ||
); | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Declares routes to be used by this resource. | ||
*/ | ||
protected function setUpRoutes() | ||
{ | ||
parent::setUpRoutes(); | ||
|
||
$this->setRoutes( | ||
[ | ||
'requested' => 'users/{id}/tickets/requested.json', | ||
'ccd' => 'users/{id}/tickets/ccd.json', | ||
'assigned' => 'users/{id}/tickets/assigned.json', | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* List tickets that a user requested | ||
* | ||
* @param array $params | ||
* | ||
* @throws MissingParametersException | ||
* @throws ResponseException | ||
* @throws \Exception | ||
* @return \stdClass | null | ||
*/ | ||
public function requested(array $params = []) | ||
{ | ||
$params = $this->addChainedParametersToParams( | ||
$params, | ||
['id' => Users::class] | ||
); | ||
|
||
if (! $this->hasKeys($params, ['id'])) { | ||
throw new MissingParametersException(__METHOD__, ['id']); | ||
} | ||
|
||
return $this->sendGetRequest(__FUNCTION__, $params); | ||
} | ||
|
||
/** | ||
* List tickets a user was CC'ed on | ||
* | ||
* @param array $params | ||
* | ||
* @throws MissingParametersException | ||
* @throws ResponseException | ||
* @throws \Exception | ||
* @return \stdClass | null | ||
*/ | ||
public function ccd(array $params = []) | ||
{ | ||
$params = $this->addChainedParametersToParams( | ||
$params, | ||
['id' => Users::class] | ||
); | ||
|
||
if (! $this->hasKeys($params, ['id'])) { | ||
throw new MissingParametersException(__METHOD__, ['id']); | ||
} | ||
|
||
return $this->sendGetRequest(__FUNCTION__, $params); | ||
} | ||
|
||
/** | ||
* List tickets a user was assigned | ||
* | ||
* @param array $params | ||
* | ||
* @throws MissingParametersException | ||
* @throws ResponseException | ||
* @throws \Exception | ||
* @return \stdClass | null | ||
*/ | ||
public function assigned(array $params = []) | ||
{ | ||
$params = $this->addChainedParametersToParams( | ||
$params, | ||
['id' => Users::class] | ||
); | ||
|
||
if (! $this->hasKeys($params, ['id'])) { | ||
throw new MissingParametersException(__METHOD__, ['id']); | ||
} | ||
|
||
return $this->sendGetRequest(__FUNCTION__, $params); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Zendesk\API\UnitTests\Core; | ||
|
||
use Zendesk\API\UnitTests\BasicTest; | ||
|
||
/** | ||
* UserTicket test class | ||
*/ | ||
class UserTicketsTest extends BasicTest | ||
{ | ||
protected $number; | ||
|
||
/** | ||
* Tests if the requested endpoint can be called by the client and is passed the correct ID | ||
*/ | ||
public function testRelated() | ||
{ | ||
$this->assertEndpointCalled(function () { | ||
$this->client->users(12345)->tickets()->requested(); | ||
}, 'users/12345/tickets/requested.json'); | ||
} | ||
|
||
/** | ||
* Tests if the requested endpoint can be called by the client and is passed the correct ID | ||
*/ | ||
public function testCCD() | ||
{ | ||
$this->assertEndpointCalled(function () { | ||
$this->client->users(12345)->tickets()->ccd(); | ||
}, 'users/12345/tickets/ccd.json'); | ||
} | ||
|
||
/** | ||
* Tests if the requested endpoint can be called by the client and is passed the correct ID | ||
*/ | ||
public function testAssigned() | ||
{ | ||
$this->assertEndpointCalled(function () { | ||
$this->client->users(12345)->tickets()->assigned(); | ||
}, 'users/12345/tickets/assigned.json'); | ||
} | ||
} |