-
-
Save k8n/3c9479379a313d5a72b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/asana/asana.py b/asana/asana.py | |
index 0900b9a..66158fa 100755 | |
--- a/asana/asana.py | |
+++ b/asana/asana.py | |
@@ -128,6 +128,27 @@ class AsanaAPI(object): | |
if (self.handle_exception(r) > 0): | |
self._asana_put(api_target, data) | |
+ def _asana_delete(self, api_target, data={}): | |
+ """Peform a PUT request | |
+ | |
+ :param api_target: API URI path for request | |
+ :param data: PUT payload | |
+ """ | |
+ target = "/".join([self.aurl, api_target]) | |
+ if self.debug: | |
+ print "-> DELETing to: %s" % target | |
+ print "-> DELETE payload:" | |
+ pprint(data) | |
+ r = requests.delete(target, auth=(self.apikey, ""), data=data) | |
+ if self._ok_status(r.status_code) and r.status_code is not 404: | |
+ if r.headers['content-type'].split(';')[0] == 'application/json': | |
+ return json.loads(r.text)['data'] | |
+ else: | |
+ raise Exception('Did not receive json from api: %s' % str(r)) | |
+ else: | |
+ if (self.handle_exception(r) > 0): | |
+ self._asana_put(api_target, data) | |
+ | |
@classmethod | |
def _ok_status(cls, status_code): | |
"""Check whether status_code is a ok status i.e. 2xx or 404""" | |
@@ -339,7 +360,7 @@ class AsanaAPI(object): | |
payload['completed'] = 'true' | |
return self._asana_post('tasks/%s/subtasks' % parent_id, payload) | |
- def create_project(self, name, workspace, notes=None, archived=False): | |
+ def create_project(self, name, workspace, notes=None, archived=False, color=None): | |
"""Create a new project | |
:param name: Name of project | |
@@ -352,6 +373,8 @@ class AsanaAPI(object): | |
payload['notes'] = notes | |
if archived: | |
payload['archived'] = 'true' | |
+ if color: | |
+ payload['color'] = color | |
return self._asana_post('projects', payload) | |
def update_project(self, project_id, name=None, notes=None, | |
@@ -399,6 +422,14 @@ class AsanaAPI(object): | |
return self._asana_post('tasks/%d/removeProject' % task_id, | |
{'project': project_id}) | |
+ def rm_project(self, project_id): | |
+ """Remove project | |
+ | |
+ :param project_id: id# of project | |
+ """ | |
+ return self._asana_delete('projects/%d' % project_id) | |
+ | |
+ | |
def add_story(self, task_id, text): | |
"""Add a story to task | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment