Skip to content

Commit

Permalink
add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sharinetmc committed Jan 7, 2025
1 parent 3ad19f1 commit 4cc54c0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions parsons/newmode/newmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(self, api_user=None, api_password=None, api_version=None):
logger.warning(
"Newmode V1 API will be sunset in Feburary 2025. To use V2, set api_version=v2.1"
)
self.api_user = check_env.check("NEWMODE_API_USER", api_user)
self.api_password = check_env.check("NEWMODE_API_PASSWORD", api_password)
self.api_user = api_user
self.api_password = api_password
self.api_version = api_version
self.client = Client(api_user, api_password, api_version)

Expand Down Expand Up @@ -358,8 +358,8 @@ def __init__(
"""
self.api_version = api_version
self.base_url = V2_API_URL
self.client_id = check_env.check("NEWMODE_API_CLIENT_ID", client_id)
self.client_secret = check_env.check("NEWMODE_API_CLIENT_SECRET", client_secret)
self.client_id = client_id
self.client_secret = client_secret
self.headers = {"content-type": "application/json"}

def base_request(
Expand Down Expand Up @@ -601,17 +601,15 @@ def __new__(
NewMode Class
"""
api_version = check_env.check("NEWMODE_API_VERSION", api_version)
client_id = check_env.check("NEWMODE_API_CLIENT_ID", client_id)
client_secret = check_env.check("NEWMODE_API_CLIENT_SECRET", client_secret)
api_user = check_env.check("NEWMODE_API_USER", api_user)
api_password = check_env.check("NEWMODE_API_PASSWORD", api_password)

if api_version.startswith("v2"):
if not client_id:
raise ValueError("Missing client_id")
if not client_secret:
raise ValueError("Missing client_secret")
return NewmodeV2(
client_id=client_id, client_secret=client_secret, api_version=api_version
)
else:
if not api_user:
raise ValueError("Missing api_user")
if not api_password:
raise ValueError("Missing api_password")
if api_version.startswith("v1"):
return NewmodeV1(api_user=api_user, api_password=api_password, api_version=api_version)
raise ValueError(f"{api_version} not supported.")

0 comments on commit 4cc54c0

Please sign in to comment.