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.
|
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
|
# Hardcoded Stuff / TODOs
|
||||||
Here are some quirks and TODOs. PRs are welcome!:
|
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.
|
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".
|
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
|
@dataclass
|
||||||
class Token:
|
class TokenStore(metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get(cls) -> "Token":
|
def get(cls) -> TokenTup:
|
||||||
...
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def delete(self) -> None:
|
|
||||||
...
|
...
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@@ -43,10 +39,7 @@ class Token:
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class TokenStoreOnDisk(Token):
|
class TokenStoreOnDisk(TokenStore):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls) -> TokenTup:
|
def get(cls) -> TokenTup:
|
||||||
@@ -64,10 +57,9 @@ class TokenStoreOnDisk(Token):
|
|||||||
json.dump(token_dict, fout)
|
json.dump(token_dict, fout)
|
||||||
|
|
||||||
|
|
||||||
class TokenStoreOnRedis(Token):
|
class TokenStoreOnRedis(TokenStore):
|
||||||
|
|
||||||
def __init__(self, redis_url, **kwargs):
|
def __init__(self, redis_url):
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.redis_client = redis.from_url(redis_url)
|
self.redis_client = redis.from_url(redis_url)
|
||||||
|
|
||||||
def get(self) -> TokenTup:
|
def get(self) -> TokenTup:
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -4,7 +4,7 @@ setup(
|
|||||||
name="avt_fresh",
|
name="avt_fresh",
|
||||||
author="Zev Averbach",
|
author="Zev Averbach",
|
||||||
author_email="zev@averba.ch",
|
author_email="zev@averba.ch",
|
||||||
version="0.0.14",
|
version="0.0.15",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
python_requires=">3.10.0",
|
python_requires=">3.10.0",
|
||||||
keywords="freshbooks API",
|
keywords="freshbooks API",
|
||||||
|
|||||||
Reference in New Issue
Block a user