-
Notifications
You must be signed in to change notification settings - Fork 262
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 #482 from zendesk/jramos/version-bump
[PEGASUS-2095] Add Webhooks support
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 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
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 | ||
|
||
namespace Zendesk\API\Resources\Core; | ||
|
||
use Zendesk\API\Resources\ResourceAbstract; | ||
use Zendesk\API\Traits\Resource\Defaults; | ||
use Zendesk\API\Traits\Resource\FindAll; | ||
|
||
/** | ||
* The Tags class exposes methods as detailed on https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/ | ||
*/ | ||
class Webhooks extends ResourceAbstract | ||
{ | ||
use Defaults; | ||
use FindAll { | ||
findAll as traitFindAll; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUpRoutes() | ||
{ | ||
parent::setUpRoutes(); | ||
|
||
$this->setRoutes([ | ||
'create' => "{$this->resourceName}", | ||
'update' => "{$this->resourceName}/{id}", | ||
'delete' => "{$this->resourceName}", | ||
'findAll' => "{$this->resourceName}", | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function findAll(array $params = []) | ||
{ | ||
$queryParams = array_filter(array_flip($params), [$this, 'filterParams']); | ||
$queryParams = array_merge($params, array_flip($queryParams)); | ||
|
||
return $this->traitFindAll($queryParams); | ||
} | ||
|
||
/** | ||
* Filter parameters passed and only allow valid query parameters. | ||
* | ||
* @param $param | ||
* @return int | ||
*/ | ||
private function filterParams($param) | ||
{ | ||
return preg_match("/^sort|page[[a-zA-Z_]*]|filter[[a-zA-Z_]*](\\[\\]?)/", $param); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace ZEndesk\Api\UnitTests\Core; | ||
|
||
use Zendesk\Api\UnitTests\BasicTest; | ||
|
||
/** | ||
* Webhooks test class | ||
*/ | ||
class WebhooksTest extends BasicTest | ||
{ | ||
/** | ||
* Test find all method | ||
*/ | ||
|
||
public function testFindAll() | ||
{ | ||
$queryParams = [ | ||
'filter[name_contains]' => 'somerule', | ||
]; | ||
|
||
// We expect invalid parameters are removed. | ||
// We also expect url encoded keys and values | ||
$expectedQueryParams = []; | ||
foreach ($queryParams as $key => $value) { | ||
$expectedQueryParams = array_merge($expectedQueryParams, [urlencode($key) => $value]); | ||
} | ||
|
||
$this->assertEndpointCalled( | ||
function () use ($queryParams) { | ||
$this->client->webhooks()->findAll($queryParams); | ||
}, | ||
'webhooks', | ||
'GET', | ||
['queryParams' => $expectedQueryParams] | ||
); | ||
} | ||
} |