Skip to content

Commit

Permalink
feat: add support for sorting reviews in Place Details requests (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnolan authored Jan 24, 2023
1 parent 65d5a26 commit 8afe628
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions googlemaps/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,14 @@ def _places(
return client._request(url, params)


def place(client, place_id, session_token=None, fields=None, language=None):
def place(
client,
place_id,
session_token=None,
fields=None,
language=None,
reviews_sort="most_relevant"
):
"""
Comprehensive details for an individual place.
Expand All @@ -416,6 +423,10 @@ def place(client, place_id, session_token=None, fields=None, language=None):
:param language: The language in which to return results.
:type language: string
:param reviews_sort: The sorting method to use when returning reviews.
Can be set to most_relevant (default) or newest.
:type reviews_sort: string
:rtype: result dict with the following keys:
result: dict containing place details
html_attributions: set of attributions which must be displayed
Expand Down Expand Up @@ -444,6 +455,8 @@ def place(client, place_id, session_token=None, fields=None, language=None):
params["language"] = language
if session_token:
params["sessiontoken"] = session_token
if reviews_sort:
params["reviews_sort"] = reviews_sort

return client._request("/maps/api/place/details/json", params)

Expand Down Expand Up @@ -657,4 +670,3 @@ def _autocomplete(

url = "/maps/api/place/%sautocomplete/json" % url_part
return client._request(url, params).get("predictions", [])

4 changes: 3 additions & 1 deletion tests/test_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def setUp(self):
self.type = "liquor_store"
self.language = "en-AU"
self.region = "AU"
self.reviews_sort="newest"
self.radius = 100

@responses.activate
Expand Down Expand Up @@ -165,11 +166,12 @@ def test_place_detail(self):
"ChIJN1t_tDeuEmsRUsoyG83frY4",
fields=["business_status", "geometry/location", "place_id"],
language=self.language,
reviews_sort=self.reviews_sort,
)

self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?language=en-AU&placeid=ChIJN1t_tDeuEmsRUsoyG83frY4"
"%s?reviews_sort=newest&language=en-AU&placeid=ChIJN1t_tDeuEmsRUsoyG83frY4"
"&key=%s&fields=business_status,geometry/location,place_id"
% (url, self.key),
responses.calls[0].request.url,
Expand Down

0 comments on commit 8afe628

Please sign in to comment.