Skip to content

Commit ca4da37

Browse files
committed
Added support for random endpoint
1 parent f9a9112 commit ca4da37

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

geouk/resources.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def get(self, name, default=None):
3737
return self.__dict__['_document'].get(name, default)
3838

3939

40-
4140
class Place(_BaseResource):
4241
"""
4342
A place within the UK or Republic of Ireland.
@@ -46,6 +45,29 @@ class Place(_BaseResource):
4645
def __str__(self):
4746
return f'Place: {self.humanized_name}'
4847

48+
@classmethod
49+
def random(cls, client, lat, lon, d):
50+
"""
51+
Fetch a random place within the given distance of the center
52+
(lat, lon).
53+
"""
54+
55+
# Fetch the random place
56+
r = client(
57+
'get',
58+
'places/random',
59+
params={
60+
'lat': lat,
61+
'lon': lon,
62+
'd': d
63+
}
64+
)
65+
66+
if r:
67+
return cls(client, r)
68+
69+
return None
70+
4971
@classmethod
5072
def search(cls, client, q):
5173
"""
@@ -77,6 +99,7 @@ def typeahead(cls, client, q):
7799

78100
return r
79101

102+
80103
class Source(_BaseResource):
81104
"""
82105
A source for the data store against a place which provides attribution for

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Versions should comply with PEP440. For a discussion on single-sourcing
2222
# the version across setup.py and the project code, see
2323
# https://packaging.python.org/en/latest/single_source_version.html
24-
version='0.0.4',
24+
version='0.0.5',
2525
description=(
2626
'The GeoUK Python library provides a pythonic interface to the GeoUK '
2727
'API.',

0 commit comments

Comments
 (0)