Completed
Push — master ( 20c412...48d54d )
by Vítězslav
05:37
created

Hooks::getChangesStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 6
rs 9.4285
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
class Hooks extends FlexiBee
13
{
14
    /**
15
     * Evidence užitá objektem.
16
     *
17
     * @var string
18
     */
19
    public $evidence = 'hooks';
20
21
    /**
22
     * Zaregistruje WebHook
23
     *
24
     * @param string $url URL skript přímající WebHook
25
     * @param string $format json|xml formát přenášených dat
26
     * @return boolean výsledek požadavku
27
     */
28
    public function register($url, $format = 'json')
29
    {
30
        $this->setDataValue('url', $url);
31
        $this->setDataValue('format', strtoupper($format));
32
33
        $hooks = $this->getAllFromFlexibee();
34
        foreach ($hooks as $hook) {
35
            if ($hook['url'] == $url) {
36
                $this->addStatusMessage(_('Url allready registered'), 'warning');
37
                return false;
38
            }
39
        }
40
41
        return $this->performRequest('hooks.xml?'.http_build_query($this->getData()),
42
                'PUT', 'xml');
43
    }
44
45
    /**
46
     * Odregistruje webhook
47
     *
48
     * @param int $id číslo záznamu
49
     */
50
    public function unregister($id)
51
    {
52
        return $this->deleteFromFlexiBee($id);
53
    }
54
}