Passed
Push — main ( e94faa...f7ccd1 )
by Leandro
12:54
created

Calendar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 48
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 14 1
A __construct() 0 3 1
A timezone() 0 10 1
A insert() 0 13 1
1
<?php
2
3
namespace LeandroFerreiraMa\GoogleCalendar;
4
5
class Calendar extends GoogleCalendar
6
{
7
    public function __construct(string $token)
8
    {
9
        parent::__construct($token);
10
    }
11
12
    public function read(?array $headers): Calendar
13
    {
14
        $url_parameters = array();
15
16
		$url_parameters['fields'] = 'items(id,summary,timeZone)';
17
		$url_parameters['minAccessRole'] = 'owner';
18
19
        $this->request(
20
            "GET",
21
            "v3/users/me/calendarList?". http_build_query($url_parameters),
22
            null,
23
            $headers
24
        );
25
        return $this;
26
    }
27
28
    public function timezone(?array $headers): ?string
29
    {
30
31
        $this->request(
32
            "POST",
33
            "v3/users/me/settings/timezone",
34
            null,
35
            $headers
36
        );
37
        return $this->response()->value;
38
    }
39
40
    public function insert(string $summary): Calendar
41
    {
42
        $calendar = [
43
            "summary" => $summary
44
        ]; 
45
46
        $this->request(
47
            "POST",
48
            "v3/calendars",
49
            $calendar,
50
            ["Content-Type" => "application/json"]
51
        );
52
        return $this;
53
    }
54
}