import requests import logging import json MEMOS_VISIBILITY_UNSPECIFIED = 'VISIBILITY_UNSPECIFIED' MEMOS_VISIBILITY_PRIVATE = 'PRIVATE' MEMOS_VISIBILITY_PROTECTED = 'PROTECTED' MEMOS_VISIBILITY_PUBLIC = 'PUBLIC' class Memos: def __init__(self, token: str, base_url: str) -> None: self.token = token self.base_url = base_url self.custom_header = dict(Authorization=f'Bearer {token}') self.create_memo_url = base_url + '/api/v1/memos' self.logger = logging.getLogger('memos') def create_memo(self, content:str, visibility: str, **kwargs) -> None: body = json.dumps(dict(content=content, visibility=visibility) | kwargs) r = requests.post(self.create_memo_url, data=body, headers=self.custom_header) if r.status_code == 200: result = r.json() self.logger.info("Memo created: " + result['name']) else: self.logger.error("Failed to create memo: " + r.text)