app-store-server-library-python icon indicating copy to clipboard operation
app-store-server-library-python copied to clipboard

Raise instead of default to Sandbox enviroment

Open Gerson4G opened this issue 1 year ago • 0 comments

When init an API Client object the parameter typing indicates it shoud receive an Environment type value but if it receives something else (like string representation of it) it pass through correctly and default the enviroment of the instance to Sandbox (https://github.com/apple/app-store-server-library-python/blob/1202058ddf4eac67c66f3947827e042e9ae6eee1/appstoreserverlibrary/api_client.py#L469); which might confuse users who think they are doing it well (It happened to me). I would expect the param to stick to only allow an Environment type value and raise otherwise.

Something like below (two suggestions I have)

class BaseAppStoreServerAPIClient:
    def __init__(self, signing_key: bytes, key_id: str, issuer_id: str, bundle_id: str, environment: Environment):
        Environment[environment] # Just check if env exists and leave it raise if not
        if environment == Environment.XCODE:
            raise ValueError("Xcode is not a supported environment for an AppStoreServerAPIClient")
        if environment == Environment.PRODUCTION:
            self._base_url = "https://api.storekit.itunes.apple.com"
        elif environment == Environment.LOCAL_TESTING:
            self._base_url = "https://local-testing-base-url"
        elif environment == Environment.SANDBOX: # Or leave the else as it is if using an early return to raise
            self._base_url = "https://api.storekit-sandbox.itunes.apple.com"
        else:
            raise ValueError(f"{environment} is not a supported environment")

Gerson4G avatar Oct 01 '24 15:10 Gerson4G