diff --git a/pyproject.toml b/pyproject.toml index 841cac2..7df2305 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ authors = [ ] requires-python = ">=3.10" urls = { "project" = "https://github.com/serraict/vine-floriday-adapter", "docs" = "https://github.com/serraict/vine-floriday-adapter/blob/main/README.md" } -dependencies = ["typer", "minio", "requests"] +dependencies = ["typer", "minio", "requests", "floriday-supplier-client"] dynamic = ["version"] license.file = "LICENCE" diff --git a/src/floridayvine/floriday.py b/src/floridayvine/floriday.py deleted file mode 100644 index b094977..0000000 --- a/src/floridayvine/floriday.py +++ /dev/null @@ -1,78 +0,0 @@ -import os -from pprint import pprint -import requests - -CLIENT_ID = os.getenv("FLORIDAY_CLIENT_ID") -CLIENT_SECRET = os.getenv("FLORIDAY_CLIENT_SECRET") -API_KEY = os.getenv("FLORIDAY_API_KEY") -AUTH_URL = os.getenv("FLORIDAY_AUTH_URL") -BASE_URL = os.getenv("FLORIDAY_BASE_URL") - -payload = { - "grant_type": "client_credentials", - "client_id": CLIENT_ID, - "client_secret": CLIENT_SECRET, - "scope": "role:app catalog:read sales-order:write organization:read supply:read supply:write sales-order:read delivery-conditions:read fulfillment:write fulfillment:read", -} - -headers = { - "Accept": "application/json", - "Content-Type": "application/x-www-form-urlencoded", -} - - -def get_access_token(): - response = requests.request("POST", AUTH_URL, headers=headers, data=payload) - response.raise_for_status() - return response.json().get("access_token") - - -def get_organizations(): - access_token = get_access_token() - url = f"{BASE_URL}/auth/key" - - headers = { - "X-Api-Key": API_KEY, - "Accept": "application/json", - "Authorization": f"Bearer {access_token}", - } - - response = requests.get(url, headers=headers) - response.raise_for_status() - return response.json() - - -def get_trade_items(): - access_token = get_access_token() - url = f"{BASE_URL}/trade-items" - - headers = { - "X-Api-Key": API_KEY, - "Accept": "application/json", - "Authorization": f"Bearer {access_token}", - } - base_sync_number = 0 - sync_items = sync_trade_items(base_sync_number) - max_sync_number = sync_items.get("maximumSequenceNumber") - results = sync_items.get("results") - print(f"{len(results)} trade items synced ({base_sync_number}..{max_sync_number})") - # pprint(items) - - response = requests.get(url, headers=headers) - response.raise_for_status() - return response.json() - - -def sync_trade_items(base_sync_number=0): - access_token = get_access_token() - url = f"{BASE_URL}/trade-items/sync/{base_sync_number}" - - headers = { - "X-Api-Key": API_KEY, - "Accept": "application/json", - "Authorization": f"Bearer {access_token}", - } - - response = requests.get(url, headers=headers) - response.raise_for_status() - return response.json() diff --git a/src/floridayvine/floriday/misc.py b/src/floridayvine/floriday/misc.py index b094977..aa1e788 100644 --- a/src/floridayvine/floriday/misc.py +++ b/src/floridayvine/floriday/misc.py @@ -2,6 +2,8 @@ from pprint import pprint import requests +from floriday_supplier_client import TradeItemsApi, api_factory + CLIENT_ID = os.getenv("FLORIDAY_CLIENT_ID") CLIENT_SECRET = os.getenv("FLORIDAY_CLIENT_SECRET") API_KEY = os.getenv("FLORIDAY_API_KEY") @@ -27,6 +29,9 @@ def get_access_token(): return response.json().get("access_token") +_api_factory = api_factory.ApiFactory() + + def get_organizations(): access_token = get_access_token() url = f"{BASE_URL}/auth/key" @@ -43,24 +48,9 @@ def get_organizations(): def get_trade_items(): - access_token = get_access_token() - url = f"{BASE_URL}/trade-items" - - headers = { - "X-Api-Key": API_KEY, - "Accept": "application/json", - "Authorization": f"Bearer {access_token}", - } - base_sync_number = 0 - sync_items = sync_trade_items(base_sync_number) - max_sync_number = sync_items.get("maximumSequenceNumber") - results = sync_items.get("results") - print(f"{len(results)} trade items synced ({base_sync_number}..{max_sync_number})") - # pprint(items) - - response = requests.get(url, headers=headers) - response.raise_for_status() - return response.json() + api = TradeItemsApi(_api_factory.get_api_client()) + items = api.get_trade_items() + return items def sync_trade_items(base_sync_number=0): diff --git a/work/backlog.md b/work/backlog.md index f10d68b..88b3fa8 100644 --- a/work/backlog.md +++ b/work/backlog.md @@ -7,25 +7,25 @@ Containers are pushed to . ## Doing -* Retrieve trade-item information. +* generate an api client ## Next -* Goal: connect to Floriday. - * Understand and implement a client for Floriday synchronization mechanism - * implement it for trade items - * Experiment: generate mock server from api definition for local development - -## Later - * Goal: have a decent developer experience - * generate an api * use the api to implement a generic sync implementation * learn about typer wrt exceptions and exit codes * document versioning strategy: what will we do when the api updates * organize typer commands into submodules + * Experiment: generate mock server from api definition for local development + +## Later + * Goal: show open quotations for a supplier on Floriday. * retrieve "Supply Line" information * create a Serra Vine dashboard for open quotations +* Goal: learn/ understand the FLoriday api + * Watch Floriday instruction videos and read som tutorials + * Understand and implement a client for Floriday synchronization mechanism + * implement it for trade items ## Out of Scope