Skip to content

Commit

Permalink
Mark a few arguments of the Client class as deprecated
Browse files Browse the repository at this point in the history
These don't seem too useful, so deprecating them

- host: quite unlikely to change
- use_ssl: we should default to True
- do_not_compress_reponse: limited use in tests
  • Loading branch information
browniebroke committed May 2, 2020
1 parent 52fb2d4 commit 9433b40
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
44 changes: 30 additions & 14 deletions deezer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Implements a client class to query the
`Deezer API <http://developers.deezer.com/api>`_
"""
import warnings
from urllib.parse import urlencode

import requests
Expand All @@ -19,6 +20,11 @@
)
from deezer.utils import SortedDict

DEPRECATED_ARG_MESSAGE = (
"The `{arg_name}` keyword argument is deprecated "
"and will be removed in the next major release."
)


class Client:
"""
Expand All @@ -42,9 +48,14 @@ class Client:
:param app_id: appliication ID.
:param app_secret: application secret.
:param access_token: user access token.
:param host: override the default hostname.
:param use_ssl: connect using HTTP is set to `False`.
:param headers: a dictionary of headers to be used.
.. deprecated:: 1.4.0
The following parameters will be removed in the next major version:
* **host** - override the default hostname.
* **use_ssl** - connect using HTTP if set to `False`.
"""

objects_types = {
Expand All @@ -63,24 +74,27 @@ class Client:
}

def __init__(
self,
app_id=None,
app_secret=None,
access_token=None,
host="api.deezer.com",
use_ssl=True,
headers=None,
**kwargs
self, app_id=None, app_secret=None, access_token=None, headers=None, **kwargs
):
self.app_id = app_id
self.app_secret = app_secret
self.access_token = access_token
self.use_ssl = use_ssl
self.host = host
self.host = "api.deezer.com"
self.use_ssl = True
self.session = requests.Session()

# Do not compress the response: to be readable in tests (cassettes)
# Deprecated arguments
deprecated_kwargs = ["host", "use_ssl"]
for arg_name in deprecated_kwargs:
arg_value = kwargs.get(arg_name)
if arg_value is not None:
warnings.warn(DEPRECATED_ARG_MESSAGE.format(arg_name=arg_name))
setattr(self, arg_name, arg_value)

if kwargs.get("do_not_compress_reponse"):
warnings.warn(
DEPRECATED_ARG_MESSAGE.format(arg_name="do_not_compress_reponse")
)
self.session.headers.update({"Accept-Encoding": "identity"})

# Headers
Expand Down Expand Up @@ -167,7 +181,9 @@ def get_object(
json = response.json()
if "error" in json:
raise ValueError(
"API request return error for object: %s id: %s" % (object_t, object_id)
"API request return error for object: {} id: {}".format(
object_t, object_id
)
)
return self._process_json(json, parent)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ max-complexity = 10
max-line-length = 120

[tool:pytest]
addopts = -v --cov=deezer
addopts = -v -Wdefault --cov=deezer

[isort]
multi_line_output = 3
Expand Down
6 changes: 2 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
class BaseTestCaseWithVcr(vcr_unittest.VCRTestCase):
def setUp(self):
super().setUp()
self.client = deezer.Client( # nosec
app_id="foo", app_secret="bar", do_not_compress_reponse=True
)
self.unsec_client = deezer.Client(use_ssl=False, do_not_compress_reponse=True)
self.client = deezer.Client(app_id="foo", app_secret="bar") # nosec
self.unsec_client = deezer.Client(use_ssl=False)
self.client_fr = deezer.Client(headers={"Accept-Language": "fr"}) # French
self.client_ja = deezer.Client(headers={"Accept-Language": "ja"}) # Japanese
2 changes: 1 addition & 1 deletion tests/test_tornado_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class TestAsyncClient(vcr_unittest.VCRTestCase):
def setUp(self):
super().setUp()
self.client = AsyncClient(do_not_compress_reponse=False)
self.client = AsyncClient()

def test_get_object(self):
@tornado.gen.coroutine
Expand Down

0 comments on commit 9433b40

Please sign in to comment.