1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FlexiPeeHP - WebHooks. |
4
|
|
|
* |
5
|
|
|
* @link https://www.flexibee.eu/api/dokumentace/ref/web-hooks WebHooks Reference |
6
|
|
|
* @author Vítězslav Dvořák <[email protected]> |
7
|
|
|
* @copyright (C) 2015,2016 Spoje.Net |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FlexiPeeHP; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Hooky pro ChangesAPI |
14
|
|
|
* |
15
|
|
|
* @note Tato položka nemá dostupné položky evidence |
16
|
|
|
*/ |
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
|
1 |
|
* |
29
|
|
|
* @param string $url URL skript přímající WebHook |
30
|
1 |
|
* @param string $format json|xml formát přenášených dat |
31
|
1 |
|
* @return boolean výsledek požadavku |
32
|
|
|
*/ |
33
|
1 |
|
public function register($url, $format = 'json') |
34
|
1 |
|
{ |
35
|
1 |
|
$this->setDataValue('url', $url); |
36
|
1 |
|
$this->setDataValue('format', strtoupper($format)); |
37
|
1 |
|
|
38
|
|
|
$hooks = $this->getAllFromFlexibee(); |
39
|
1 |
|
if (count($hooks)) { |
40
|
|
|
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
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
1 |
|
$this->performRequest('hooks.xml?'.http_build_query($this->getData()), |
51
|
|
|
'PUT', 'xml'); |
52
|
1 |
|
|
53
|
|
|
return $this->lastResponseCode === 200; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Aktualizuje WebHook (penalty = 0) |
58
|
|
|
* |
59
|
|
|
* @param int $id |
60
|
|
|
*/ |
61
|
|
|
public function refresh($id) |
62
|
|
|
{ |
63
|
|
|
$this->performRequest('hooks/'.$id.'/retry', 'PUT'); |
64
|
|
|
return $this->lastResponseCode === 200; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Odregistruje webhook |
69
|
|
|
* |
70
|
|
|
* @param int $id číslo záznamu |
71
|
|
|
*/ |
72
|
|
|
public function unregister($id) |
73
|
|
|
{ |
74
|
|
|
return $this->deleteFromFlexiBee($id); |
75
|
|
|
} |
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) |
84
|
|
|
{ |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|