Completed
Push — master ( 14dc45...6a7b8b )
by Vítězslav
08:50
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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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 ($hook['url'] == $url) {
42 1
                    $this->addStatusMessage(_('Url allready registered'),
43
                        'warning');
44
                    return false;
45
                }
46
            }
47
        }
48
        $this->performRequest('hooks.xml?'.http_build_query($this->getData()),
49
            'PUT', 'xml');
50 1
51
        return $this->lastResponseCode === 200;
52 1
    }
53
54
    /**
55
     * Odregistruje webhook
56
     *
57
     * @param int $id číslo záznamu
58
     */
59
    public function unregister($id)
60
    {
61
        return $this->deleteFromFlexiBee($id);
62
    }
63
64
    /**
65
     * Test if given record exists in FlexiBee.
66
     *
67
     * @param array $data
68
     * @return null Unsupported evidence
69
     */
70
    public function recordExists($data = null)
71
    {
72
        return null;
73
    }
74
75
}
76