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

Calendar::insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
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
}