Completed
Push — master ( 18a32e...28949e )
by Vítězslav
03:50
created

Hooks   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 64
rs 10
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A unregister() 0 4 1
A enableChanges() 0 5 1
A disableChanges() 0 5 1
A getChangesStatus() 0 5 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
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 string výsledek požadavku
27
     */
28
    public function register($url, $format = 'json')
29
    {
30
        $this->setDataValue('url', $url);
31
        $this->setDataValue('format', $format);
32
        return $this->insertToFlexiBee();
33
    }
34
35
    /**
36
     * Odregistruje webhook
37
     *
38
     * @param int $id číslo záznamu
39
     */
40
    public function unregister($id)
41
    {
42
        return $this->deleteFromFlexiBee($id);
43
    }
44
45
    /**
46
     * Povolí oznamování změn
47
     * @return type
48
     */
49
    public function enableChanges()
50
    {
51
        $this->performRequest('changes/enable.xml', 'POST', 'xml');
52
        return $this->lastResponseCode == 200;
53
    }
54
55
    /**
56
     * Zakáže oznamování změn
57
     * @return type
58
     */
59
    public function disableChanges()
60
    {
61
        $this->performRequest('changes/disable.xml', 'POST', 'xml');
62
        return $this->lastResponseCode == 200;
63
    }
64
65
    /**
66
     * Vrátí stav zapnutí ChangesAPI
67
     *
68
     * @return boolan
69
     */
70
    public function getChangesStatus()
71
    {
72
        $status = $this->performRequest('changes/status.xml', 'GET', 'xml');
73
        return (($this->lastResponseCode == 200) && ($status['success'] == 'true'));
74
    }
75
}