feat: Add Booklooker client configuration and exception handling
- Introduced BooklookerConfig class for runtime configuration management. - Created custom exceptions for API errors, including authentication and validation errors. - Generated API contracts from OpenAPI specification, including endpoints and security schemes. - Implemented models for articles, orders, and webhooks to facilitate data handling. - Developed a webhook helper for processing and enriching webhook events. - Added tests for configuration defaults, token expiration, and webhook enrichment.
This commit is contained in:
commit
1d8ee1bba6
21 changed files with 3009 additions and 0 deletions
14
examples/sync_usage.py
Normal file
14
examples/sync_usage.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from booklooker_client import BooklookerConfig, SyncBooklookerClient
|
||||
|
||||
|
||||
api_key = os.environ.get("BOOKLOOKER_API_KEY", "REPLACE_ME")
|
||||
config = BooklookerConfig(api_key=api_key)
|
||||
|
||||
with SyncBooklookerClient(config) as client:
|
||||
token = client.authenticate()
|
||||
print("Token acquired:", token.token)
|
||||
print("Available endpoints:", client.available_endpoints)
|
||||
19
examples/webhook_fastapi.py
Normal file
19
examples/webhook_fastapi.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
|
||||
from booklooker_client import BooklookerConfig, BooklookerWebhookHelper, SyncBooklookerClient
|
||||
|
||||
|
||||
app = FastAPI(title="Booklooker webhook receiver")
|
||||
helper = BooklookerWebhookHelper()
|
||||
client = SyncBooklookerClient(BooklookerConfig(api_key=os.environ.get("BOOKLOOKER_API_KEY", "REPLACE_ME")))
|
||||
|
||||
|
||||
@app.post("/webhooks/booklooker")
|
||||
async def receive_booklooker_webhook(request: Request) -> dict:
|
||||
payload = await request.json()
|
||||
event = helper.enrich_with_client(payload, client)
|
||||
return {"accepted": True, "event": event.model_dump(mode="json")}
|
||||
Loading…
Add table
Add a link
Reference in a new issue