1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89:
<?php
/**
* FlexiPeeHP - WebHooks.
*
* @link https://www.flexibee.eu/api/dokumentace/ref/web-hooks WebHooks Reference
* @author Vítězslav Dvořák <vitex@arachne.cz>
* @copyright (C) 2015-2017 Spoje.Net
*/
namespace FlexiPeeHP;
/**
* Hooky pro ChangesAPI
*
* @note Tato položka nemá dostupné položky evidence
*/
class Hooks extends FlexiBeeRW
{
/**
* Evidence užitá objektem.
*
* @var string
*/
public $evidence = 'hooks';
/**
* Zaregistruje WebHook
*
* @param string $url URL skript přímající WebHook
* @param string $format json|xml formát přenášených dat
*
* @return boolean výsledek požadavku
*/
public function register($url, $format = 'json')
{
$this->setDataValue('url', $url);
$this->setDataValue('format', strtoupper($format));
$hooks = $this->getAllFromFlexibee();
if (is_array($hooks) && count($hooks)) {
foreach ($hooks as $hook) {
if (is_array($hook) && array_key_exists('url', $hook)) {
if ($hook['url'] == $url) {
$this->addStatusMessage(_('Url allready registered'),
'warning');
return false;
}
}
}
}
$this->performRequest('?'.http_build_query($this->getData()), 'PUT',
'xml');
return $this->lastResponseCode === 200;
}
/**
* Aktualizuje WebHook (penalty = 0)
*
* @param int $id
*/
public function refreshWebHook($id)
{
$this->performRequest($id.'/retry', 'PUT');
return $this->lastResponseCode === 200;
}
/**
* Odregistruje webhook
*
* @param int $id číslo záznamu
*/
public function unregister($id)
{
return $this->deleteFromFlexiBee($id);
}
/**
* Test if given record exists in FlexiBee.
*
* @param array $data
* @return null Unsupported evidence
*/
public function recordExists($data = null)
{
return null;
}
}