Skip to content

Commit

Permalink
Started adding task endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmanley committed Jun 11, 2020
1 parent c9c6796 commit c3083a2
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
8 changes: 6 additions & 2 deletions maproulette/api/maproulette_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ def put(self, endpoint, body=None, params=None):
"status": response.status_code
}

def delete(self, endpoint):
def delete(self, endpoint, params=None):
"""Method that completes a DELETE request to the MapRoulette API
:param endpoint: the server endpoint to use for the DELETE request
:param params: the parameters that pertain to the request (optional)
:returns: a JSON object containing the API response
"""
response = self.session.delete(self.url + endpoint)
response = self.session.delete(
self.url + endpoint,
params=params
)
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
Expand Down
95 changes: 95 additions & 0 deletions maproulette/api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,101 @@ def get_task_by_id(self, task_id):
endpoint=f"/task/{task_id}")
return response

def get_task_history(self, task_id):
"""Method to retrieve task history using the corresponding task ID
:param task_id: the ID corresponding with the task
:return: the API response from the GET request
"""
response = self.get(
endpoint=f"/task/{task_id}/history")
return response

def create_tasks(self, data):
"""Method to create a batch of tasks
:param data: a JSON input containing task details
:return: the API response from the POST request
"""
response = self.post(
endpoint="/tasks",
body=data)
return response

def update_tasks(self, data):
"""Method to update a batch of tasks
:param data: a JSON input containing task details
:return: the API response from the PUT request
"""
response = self.put(
endpoint="/tasks",
body=data)
return response

def get_task_tags(self, task_id):
"""Method to retrieve the tags for a task using the corresponding task ID
:param task_id: the ID corresponding with the task
:return: the API response from the GET request
"""
response = self.get(
endpoint=f"/task/{task_id}/tags")
return response

def delete_task_tags(self, task_id, tags):
"""Method to delete the supplied tags from a task using the corresponding task ID
:param task_id: the ID corresponding with the task
:param tags: a comma-separated list of tags to be deleted
:return: the API response from the DELETE request
"""
query_params = {
"tags": str(tags)
}
response = self.delete(
endpoint=f"/task/{task_id}/tags",
params=query_params
)
return response

def get_tasks_by_tags(self, tags, limit=10, page=0):
"""Method to retrieve tasks that have the specified tags
:param tags: a comma-separated list of tags to be searched for
:param limit: the limit to the number of results returned in the response. Default is 10
:param page: used in conjunction with the limit parameter to page through X number of responses. Default is 0.
:return: the API response from the GET request
"""
query_params = {
"tags": str(tags),
"limit": str(limit),
"page": str(page)
}
response = self.get(
endpoint="/tasks/tags",
params=query_params
)
return response

def update_task_tags(self, task_id, tags):
"""Method to update a task's tags using the supplied tags and corresponding task ID
:param task_id: the ID corresponding with the task
:param tags: a comma-separated list of tags to be updated. If empty all tags will be removed.
:return: the API response from the GET request
"""
query_params = {
"tags": str(tags)
}
response = self.get(
endpoint=f"/task/{task_id}/tags/update",
params=query_params
)
return response



@staticmethod
def is_task_model(input_object):
"""Method to determine whether user input is a valid task model
Expand Down

0 comments on commit c3083a2

Please sign in to comment.