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

Hooks   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 3
A unregister() 0 4 1
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
}