Skip to content

Commit 3a15a91

Browse files
committed
Replace user ID usage with account ID
1 parent cb96185 commit 3a15a91

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
History
44
-------
55

6+
2.8.0
7+
+++++++++++++++++
8+
9+
* Renamed user ID to account ID in the code and added support for the new
10+
``ACCOUNT_ID_REQUIRED`` AND ``ACCOUNT_ID_UNKNOWN`` error codes.
11+
612
2.7.0 (2018-01-18)
713
++++++++++++++++++
814

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Usage
4646
-----
4747

4848
To use this API, you first create either a web service object with your
49-
MaxMind ``user_id`` and ``license_key`` or a database reader object with the
49+
MaxMind ``account_id`` and ``license_key`` or a database reader object with the
5050
path to your database file. After doing this, you may call the method
5151
corresponding to request type (e.g., ``city`` or ``country``), passing it the
5252
IP address you want to look up.
@@ -65,7 +65,7 @@ Web Service Example
6565
>>> import geoip2.webservice
6666
>>>
6767
>>> # This creates a Client object that can be reused across requests.
68-
>>> # Replace "42" with your user ID and "license_key" with your license
68+
>>> # Replace "42" with your account ID and "license_key" with your license
6969
>>> # key.
7070
>>> client = geoip2.webservice.Client(42, 'license_key')
7171
>>>

geoip2/webservice.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Client(object):
4444
4545
It accepts the following required arguments:
4646
47-
:param user_id: Your MaxMind User ID.
47+
:param account_id: Your MaxMind account ID.
4848
:param license_key: Your MaxMind license key.
4949
5050
Go to https://www.maxmind.com/en/my_license_key to see your MaxMind
@@ -83,7 +83,7 @@ class Client(object):
8383
"""
8484

8585
def __init__(self,
86-
user_id,
86+
account_id,
8787
license_key,
8888
host='geoip.maxmind.com',
8989
locales=None,
@@ -95,7 +95,8 @@ def __init__(self,
9595
self._locales = locales
9696
# requests 2.12.2 requires that the username passed to auth be bytes
9797
# or a string, with the former being preferred.
98-
self._user_id = user_id if isinstance(user_id, bytes) else str(user_id)
98+
self._account_id = account_id if isinstance(account_id,
99+
bytes) else str(account_id)
99100
self._license_key = license_key
100101
self._base_uri = 'https://%s/geoip/v2.1' % host
101102
self._timeout = timeout
@@ -143,7 +144,7 @@ def _response_for(self, path, model_class, ip_address):
143144
uri = '/'.join([self._base_uri, path, ip_address])
144145
response = requests.get(
145146
uri,
146-
auth=(self._user_id, self._license_key),
147+
auth=(self._account_id, self._license_key),
147148
headers={
148149
'Accept': 'application/json',
149150
'User-Agent': self._user_agent()
@@ -201,7 +202,8 @@ def _exception_for_4xx_status(self, response, status, uri):
201202
def _exception_for_web_service_error(self, message, code, status, uri):
202203
if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
203204
return AddressNotFoundError(message)
204-
elif code in ('AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
205+
elif code in ('ACCOUNT_ID_REQUIRED', 'ACCOUNT_ID_UNKNOWN',
206+
'AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
205207
'USER_ID_REQUIRED', 'USER_ID_UNKNOWN'):
206208
return AuthenticationError(message)
207209
elif code in ('INSUFFICIENT_FUNDS', 'OUT_OF_QUERIES'):

tests/webservice_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,18 @@ def test_license_key_required(self, mock):
221221
self._test_error(mock, 401, 'LICENSE_KEY_REQUIRED',
222222
AuthenticationError)
223223

224+
@requests_mock.mock()
225+
def test_account_id_required(self, mock):
226+
self._test_error(mock, 401, 'ACCOUNT_ID_REQUIRED', AuthenticationError)
227+
224228
@requests_mock.mock()
225229
def test_user_id_required(self, mock):
226230
self._test_error(mock, 401, 'USER_ID_REQUIRED', AuthenticationError)
227231

232+
@requests_mock.mock()
233+
def test_account_id_unkown(self, mock):
234+
self._test_error(mock, 401, 'ACCOUNT_ID_UNKNOWN', AuthenticationError)
235+
228236
@requests_mock.mock()
229237
def test_user_id_unkown(self, mock):
230238
self._test_error(mock, 401, 'USER_ID_UNKNOWN', AuthenticationError)

0 commit comments

Comments
 (0)