Skip to content

Commit f763930

Browse files
committed
Merge pull request #12 from maxmind/greg/ws-v2.1
Update Python API for v2.1 of web services
2 parents aa95981 + 7d0fc0f commit f763930

File tree

11 files changed

+170
-223
lines changed

11 files changed

+170
-223
lines changed

HISTORY.rst

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

6+
0.6.0 (2014-07-XX)
7+
++++++++++++++++++
8+
9+
* The web service client API has been updated for the v2.1 release of the web
10+
service. In particular, the ``city_isp_org`` and ``omni`` methods on
11+
``geoip2.webservice.Client`` should be considered deprecated. The ``city``
12+
method now provides all of the data formerly provided by ``city_isp_org``,
13+
and the ``omni`` method has been replaced by the ``insights`` method.
14+
15+
616
0.5.1 (2014-03-28)
717
++++++++++++++++++
818

@@ -26,13 +36,13 @@ History
2636
0.4.1 (2013-10-25)
2737
++++++++++++++++++
2838

29-
* Read in `README.rst` as UTF-8 in `setup.py`.
39+
* Read in ``README.rst`` as UTF-8 in ``setup.py``.
3040

3141
0.4.0 (2013-10-21)
3242
++++++++++++++++++
3343

34-
* API CHANGE: Changed the `languages` keyword argument to `locales` on the
35-
constructors for `geoip.webservice.Client` and `geoip.database.Reader`.
44+
* API CHANGE: Changed the ``languages`` keyword argument to ``locales`` on the
45+
constructors for ``geoip.webservice.Client`` and ``geoip.database.Reader``.
3646

3747
0.3.1 (2013-10-15)
3848
++++++++++++++++++
@@ -42,17 +52,17 @@ History
4252
0.3.0 (2013-10-15)
4353
++++++++++++++++++
4454

45-
* IMPORTANT: `geoip.webservices` was renamed `geoip.webservice` as it
55+
* IMPORTANT: ``geoip.webservices`` was renamed ``geoip.webservice`` as it
4656
contains only one class.
47-
* Added GeoIP2 database reader using maxminddb. This does not work with PyPy
48-
as it relies on a C extension.
57+
* Added GeoIP2 database reader using ``maxminddb``. This does not work with
58+
PyPy as it relies on a C extension.
4959
* Added more specific exceptions for web service client.
5060

5161
0.2.2 (2013-06-20)
5262
++++++++++++++++++
5363

54-
* Fixed a bug in the model objects that prevented `longitude` and `metro_code`
55-
from being used.
64+
* Fixed a bug in the model objects that prevented ``longitude`` and
65+
``metro_code`` from being used.
5666

5767
0.2.1 (2013-06-10)
5868
++++++++++++++++++
@@ -64,9 +74,9 @@ History
6474
++++++++++++++++++
6575

6676
* Support for Python 3.2 was dropped.
67-
* The methods to call the web service on the `Client` object now validate
77+
* The methods to call the web service on the ``Client`` object now validate
6878
the IP addresses before calling the web service. This requires the
69-
`ipaddr` module on Python 2.x.
79+
``ipaddr`` module on Python 2.x.
7080
* We now support more languages. The new languages are de, es, fr, and pt-BR.
7181
* The REST API now returns a record with data about your account. There is
7282
a new geoip.records.MaxMind class for this data.

README.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ Web Service Example
7070
>>> # key.
7171
>>> client = geoip2.webservice.Client(42, 'license_key')
7272
>>>
73-
>>> # Replace "omni" with the method corresponding to the web service
74-
>>> # that you are using, e.g., "country", "city_isp_org", "city".
75-
>>> response = client.omni('128.101.101.101')
73+
>>> # Replace "insights" with the method corresponding to the web service
74+
>>> # that you are using, e.g., "country", "city".
75+
>>> response = client.insights('128.101.101.101')
7676
>>>
7777
>>> response.country.iso_code
7878
'US'
@@ -101,8 +101,8 @@ Web Service Client Exceptions
101101
-----------------------------
102102

103103
For details on the possible errors returned by the web service itself, see
104-
http://dev.maxmind.com/geoip/geoip2/web-services for the GeoIP2 web service
105-
docs.
104+
http://dev.maxmind.com/geoip/geoip2/web-services for the GeoIP2 Precision web
105+
service docs.
106106

107107
If the web service returns an explicit error document, this is thrown as a
108108
``AddressNotFoundError``, ``AuthenticationError``, ``InvalidRequestError``, or
@@ -162,6 +162,8 @@ City Database
162162
Connection-Type Database
163163
^^^^^^^^^^^^^^^^^^^^^^^^
164164

165+
.. code-block:: pycon
166+
165167
>>> import geoip2.database
166168
>>>
167169
>>> # This creates a Reader object. You should use the same object
@@ -180,6 +182,8 @@ Connection-Type Database
180182
Domain Database
181183
^^^^^^^^^^^^^^^
182184

185+
.. code-block:: pycon
186+
183187
>>> import geoip2.database
184188
>>>
185189
>>> # This creates a Reader object. You should use the same object
@@ -197,6 +201,8 @@ Domain Database
197201
ISP Database
198202
^^^^^^^^^^^^
199203

204+
.. code-block:: pycon
205+
200206
>>> import geoip2.database
201207
>>>
202208
>>> # This creates a Reader object. You should use the same object

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
# General information about the project.
4545
project = 'geoip2'
46-
copyright = '2013, Gregory Oschwald'
46+
copyright = '2014, MaxMind, Inc.'
4747

4848
# The version info for the project you're documenting, acts as replacement for
4949
# |version| and |release|, also used in various other places throughout the

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ Indices and tables
3838
* :ref:`modindex`
3939
* :ref:`search`
4040

41-
:copyright: (c) 2013 by MaxMind, Inc.
41+
:copyright: (c) 2014 by MaxMind, Inc.
4242
:license: Apache License, Version 2.0
4343

geoip2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint:disable=C0111
22

33
__title__ = 'geoip2'
4-
__version__ = '0.5.1'
4+
__version__ = '0.6.0'
55
__author__ = 'Gregory Oschwald'
66
__license__ = 'Apache License, Version 2.0'
77
__copyright__ = 'Copyright 2014 Maxmind, Inc.'

geoip2/database.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class Reader(object):
1616
1717
Instances of this class provide a reader for the GeoIP2 database format.
1818
IP addresses can be looked up using the ``country`` and ``city`` methods.
19-
We also provide ``city_isp_org`` and ``omni`` methods to ease
20-
compatibility with the web service client.
2119
2220
Usage
2321
-----
@@ -68,26 +66,30 @@ def city(self, ip_address):
6866
return self._model_for(geoip2.models.City, ip_address)
6967

7068
def city_isp_org(self, ip_address):
71-
"""Get the CityISPOrg object for the IP address
69+
"""Get the City object for the IP address
7270
7371
:param ip_address: IPv4 or IPv6 address as a string. If no address
7472
is provided.
7573
76-
:returns: :py:class:`geoip2.models.CityISPOrg` object
74+
:returns: :py:class:`geoip2.models.City` object
7775
76+
.. deprecated:: 0.6.0
77+
Use :py:method:`city` instead.
7878
"""
7979

80-
return self._model_for(geoip2.models.CityISPOrg, ip_address)
80+
return self.city(ip_address)
8181

8282
def omni(self, ip_address):
83-
"""Get the Omni object for the IP address
83+
"""Get the Insights object for the IP address
8484
8585
:param ip_address: IPv4 or IPv6 address as a string.
8686
87-
:returns: :py:class:`geoip2.models.Omni` object
87+
:returns: :py:class:`geoip2.models.Insights` object
8888
89+
.. deprecated:: 0.6.0
90+
Use :py:method:`city` instead.
8991
"""
90-
return self._model_for(geoip2.models.Omni, ip_address)
92+
return self._model_for(geoip2.models.Insights, ip_address)
9193

9294
def connection_type(self, ip_address):
9395
"""Get the ConnectionType object for the IP address

geoip2/models.py

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
======
44
55
These classes provide models for the data returned by the GeoIP2
6-
end points.
6+
web service and databases.
77
8-
The only difference between the City, City/ISP/Org, and Omni model classes is
9-
which fields in each record may be populated. See
8+
The only difference between the City and Insights model classes is which
9+
fields in each record may be populated. See
1010
http://dev.maxmind.com/geoip/geoip2/web-services for more details.
1111
1212
"""
@@ -16,7 +16,7 @@
1616

1717
class Country(object):
1818

19-
"""Model class for the GeoIP2 Country
19+
"""Model for the GeoIP2 Precision: Country and the GeoIP2 Country database
2020
2121
This class provides the following attributes:
2222
@@ -51,8 +51,7 @@ class Country(object):
5151
5252
Object for the country represented by the users of the IP address
5353
when that country is different than the country in ``country``. For
54-
instance, the country represented by an overseas military base or
55-
embassy.
54+
instance, the country represented by an overseas military base.
5655
5756
:type: :py:class:`geoip2.records.RepresentedCountry`
5857
@@ -92,8 +91,7 @@ def __init__(self, raw_response, locales=None):
9291

9392
class City(Country):
9493

95-
"""Model class for the GeoIP2 Precision City
96-
94+
"""Model for the GeoIP2 Precision: City and the GeoIP2 City database
9795
.. attribute:: city
9896
9997
City object for the requested IP address.
@@ -135,8 +133,7 @@ class City(Country):
135133
136134
Object for the country represented by the users of the IP address
137135
when that country is different than the country in ``country``. For
138-
instance, the country represented by an overseas military base or
139-
embassy.
136+
instance, the country represented by an overseas military base.
140137
141138
:type: :py:class:`geoip2.records.RepresentedCountry`
142139
@@ -153,7 +150,7 @@ class City(Country):
153150
154151
:type: :py:class:`geoip2.records.Traits`
155152
156-
"""
153+
"""
157154

158155
def __init__(self, raw_response, locales=None):
159156
super(City, self).__init__(raw_response, locales)
@@ -168,75 +165,9 @@ def __init__(self, raw_response, locales=None):
168165
*raw_response.get('subdivisions', []))
169166

170167

171-
class CityISPOrg(City):
172-
173-
"""Model class for the GeoIP2 Precision City/ISP/Org
174-
175-
.. attribute:: city
176-
177-
City object for the requested IP address.
178-
179-
:type: :py:class:`geoip2.records.City`
180-
181-
.. attribute:: continent
182-
183-
Continent object for the requested IP address.
184-
185-
:type: :py:class:`geoip2.records.Continent`
186-
187-
.. attribute:: country
188-
189-
Country object for the requested IP address. This record represents the
190-
country where MaxMind believes the IP is located.
191-
192-
:type: :py:class:`geoip2.records.Country`
193-
194-
.. attribute:: location
195-
196-
Location object for the requested IP address.
197-
198-
.. attribute:: maxmind
199-
200-
Information related to your MaxMind account.
201-
202-
:type: :py:class:`geoip2.records.MaxMind`
203-
204-
.. attribute:: registered_country
205-
206-
The registered country object for the requested IP address. This record
207-
represents the country where the ISP has registered a given IP block in
208-
and may differ from the user's country.
209-
210-
:type: :py:class:`geoip2.records.Country`
211-
212-
.. attribute:: represented_country
213-
214-
Object for the country represented by the users of the IP address
215-
when that country is different than the country in ``country``. For
216-
instance, the country represented by an overseas military base or
217-
embassy.
218-
219-
:type: :py:class:`geoip2.records.RepresentedCountry`
220-
221-
.. attribute:: subdivisions
222-
223-
Object (tuple) representing the subdivisions of the country to which
224-
the location of the requested IP address belongs.
225-
226-
:type: :py:class:`geoip2.records.Subdivisions`
227-
228-
.. attribute:: traits
229-
230-
Object with the traits of the requested IP address.
231-
232-
:type: :py:class:`geoip2.records.Traits`
233-
234-
"""
235-
236-
237-
class Omni(CityISPOrg):
168+
class Insights(City):
238169

239-
"""Model class for the GeoIP2 Precision Omni
170+
"""Model for the GeoIP2 Precision: Insights web service endpoint
240171
241172
.. attribute:: city
242173
@@ -279,8 +210,7 @@ class Omni(CityISPOrg):
279210
280211
Object for the country represented by the users of the IP address
281212
when that country is different than the country in ``country``. For
282-
instance, the country represented by an overseas military base or
283-
embassy.
213+
instance, the country represented by an overseas military base.
284214
285215
:type: :py:class:`geoip2.records.RepresentedCountry`
286216

0 commit comments

Comments
 (0)