miro_api.storage

 1from dataclasses import dataclass
 2from abc import ABC, abstractmethod
 3import datetime
 4
 5from typing import Optional
 6
 7
 8@dataclass
 9class State:
10    """
11    A dataclass containing access token, refresh token and access token expiration time
12    """
13
14    access_token: str
15    refresh_token: Optional[str]
16    token_expires_at: Optional[datetime.datetime]
17
18
19class Storage(ABC):
20    """Abstract class that's used by the stateful client to set and get State."""
21
22    @abstractmethod
23    def set(self, state: Optional[State]) -> None:
24        pass
25
26    @abstractmethod
27    def get(self) -> Optional[State]:
28        pass
29
30
31class InMemoryStorage(Storage):
32    """In memory implementation of the `Storage`. Not recommended to be used in production."""
33
34    def __init__(self):
35        self.data: Optional[State] = None
36
37    def set(self, state: Optional[State]) -> None:
38        self.data = state
39
40    def get(self) -> Optional[State]:
41        return self.data
@dataclass
class State:
 9@dataclass
10class State:
11    """
12    A dataclass containing access token, refresh token and access token expiration time
13    """
14
15    access_token: str
16    refresh_token: Optional[str]
17    token_expires_at: Optional[datetime.datetime]

A dataclass containing access token, refresh token and access token expiration time

State( access_token: str, refresh_token: Optional[str], token_expires_at: Optional[datetime.datetime])
access_token: str
refresh_token: Optional[str]
token_expires_at: Optional[datetime.datetime]
class Storage(abc.ABC):
20class Storage(ABC):
21    """Abstract class that's used by the stateful client to set and get State."""
22
23    @abstractmethod
24    def set(self, state: Optional[State]) -> None:
25        pass
26
27    @abstractmethod
28    def get(self) -> Optional[State]:
29        pass

Abstract class that's used by the stateful client to set and get State.

@abstractmethod
def set(self, state: Optional[State]) -> None:
23    @abstractmethod
24    def set(self, state: Optional[State]) -> None:
25        pass
@abstractmethod
def get(self) -> Optional[State]:
27    @abstractmethod
28    def get(self) -> Optional[State]:
29        pass
class InMemoryStorage(Storage):
32class InMemoryStorage(Storage):
33    """In memory implementation of the `Storage`. Not recommended to be used in production."""
34
35    def __init__(self):
36        self.data: Optional[State] = None
37
38    def set(self, state: Optional[State]) -> None:
39        self.data = state
40
41    def get(self) -> Optional[State]:
42        return self.data

In memory implementation of the Storage. Not recommended to be used in production.

data: Optional[State]
def set(self, state: Optional[State]) -> None:
38    def set(self, state: Optional[State]) -> None:
39        self.data = state
def get(self) -> Optional[State]:
41    def get(self) -> Optional[State]:
42        return self.data