Test Failed
Push — master ( 0a6b17...c396e6 )
by Vítězslav
07:31
created

Hooks::recordExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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-2017 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
     *
29
     * @param string $url URL skript přímající WebHook
30
     * @param string $format json|xml formát přenášených dat
31
     *
32
     * @return boolean výsledek požadavku
33
     */
34 1
    public function register($url, $format = 'json')
35
    {
36 1
        $this->setDataValue('url', $url);
37 1
        $this->setDataValue('format', strtoupper($format));
38
39 1
        $hooks = $this->getAllFromFlexibee();
40 1
        if (count($hooks)) {
41
            foreach ($hooks as $hook) {
42
                if (is_array($hook) && array_key_exists('url', $hook)) {
43
                    if ($hook['url'] == $url) {
44
                        $this->addStatusMessage(_('Url allready registered'),
45
                            'warning');
46
                        return false;
47
                    }
48
                }
49
            }
50
        }
51 1
        $this->performRequest('?'.http_build_query($this->getData()), 'PUT',
52 1
            'xml');
53
54 1
        return $this->lastResponseCode === 200;
55
    }
56
57
    /**
58
     * Aktualizuje WebHook (penalty = 0)
59
     * 
60
     * @param int $id
61
     */
62
    public function refreshWebHook($id)
63
    {
64
        $this->performRequest($id.'/retry', 'PUT');
65
        return $this->lastResponseCode === 200;
66
    }
67
68
    /**
69
     * Odregistruje webhook
70
     *
71
     * @param int $id číslo záznamu
72
     */
73
    public function unregister($id)
74
    {
75
        return $this->deleteFromFlexiBee($id);
76
    }
77
78
    /**
79
     * Test if given record exists in FlexiBee.
80
     *
81
     * @param array $data
82
     * @return null Unsupported evidence
83
     */
84
    public function recordExists($data = null)
85
    {
86
        return null;
87
    }
88
}
89