1 | <?php |
||
17 | class Hooks extends FlexiBeeRW |
||
18 | { |
||
19 | /** |
||
20 | * Evidence užitá objektem. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | public $evidence = 'hooks'; |
||
25 | |||
26 | /** |
||
27 | * Zaregistruje WebHook |
||
28 | * |
||
29 | * @param string $url URL skript přímající WebHook |
||
30 | * @param string $format json|xml formát přenášených dat |
||
31 | * @return boolean výsledek požadavku |
||
32 | */ |
||
33 | 1 | public function register($url, $format = 'json') |
|
34 | { |
||
35 | 1 | $this->setDataValue('url', $url); |
|
36 | 1 | $this->setDataValue('format', strtoupper($format)); |
|
37 | |||
38 | 1 | $hooks = $this->getAllFromFlexibee(); |
|
39 | 1 | if (count($hooks)) { |
|
40 | 1 | foreach ($hooks as $hook) { |
|
41 | 1 | if (is_array($hook) && array_key_exists('url', $hook)) { |
|
42 | 1 | if ($hook['url'] == $url) { |
|
43 | $this->addStatusMessage(_('Url allready registered'), |
||
44 | 'warning'); |
||
45 | return false; |
||
46 | } |
||
47 | 1 | } |
|
48 | 1 | } |
|
49 | 1 | } |
|
50 | 1 | $this->performRequest('hooks.xml?'.http_build_query($this->getData()), |
|
51 | 1 | 'PUT', 'xml'); |
|
52 | |||
53 | 1 | return $this->lastResponseCode === 200; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Aktualizuje WebHook (penalty = 0) |
||
58 | * |
||
59 | * @param int $id |
||
60 | */ |
||
61 | public function refreshWebHook($id) |
||
66 | |||
67 | /** |
||
68 | * Odregistruje webhook |
||
69 | * |
||
70 | * @param int $id číslo záznamu |
||
71 | */ |
||
72 | public function unregister($id) |
||
76 | |||
77 | /** |
||
78 | * Test if given record exists in FlexiBee. |
||
79 | * |
||
80 | * @param array $data |
||
81 | * @return null Unsupported evidence |
||
82 | */ |
||
83 | public function recordExists($data = null) |
||
87 | } |
||
88 |