Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise instead of default to Sandbox enviroment #111

Open
Gerson4G opened this issue Oct 1, 2024 · 0 comments
Open

Raise instead of default to Sandbox enviroment #111

Gerson4G opened this issue Oct 1, 2024 · 0 comments

Comments

@Gerson4G
Copy link

Gerson4G commented Oct 1, 2024

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 (

); 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant