Skip to content

Commit 4258a98

Browse files
authored
Merge pull request #88 from osmlab/dev
Dev -> Master
2 parents 800a302 + cc35fab commit 4258a98

File tree

8 files changed

+61
-9
lines changed

8 files changed

+61
-9
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v1.6.0](https://github.com/osmlab/maproulette-python-client/compare/v1.5.0...v1.6.0)
8+
9+
> 26 January 2021
10+
11+
- dev > master (version bump to 1.6.0) [`#76`](https://github.com/osmlab/maproulette-python-client/pull/76)
12+
- Merge dev > master [`#75`](https://github.com/osmlab/maproulette-python-client/pull/75)
13+
- Cooperative Work Model [`#69`](https://github.com/osmlab/maproulette-python-client/pull/69)
14+
- Updated changelog [`#71`](https://github.com/osmlab/maproulette-python-client/pull/71)
15+
- Added new endpoint for fetching tasks by bounding box [`#70`](https://github.com/osmlab/maproulette-python-client/pull/70)
16+
- Refactoring existing endpoint unit tests [`#67`](https://github.com/osmlab/maproulette-python-client/pull/67)
17+
718
#### [v1.5.0](https://github.com/osmlab/maproulette-python-client/compare/v1.4.0...v1.5.0)
819

920
> 3 September 2020

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ that when you create your configuration. For example:
4141
config = maproulette.Configuration(api_key='{YOUR_API_KEY}')
4242
```
4343

44+
Your API key is listed at the bottom of https://maproulette.org/user/profile page.
45+
4446
Once you have your configuration object we can create an API object using one of several modules depending on the
4547
functionality that the user is looking for. For example, creating a Project object allows the user to interact with all
4648
of the project-related functionality in the MapRoulette package.

maproulette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
from .api.task import Task
1818
from .api.user import User
1919

20-
__version__ = '1.6.0'
20+
__version__ = '1.7.0'

maproulette/api/challenge.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_challenge_by_name(self, project_id, challenge_name):
5151
:param challenge_name: the name corresponding to the challenge
5252
:returns: the API response from the GET request
5353
"""
54-
response = self.get(endpoint=f"/project/{project_id}/challenge/{challenge_name}")
54+
response = self.get(endpoint=f"/project/{project_id}/challenge/{challenge_name.replace('/', '%2F')}")
5555
return response
5656

5757
def get_challenges_by_tags(self, challenge_tags, limit=10, page=0):
@@ -325,6 +325,23 @@ def update_challenge(self, challenge_id, data):
325325
body=data)
326326
return response
327327

328+
def rebuild_challenge(self, challenge_id, remove_unmatched=False, skip_snapshot=False):
329+
"""Rebuild the challenge by re-creating the tasks from the task data source
330+
331+
:param challenge_id: the ID corresponding to the challenge
332+
:param remove_unmatched: Used to remove incomplete tasks that have been addressed externally since the last
333+
rebuild, assuming the source data represents all tasks outstanding. If set to true, all existing tasks in
334+
CREATED or SKIPPED status (only) will be removed prior to rebuilding with the assumption that they will be
335+
recreated if they still appear in the updated source data. If set to false, unmatched existing tasks are
336+
simply left as-is. Default: False
337+
:param skip_snapshot: Whether to skip recording a snapshot before proceeding. Default: False
338+
"""
339+
response = self.put(
340+
endpoint=f"/challenge/{challenge_id}/rebuild",
341+
params={'removeUnmatched': str(remove_unmatched).lower(), 'skipSnapshot': str(skip_snapshot).lower()}
342+
)
343+
return response
344+
328345
@staticmethod
329346
def is_challenge_model(input_object):
330347
"""Method to determine whether user input is a valid challenge model

maproulette/api/maproulette_server.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def get(self, endpoint, params=None):
5454
5555
:param endpoint: the server endpoint to use for the GET request
5656
:param params: the parameters that pertain to the request (optional)
57-
:returns: a JSON object containing the API response
57+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
58+
was successful. If not, the response text is returned.
5859
"""
5960
response = self.session.get(
6061
self.url + endpoint,
@@ -85,6 +86,7 @@ def get(self, endpoint, params=None):
8586
}
8687
except ValueError:
8788
return {
89+
"data": response.text,
8890
"status": response.status_code
8991
}
9092

@@ -94,7 +96,8 @@ def post(self, endpoint, body=None, params=None):
9496
:param endpoint: the server endpoint to use for the POST request
9597
:param body: the body of the request (optional)
9698
:param params: the parameters that pertain to the request (optional)
97-
:returns: a JSON object containing the API response
99+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
100+
was successful. If not, the response text is returned.
98101
"""
99102
response = self.session.post(
100103
self.url + endpoint,
@@ -128,6 +131,7 @@ def post(self, endpoint, body=None, params=None):
128131
}
129132
except ValueError:
130133
return {
134+
"data": response.text,
131135
"status": response.status_code
132136
}
133137

@@ -137,7 +141,8 @@ def put(self, endpoint, body=None, params=None):
137141
:param endpoint: the server endpoint to use for the PUT request
138142
:param body: the body of the request (optional)
139143
:param params: the parameters that pertain to the request (optional)
140-
:returns: a JSON object containing the response code and the API response if
144+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
145+
was successful. If not, the response text is returned.
141146
"""
142147
response = self.session.put(
143148
self.url + endpoint,
@@ -171,6 +176,7 @@ def put(self, endpoint, body=None, params=None):
171176
}
172177
except ValueError:
173178
return {
179+
"data": response.text,
174180
"status": response.status_code
175181
}
176182

@@ -179,7 +185,8 @@ def delete(self, endpoint, params=None):
179185
180186
:param endpoint: the server endpoint to use for the DELETE request
181187
:param params: the parameters that pertain to the request (optional)
182-
:returns: a JSON object containing the API response
188+
:returns: a dictionary containing the API response status code as well as the decoded JSON response if decoding
189+
was successful. If not, the response text is returned.
183190
"""
184191
response = self.session.delete(
185192
self.url + endpoint,
@@ -212,6 +219,7 @@ def delete(self, endpoint, params=None):
212219
}
213220
except ValueError:
214221
return {
222+
"data": response.text,
215223
"status": response.status_code
216224
}
217225

maproulette/api/project.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,20 @@ def remove_challenge_from_project(self, project_id, challenge_id):
110110
)
111111
return response
112112

113-
def delete_project(self, project_id):
113+
def delete_project(self, project_id, immediate="false"):
114114
"""
115115
Method to delete a project.
116116
117117
:param project_id: the id of the project being deleted
118+
:param immediate: whether or not the project should be deleted immediately
118119
:returns: the API response form the DELETE request
119120
"""
121+
query_params = {
122+
"immediate": str(immediate)
123+
}
120124
response = self.delete(
121-
endpoint=f"/project/{project_id}"
125+
endpoint=f"/project/{project_id}",
126+
params=query_params
122127
)
123128
return response
124129

tests/test_challenge_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,12 @@ def test_update_challenge(self, mock_request, api_instance=api):
203203
f'{self.url}/challenge/{test_challenge_id}',
204204
json=json.loads(create_challenge_output),
205205
params=None)
206+
207+
@patch('maproulette.api.maproulette_server.requests.Session.put')
208+
def test_rebuild_challenge(self, mock_request, api_instance=api):
209+
test_challenge_id = '12345'
210+
api_instance.rebuild_challenge(test_challenge_id, True, True)
211+
mock_request.assert_called_once_with(
212+
f'{self.url}/challenge/{test_challenge_id}/rebuild',
213+
params={'removeUnmatched': 'true', 'skipSnapshot': 'true'},
214+
json=None)

tests/test_project_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_delete_project(self, mock_request, api_instance=api):
9090
api_instance.delete_project(test_project_id)
9191
mock_request.assert_called_once_with(
9292
f'{self.url}/project/{test_project_id}',
93-
params=None)
93+
params={'immediate': 'false'})
9494

9595
@patch('maproulette.api.maproulette_server.requests.Session.put')
9696
def test_update_project(self, mock_request, api_instance=api):

0 commit comments

Comments
 (0)