File size: 1,035 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
from gcsa.attachment import Attachment
from .base_serializer import BaseSerializer


class AttachmentSerializer(BaseSerializer):
    type_ = Attachment

    def __init__(self, attachment):
        super().__init__(attachment)

    @staticmethod
    def _to_json(attachment: Attachment):
        res = {
            "fileUrl": attachment.file_url,
            "title": attachment.title,
            "mimeType": attachment.mime_type,
        }

        if attachment.file_id:
            res['fileId'] = attachment.file_id
        if attachment.icon_link:
            res['iconLink'] = attachment.icon_link

        return res

    @staticmethod
    def _to_object(json_attachment):
        return Attachment(
            file_url=json_attachment['fileUrl'],
            title=json_attachment.get('title', None),
            mime_type=json_attachment.get('mimeType', None),
            _icon_link=json_attachment.get('iconLink', None),
            _file_id=json_attachment.get('fileId', None)
        )