further simplified constructors, renamed parent class of token stores, made it an official ABC, updated README
This commit is contained in:
19
README.md
19
README.md
@@ -134,11 +134,26 @@ Finally, once you have an app on that developer page, click into it and click "g
|
||||
|
||||
You should only have to do this once in each environment you use this library in.
|
||||
|
||||
# OAuth Token Stores
|
||||
|
||||
By default this library stores OAuth tokens on disk in whatever working directory its methods are called from. As an alternative you can use Redis via the `avt_fresh.token.TokenStoreOnRedis` at instantiation of an `ApiClient` like so:
|
||||
|
||||
```python
|
||||
client = Client(
|
||||
client_secret="...",
|
||||
client_id="...",
|
||||
redirect_uri="https://...",
|
||||
account_id="...",
|
||||
token_store=avt_fresh.token.TokenStoreOnRedis,
|
||||
connection_string="redis://..." ,
|
||||
)
|
||||
```
|
||||
|
||||
As a further alternative, feel free to implement and inject your own! See `avt_fresh.token.TokenStore` for the API, but tl;dr simply inherit from `TokenStore` and implement `get()` and `set()` methods, the former of which should return an instance of `avt_fresh.token.TokenTup`.
|
||||
|
||||
# Hardcoded Stuff / TODOs
|
||||
Here are some quirks and TODOs. PRs are welcome!:
|
||||
|
||||
OAuth tokens are currently saved in the ever-so-insecure path of `~/freshbooks_oauth_token.json`. TODO: don't do this anymore. ¯\_(ツ)_/¯
|
||||
|
||||
Only Python 3.10 is supported at the moment.
|
||||
|
||||
When it comes to invoice statuses, we're only using `v3_status` strings, not the numbers. What's more, when you create an invoice we're only supporting two possible statuses: "draft" and "paid".
|
||||
|
||||
@@ -28,14 +28,10 @@ class TokenTup(typing.NamedTuple):
|
||||
|
||||
|
||||
@dataclass
|
||||
class Token:
|
||||
class TokenStore(metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def get(cls) -> "Token":
|
||||
...
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete(self) -> None:
|
||||
def get(cls) -> TokenTup:
|
||||
...
|
||||
|
||||
@abc.abstractmethod
|
||||
@@ -43,10 +39,7 @@ class Token:
|
||||
...
|
||||
|
||||
|
||||
class TokenStoreOnDisk(Token):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
class TokenStoreOnDisk(TokenStore):
|
||||
|
||||
@classmethod
|
||||
def get(cls) -> TokenTup:
|
||||
@@ -64,10 +57,9 @@ class TokenStoreOnDisk(Token):
|
||||
json.dump(token_dict, fout)
|
||||
|
||||
|
||||
class TokenStoreOnRedis(Token):
|
||||
class TokenStoreOnRedis(TokenStore):
|
||||
|
||||
def __init__(self, redis_url, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
def __init__(self, redis_url):
|
||||
self.redis_client = redis.from_url(redis_url)
|
||||
|
||||
def get(self) -> TokenTup:
|
||||
|
||||
Reference in New Issue
Block a user