Skip to content

Commit a7c7056

Browse files
authored
Merge pull request #70 from mattmanley/tasks_bounding_box
Added new endpoint for fetching tasks by bounding box
2 parents 3aeb48b + aa8a7f5 commit a7c7056

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

maproulette/api/task.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ def get_tasks_by_tags(self, tags, limit=10, page=0):
102102
)
103103
return response
104104

105+
def get_tasks_by_bounding_box(self, left, bottom, right, top, limit=10000, page=0, exclude_locked="false",
106+
order="ASC", include_total="false", include_geometries="false", include_tags="false"):
107+
"""Method to retrieve tasks by a bounding box defined by left, bottom, right, and top lat/long values
108+
109+
:param left: the minimum latitude of the bounding box
110+
:param bottom: the minimum longitude of the bounding box
111+
:param right: the maximum latitude of the bounding box
112+
:param top: the maximum longitude of the bounding box
113+
:param limit: the limit to the number of results returned in the response. Default is 10,000.
114+
:param page: used in conjunction with the limit parameter to page through X number of responses. Default is 0.
115+
:param exclude_locked: boolean indicating whether to exclude locked tasks. Default is 'false'.
116+
:param order: the order of the results. Default is 'ASC'
117+
:param include_total: whether to include total or not. Default is 'false'
118+
:param include_geometries: whether to include geometries or not. Default is 'false'
119+
:param include_tags: whether to include tags or not. Default is 'false'
120+
:return: the API response from the PUT request
121+
"""
122+
query_params = {
123+
"limit": str(limit),
124+
"page": str(page),
125+
"excludeLocked": str(exclude_locked),
126+
"order": str(order),
127+
"includeTotal": str(include_total),
128+
"includeGeometries": str(include_geometries),
129+
"includeTags": str(include_tags)
130+
}
131+
response = self.put(
132+
endpoint=f'/tasks/box/{left}/{bottom}/{right}/{top}',
133+
params=query_params
134+
)
135+
return response
136+
105137
def update_task_tags(self, task_id, tags):
106138
"""Method to update a task's tags using the supplied tags and corresponding task ID
107139

tests/test_task_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ def test_get_tasks_by_tags(self, mock_request, api_instance=api):
8585
'limit': '10',
8686
'page': '0'})
8787

88+
@patch('maproulette.api.maproulette_server.requests.Session.put')
89+
def test_get_tasks_by_bounding_box(self, mock_request, api_instance=api):
90+
left = -1.22321018
91+
bottom = 47.690315
92+
right = -122.306191
93+
top = 47.706912
94+
api_instance.get_tasks_by_bounding_box(
95+
left=left,
96+
bottom=bottom,
97+
right=right,
98+
top=top
99+
)
100+
mock_request.assert_called_once_with(
101+
f'{self.url}/tasks/box/{left}/{bottom}/{right}/{top}',
102+
json=None,
103+
params={
104+
"limit": '10000',
105+
"page": '0',
106+
"excludeLocked": 'false',
107+
"order": 'ASC',
108+
"includeTotal": 'false',
109+
"includeGeometries": 'false',
110+
"includeTags": 'false'})
111+
88112
@patch('maproulette.api.maproulette_server.requests.Session.get')
89113
def test_update_task_tags(self, mock_request, api_instance=api):
90114
task_id = '42914448'

0 commit comments

Comments
 (0)