Skip to content

Commit 3434742

Browse files
authored
Merge pull request #51 from maxmind/greg/user-id-to-account-id
Replace user ID usage with account ID
2 parents cb96185 + ec20d27 commit 3434742

File tree

7 files changed

+85
-73
lines changed

7 files changed

+85
-73
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
language: python
33
python:
4-
- '2.6'
54
- '2.7'
65
- '3.3'
76
- '3.4'
@@ -27,7 +26,6 @@ before_install:
2726
install:
2827
- pip install -r requirements.txt
2928
- pip install requests_mock pylint coveralls
30-
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2 ipaddr; fi"
3129
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install ipaddr; fi"
3230
script:
3331
- coverage run --source=geoip2 setup.py test

HISTORY.rst

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

6+
2.8.0
7+
+++++++++++++++++
8+
9+
* Python 2.6 support has been dropped. Python 2.7+ or 3.3+ is now required.
10+
* Renamed user ID to account ID in the code and added support for the new
11+
``ACCOUNT_ID_REQUIRED`` AND ``ACCOUNT_ID_UNKNOWN`` error codes.
12+
613
2.7.0 (2018-01-18)
714
++++++++++++++++++
815

README.rst

Lines changed: 3 additions & 3 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
>>>
@@ -385,7 +385,7 @@ correction, please `contact MaxMind support
385385
Requirements
386386
------------
387387

388-
This code requires Python 2.6+ or 3.3+. Older versions are not supported.
388+
This code requires Python 2.7+ or 3.3+. Older versions are not supported.
389389
This library has been tested with CPython and PyPy.
390390

391391
The Requests HTTP library is also required. See

docs/conf.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
# Add any Sphinx extension module names here, as strings. They can be extensions
3030
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
31-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
32-
'sphinx.ext.intersphinx', 'sphinx.ext.coverage']
31+
extensions = [
32+
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
33+
'sphinx.ext.coverage'
34+
]
3335

3436
# Add any paths that contain templates here, relative to this directory.
3537
templates_path = ['_templates']
@@ -90,7 +92,6 @@
9092
# A list of ignored prefixes for module index sorting.
9193
#modindex_common_prefix = []
9294

93-
9495
# -- Options for HTML output ---------------------------------------------
9596

9697
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -170,7 +171,6 @@
170171
# Output file base name for HTML help builder.
171172
htmlhelp_basename = 'geoip2doc'
172173

173-
174174
# -- Options for LaTeX output --------------------------------------------
175175

176176
latex_elements = {
@@ -187,8 +187,8 @@
187187
# Grouping the document tree into LaTeX files. List of tuples
188188
# (source start file, target name, title, author, documentclass [howto/manual]).
189189
latex_documents = [
190-
('index', 'geoip2.tex', 'geoip2 Documentation',
191-
'Gregory Oschwald', 'manual'),
190+
('index', 'geoip2.tex', 'geoip2 Documentation', 'Gregory Oschwald',
191+
'manual'),
192192
]
193193

194194
# The name of an image file (relative to this directory) to place at the top of
@@ -211,29 +211,24 @@
211211
# If false, no module index is generated.
212212
#latex_domain_indices = True
213213

214-
215214
# -- Options for manual page output --------------------------------------
216215

217216
# One entry per manual page. List of tuples
218217
# (source start file, name, description, authors, manual section).
219-
man_pages = [
220-
('index', 'geoip2', 'geoip2 Documentation',
221-
['Gregory Oschwald'], 1)
222-
]
218+
man_pages = [('index', 'geoip2', 'geoip2 Documentation', ['Gregory Oschwald'],
219+
1)]
223220

224221
# If true, show URL addresses after external links.
225222
#man_show_urls = False
226223

227-
228224
# -- Options for Texinfo output ------------------------------------------
229225

230226
# Grouping the document tree into Texinfo files. List of tuples
231227
# (source start file, target name, title, author,
232228
# dir menu entry, description, category)
233229
texinfo_documents = [
234-
('index', 'geoip2', 'geoip2 Documentation',
235-
'Gregory Oschwald', 'geoip2', 'One line description of project.',
236-
'Miscellaneous'),
230+
('index', 'geoip2', 'geoip2 Documentation', 'Gregory Oschwald', 'geoip2',
231+
'One line description of project.', 'Miscellaneous'),
237232
]
238233

239234
# Documents to append as an appendix to all manuals.
@@ -245,6 +240,5 @@
245240
# How to display URL addresses: 'footnote', 'no', or 'inline'.
246241
#texinfo_show_urls = 'footnote'
247242

248-
249243
# Example configuration for intersphinx: refer to the Python standard library.
250244
intersphinx_mapping = {'http://docs.python.org/': None}

geoip2/webservice.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ 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
51-
User ID and license key.
51+
account ID and license key.
5252
5353
The following keyword arguments are also accepted:
5454
@@ -82,20 +82,34 @@ class Client(object):
8282
8383
"""
8484

85-
def __init__(self,
86-
user_id,
87-
license_key,
88-
host='geoip.maxmind.com',
89-
locales=None,
90-
timeout=None):
85+
def __init__(
86+
self,
87+
account_id=None,
88+
license_key=None,
89+
host='geoip.maxmind.com',
90+
locales=None,
91+
timeout=None,
92+
93+
# This is deprecated and not documented for that reason.
94+
# It can be removed if we do a major release in the future.
95+
user_id=None):
9196
"""Construct a Client."""
9297
# pylint: disable=too-many-arguments
9398
if locales is None:
9499
locales = ['en']
100+
if account_id is None:
101+
account_id = user_id
102+
103+
if account_id is None:
104+
raise TypeError('The account_id is a required parameter')
105+
if license_key is None:
106+
raise TypeError('The license_key is a required parameter')
107+
95108
self._locales = locales
96109
# requests 2.12.2 requires that the username passed to auth be bytes
97110
# or a string, with the former being preferred.
98-
self._user_id = user_id if isinstance(user_id, bytes) else str(user_id)
111+
self._account_id = account_id if isinstance(account_id,
112+
bytes) else str(account_id)
99113
self._license_key = license_key
100114
self._base_uri = 'https://%s/geoip/v2.1' % host
101115
self._timeout = timeout
@@ -143,7 +157,7 @@ def _response_for(self, path, model_class, ip_address):
143157
uri = '/'.join([self._base_uri, path, ip_address])
144158
response = requests.get(
145159
uri,
146-
auth=(self._user_id, self._license_key),
160+
auth=(self._account_id, self._license_key),
147161
headers={
148162
'Accept': 'application/json',
149163
'User-Agent': self._user_agent()
@@ -201,7 +215,8 @@ def _exception_for_4xx_status(self, response, status, uri):
201215
def _exception_for_web_service_error(self, message, code, status, uri):
202216
if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
203217
return AddressNotFoundError(message)
204-
elif code in ('AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
218+
elif code in ('ACCOUNT_ID_REQUIRED', 'ACCOUNT_ID_UNKNOWN',
219+
'AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
205220
'USER_ID_REQUIRED', 'USER_ID_UNKNOWN'):
206221
return AuthenticationError(message)
207222
elif code in ('INSUFFICIENT_FUNDS', 'OUT_OF_QUERIES'):

setup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
package_data={'': ['LICENSE']},
2525
package_dir={'geoip2': 'geoip2'},
2626
include_package_data=True,
27+
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*',
2728
install_requires=requirements,
28-
extras_require={
29-
':python_version=="2.6" or python_version=="2.7"': ['ipaddress']
30-
},
29+
extras_require={':python_version=="2.7"': ['ipaddress']},
3130
tests_require=['requests_mock>=0.5'],
3231
test_suite="tests",
3332
license=geoip2.__license__,
@@ -37,7 +36,6 @@
3736
'Intended Audience :: Developers',
3837
'Intended Audience :: System Administrators',
3938
'License :: OSI Approved :: Apache Software License',
40-
'Programming Language :: Python :: 2.6',
4139
'Programming Language :: Python :: 2.7',
4240
'Programming Language :: Python :: 3',
4341
'Programming Language :: Python :: 3.3',
@@ -47,4 +45,5 @@
4745
'Programming Language :: Python',
4846
'Topic :: Internet :: Proxy Servers',
4947
'Topic :: Internet',
50-
], )
48+
],
49+
)

0 commit comments

Comments
 (0)