File size: 2,385 Bytes
550665c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from typing import Callable, Type, Union

from gcsa._resource import Resource
from gcsa._services.authentication import AuthenticatedService


class BaseService(AuthenticatedService):
    def __init__(self, default_calendar, *args, **kwargs):
        """

        :param default_calendar:

                Users email address or name/id of the calendar. Default: primary calendar of the user



                If user's email or "primary" is specified, then primary calendar of the user is used.

                You don't need to specify this parameter in this case as it is a default behaviour.



                To use a different calendar you need to specify its id.

                Go to calendar's `settings and sharing` -> `Integrate calendar` -> `Calendar ID`.

        """
        super().__init__(*args, **kwargs)
        self.default_calendar = default_calendar

    @staticmethod
    def _list_paginated(

            request_method: Callable,

            serializer_cls: Type = None,

            **kwargs

    ):
        page_token = None
        while True:
            response_json = request_method(
                **kwargs,
                pageToken=page_token
            ).execute()
            for item_json in response_json['items']:
                if serializer_cls:
                    yield serializer_cls(item_json).get_object()
                else:
                    yield item_json
            page_token = response_json.get('nextPageToken')
            if not page_token:
                break

    @staticmethod
    def _get_resource_id(resource: Union[Resource, str]):
        """If `resource` is `Resource` returns its id.

        If `resource` is string, returns `resource` itself.



        :raises:

            ValueError: if `resource` is `Resource` object that doesn't have id

            TypeError: if `resource` is neither `Resource` nor `str`

        """
        if isinstance(resource, Resource):
            if resource.id is None:
                raise ValueError("Resource has to have id to be updated, moved or deleted.")
            return resource.id
        elif isinstance(resource, str):
            return resource
        else:
            raise TypeError('"resource" object must be Resource or str, not {!r}'.format(
                resource.__class__.__name__
            ))