2014-10-22 19:59:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Webhook model
|
|
|
|
*
|
|
|
|
* @package model
|
|
|
|
* @author Frederic Guillot
|
|
|
|
*/
|
|
|
|
class Webhook extends Base
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Call the external URL
|
|
|
|
*
|
|
|
|
* @access public
|
2015-08-16 17:04:56 +02:00
|
|
|
* @param array $values Event payload
|
2014-10-22 19:59:09 +02:00
|
|
|
*/
|
2015-08-16 17:04:56 +02:00
|
|
|
public function notify(array $values)
|
2014-10-22 19:59:09 +02:00
|
|
|
{
|
2015-08-16 17:04:56 +02:00
|
|
|
$url = $this->config->get('webhook_url');
|
2015-01-16 14:23:05 +01:00
|
|
|
$token = $this->config->get('webhook_token');
|
|
|
|
|
2015-08-16 17:04:56 +02:00
|
|
|
if (! empty($url)) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
2015-08-16 17:04:56 +02:00
|
|
|
if (strpos($url, '?') !== false) {
|
|
|
|
$url .= '&token='.$token;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$url .= '?token='.$token;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->httpClient->postJson($url, $values);
|
|
|
|
}
|
2014-10-22 19:59:09 +02:00
|
|
|
}
|
|
|
|
}
|