lagerfeuer / cryptocompare

Python3 Wrapper for the CryptoCompare API
MIT License
181 stars 73 forks source link

Add setting API key without env vars #49

Closed MHHukiewitz closed 2 years ago

MHHukiewitz commented 3 years ago

Add possibility to set the _API_KEY through _set_api_key_parameter(), while the original function has been aptly renamed to _get_api_key_parameter().

To stay in line with documentation, _set_api_key_parameter() has been replaced by a function that allows setting the protected _API_KEY variable, which is being used, in case no api_key has been passed to _query_cryptocompare().

This will keep current code, relying on env vars still running, but enables setting the api_key without manipulating environment variables. In case _API_KEY is set, it will override any API keys set in env vars.

The code should now work as described on https://pypi.org/project/cryptocompare/.

_API_KEY_PARAMETER should be assigned a value, as intended, through the addition of global before the assignment in _get_api_key_parameter().

MHHukiewitz commented 3 years ago

This PR should handle issues related to issue #44.

lagerfeuer commented 3 years ago

Thanks for the PR! Could you please make sure the tests pass? I use pytest and mypy:

python -m mypy cryptocompare/
python -m pytest tests/
MHHukiewitz commented 3 years ago

The tests which fail, are test_sets_api_key_passed_in_works, test_sets_api_key_using_environment_variable and test_sets_api_key_with_no_env_var_and_none_passed, which use the old meaning of _set_api_key_parameter(), which was renamed to _get_api_key_parameter(), so I replaced the function calls where appropriate and renamed the tests accordingly.