Completed
Push — master ( 48d54d...aba11b )
by Vítězslav
04:04
created

Hooks::unregister()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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 1
    public function register($url, $format = 'json')
29
    {
30 1
        $this->setDataValue('url', $url);
31 1
        $this->setDataValue('format', strtoupper($format));
32
33 1
        $hooks = $this->getAllFromFlexibee();
34 1
        foreach ($hooks as $hook) {
35 1
            if ($hook['url'] == $url) {
36 1
                $this->addStatusMessage(_('Url allready registered'), 'warning');
37 1
                return false;
38
            }
39 1
        }
40
41 1
        return $this->performRequest('hooks.xml?'.http_build_query($this->getData()),
42 1
                'PUT', 'xml');
43
    }
44
45
    /**
46
     * Odregistruje webhook
47
     *
48
     * @param int $id číslo záznamu
49
     */
50 1
    public function unregister($id)
51
    {
52 1
        return $this->deleteFromFlexiBee($id);
53
    }
54
}