Skip to content

Commit 1b5c9d8

Browse files
committed
Use PSL defined HTTP codes
1 parent 2f6c15e commit 1b5c9d8

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

Diff for: gdax/public_client.py

+13-20
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
#
55
# For public requests to the GDAX exchange
66

7+
from http import HTTPStatus
78
import requests
89
from gdax import exceptions
910

1011

11-
HTTP_200_OK = 200
12-
HTTP_300_MULTIPLE_CHOICES = 300
13-
HTTP_400_BAD_REQUEST = 400
14-
HTTP_401_UNAUTHORIZED = 401
15-
HTTP_403_FORBIDDEN = 403
16-
HTTP_404_NOT_FOUND = 404
17-
HTTP_500_INTERNAL_SERVER_ERROR = 500
18-
1912

2013
class PublicClient(object):
2114
"""GDAX public client API.
@@ -40,15 +33,15 @@ def __init__(self, api_url='https://api.gdax.com', timeout=30):
4033

4134
def _is_http_success(self, code):
4235
# type: (int) -> bool
43-
return code >= HTTP_200_OK and code < HTTP_300_MULTIPLE_CHOICES
36+
return code >= HTTPStatus.OK and code < HTTPStatus.MULTIPLE_CHOICES
4437

4538
def _is_http_client_error(self, code):
4639
# type: (int) -> bool
47-
return code >= HTTP_400_BAD_REQUEST and code < HTTP_500_INTERNAL_SERVER_ERROR
40+
return code >= HTTPStatus.BAD_REQUEST and code < HTTPStatus.INTERNAL_SERVER_ERROR
4841

4942
def _is_http_server_error(self, code):
5043
# type: (int) -> bool
51-
return code >= HTTP_500_INTERNAL_SERVER_ERROR
44+
return code >= HTTPStatus.INTERNAL_SERVER_ERROR
5245

5346
def _determine_response(self, response):
5447
"""
@@ -61,26 +54,26 @@ def _determine_response(self, response):
6154
elif self._is_http_client_error(response.status_code):
6255
body = response.json()
6356
message = body.get('message')
64-
if response.status_code == HTTP_400_BAD_REQUEST:
57+
if response.status_code == HTTPStatus.BAD_REQUEST:
6558
raise exceptions.InvalidGdaxRequest(message,
66-
HTTP_400_BAD_REQUEST)
67-
elif response.status_code == HTTP_401_UNAUTHORIZED:
59+
HTTPStatus.BAD_REQUEST)
60+
elif response.status_code == HTTPStatus.UNAUTHORIZED:
6861
raise exceptions.UnauthorizedGdaxRequest(message,
69-
HTTP_401_UNAUTHORIZED)
70-
elif response.status_code == HTTP_403_FORBIDDEN:
62+
HTTPStatus.UNAUTHORIZED)
63+
elif response.status_code == HTTPStatus.FORBIDDEN:
7164
raise exceptions.ForbiddenGdaxRequest(message,
72-
HTTP_403_FORBIDDEN)
73-
elif response.status_code == HTTP_404_NOT_FOUND:
65+
HTTPStatus.FORBIDDEN)
66+
elif response.status_code == HTTPStatus.NOT_FOUND:
7467
raise exceptions.NotFoundGdaxRequest(message,
75-
HTTP_404_NOT_FOUND)
68+
HTTPStatus.NOT_FOUND)
7669
else: # Other 4XX response not yet mapped
7770
raise exceptions.UnknownGdaxClientRequest(message,
7871
response.status_code)
7972

8073
elif self._is_http_server_error(response.status_code):
8174
body = response.json()
8275
raise exceptions.InternalErrorGdaxRequest(body.get('message'),
83-
HTTP_500_INTERNAL_SERVER_ERROR)
76+
HTTPStatus.INTERNAL_SERVER_ERROR)
8477

8578
def _get(self, path, params=None):
8679
"""Perform get request"""

0 commit comments

Comments
 (0)