Skip to content

Commit cb48ba5

Browse files
committed
Added methods for managing REST hooks
1 parent 85a6170 commit cb48ba5

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ $manager->allTriggers();
103103
$manager->addContactToJourney($journey, $id|$email);
104104
```
105105

106+
### allRestHooks
107+
```php
108+
$manager->allRestHooks();
109+
```
110+
111+
### deleteAllRestHooks
112+
```php
113+
$manager->deleteAllRestHooks();
114+
```
115+
116+
### addRestHook
117+
```php
118+
$manager->addRestHook($event, $targetUrl);
119+
```
120+
121+
### deleteRestHook
122+
```php
123+
$manager->deleteRestHook($hookId);
124+
```
125+
106126
## AutopilotContact
107127
---
108128
### get value

src/AutopilotManager.php

+67
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,73 @@ public function addContactToJourney($name, $contactId)
403403
return $response;
404404
}
405405

406+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
407+
// REST hooks methods
408+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
409+
410+
/**
411+
* Get all REST hooks
412+
*
413+
* @return array
414+
*
415+
* @throws AutopilotException
416+
*/
417+
public function allRestHooks()
418+
{
419+
$response = $this->apiGet('hooks');
420+
421+
return $response['hooks'];
422+
}
423+
424+
/**
425+
* Deletes all REST hooks
426+
*
427+
* @return boolean
428+
*
429+
* @throws AutopilotException
430+
*/
431+
public function deleteAllRestHooks()
432+
{
433+
$this->apiDelete('hooks');
434+
435+
return true;
436+
}
437+
438+
/**
439+
* Add REST hook
440+
*
441+
* @param string $event
442+
* @param string $targetUrl
443+
*
444+
* @return string Returns hook ID
445+
*
446+
* @throws AutopilotException
447+
*/
448+
public function addRestHook($event, $targetUrl)
449+
{
450+
$request = ['event' => $event, 'target_url' => $targetUrl];
451+
452+
$response = $this->apiPost('hook', $request);
453+
454+
return $response['hook_id'];
455+
}
456+
457+
/**
458+
* Deletes a single REST hook
459+
*
460+
* @param string $hookId
461+
*
462+
* @return bool
463+
*
464+
* @throws AutopilotException
465+
*/
466+
public function deleteRestHook($hookId)
467+
{
468+
$this->apiDelete('hook/' . $hookId);
469+
470+
return true;
471+
}
472+
406473
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
407474
// REQUEST helpers
408475
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)