Finished check health endpoint.
This commit is contained in:
parent
6f24b1f3e0
commit
b51b006bd1
1 changed files with 20 additions and 0 deletions
|
|
@ -6,5 +6,25 @@ from woocommerce import API
|
|||
API_CONFIG = dotenv_values(
|
||||
dotenv_path=Path.home() / Path(".camisatoshi-wordpress-reports/.env")
|
||||
)
|
||||
|
||||
|
||||
def check_health():
|
||||
print(f"Connecting to the configured woocomerce at {API_CONFIG['URL']}")
|
||||
wc_api = API(
|
||||
url=API_CONFIG["URL"],
|
||||
consumer_key=API_CONFIG["CONSUMER_KEY"],
|
||||
consumer_secret=API_CONFIG["CONSUMER_SECRET"],
|
||||
version=API_CONFIG["VERSION"],
|
||||
)
|
||||
|
||||
try:
|
||||
api_reported_version = wc_api.get("").json()["namespace"]
|
||||
except:
|
||||
raise ConnectionError(
|
||||
"There was an issue connecting to the woocomerce API."
|
||||
)
|
||||
|
||||
print(f"Informed version of the API: {API_CONFIG['VERSION']}")
|
||||
print(f"Version reported by the API itself: {api_reported_version}")
|
||||
|
||||
print("Connection successful. The API is reachable.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue