Completed
Push — master ( dc7840...a43799 )
by Guillaume
06:14
created

Service::deleteTimer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace AlfredTime;
4
5
use AlfredTime\ServiceApiCall;
6
7
abstract class Service
8
{
9
    /**
10
     * @var mixed
11
     */
12
    protected $serviceApiCall = null;
13
14
    /**
15
     * @param  $timerId
16
     * @return mixed
17
     */
18
    public function deleteTimer($timerId)
19
    {
20
        return $this->serviceApiCall->send(
21
            $this->methodForAction('delete'),
22
            $this->apiDeleteUrl($timerId)
23
        );
24
    }
25
26
    /**
27
     * @param  $descrition
28
     * @param  $projectId
29
     * @param  $tagData
30
     * @return mixed
31
     */
32
    public function startTimer($description, $projectId, $tagData)
33
    {
34
        $timerId = null;
35
36
        $item = $this->generateTimer($description, $projectId, $tagData);
37
38
        $data = $this->serviceApiCall->send(
39
            $this->methodForAction('start'),
40
            $this->apiStartUrl(),
41
            ['json' => $item],
42
            true
43
        );
44
45
        if (isset($data['id']) === true) {
46
            $timerId = $data['id'];
47
        }
48
49
        if (isset($data['data']['id']) === true) {
50
            $timerId = $data['data']['id'];
51
        }
52
53
        return $timerId;
54
    }
55
56
    /**
57
     * @param  $timerId
58
     * @return mixed
59
     */
60
    public function stopTimer($timerId)
61
    {
62
        return $this->serviceApiCall->send(
63
            $this->methodForAction('stop'),
64
            $this->apiStopUrl($timerId)
65
        );
66
    }
67
68
    /**
69
     * @param $baseUri
70
     * @param $apiToken
71
     */
72
    protected function __construct($baseUri, $credentials)
73
    {
74
        $this->serviceApiCall = new ServiceApiCall([
75
            'base_uri' => $baseUri,
76
            'headers'  => [
77
                'Authorization' => 'Basic ' . $credentials,
78
            ],
79
        ]);
80
    }
81
82
    /**
83
     * @param $timerId
84
     */
85
    abstract protected function apiDeleteUrl($timerId);
86
87
    abstract protected function methodForAction($action);
88
89
    /**
90
     * @param $timerId
91
     */
92
    abstract protected function apiStopUrl($timerId);
93
94
    abstract protected function getOnlineData();
95
96
    /**
97
     * @param $data
98
     */
99
    abstract protected function getProjects($data);
100
101
    abstract protected function getRecentTimers();
102
103
    /**
104
     * @param $data
105
     */
106
    abstract protected function getTags($data);
107
}
108