Class: Asana::Resources::Task
- Includes:
- AttachmentUploading, EventSubscription
- Defined in:
- lib/asana/resources/task.rb
Overview
The task is the basic object around which many operations in Asana are centered. In the Asana application, multiple tasks populate the middle pane according to some view parameters, and the set of selected tasks determines the more detailed information presented in the details pane.
Instance Attribute Summary collapse
- #assignee ⇒ Object readonly
- #assignee_status ⇒ Object readonly
- #completed ⇒ Object readonly
- #completed_at ⇒ Object readonly
- #created_at ⇒ Object readonly
- #custom_fields ⇒ Object readonly
-
#dependencies(options: {}) ⇒ Object
readonly
Returns the compact representations of all of the dependencies of a task.
-
#dependents(options: {}) ⇒ Object
readonly
Returns the compact representations of all of the dependents of a task.
- #due_at ⇒ Object readonly
- #due_on ⇒ Object readonly
- #external ⇒ Object readonly
- #followers ⇒ Object readonly
-
#hearted ⇒ Object
readonly
DEPRECATED: prefer “liked”.
-
#hearts ⇒ Object
readonly
DEPRECATED: prefer “likes”.
- #id ⇒ Object readonly
- #liked ⇒ Object readonly
- #likes ⇒ Object readonly
- #memberships ⇒ Object readonly
- #modified_at ⇒ Object readonly
- #name ⇒ Object readonly
- #notes ⇒ Object readonly
-
#num_hearts ⇒ Object
readonly
DEPRECATED: prefer “num_likes”.
- #num_likes ⇒ Object readonly
- #parent ⇒ Object readonly
-
#projects(per_page: 20, options: {}) ⇒ Object
readonly
Returns a compact representation of all of the projects the task is in.
- #start_on ⇒ Object readonly
-
#tags(per_page: 20, options: {}) ⇒ Object
readonly
Returns a compact representation of all of the tags the task has.
- #workspace ⇒ Object readonly
Class Method Summary collapse
-
.create(client, workspace: nil, options: {}, **data) ⇒ Object
Creating a new task is as easy as POSTing to the ‘/tasks` endpoint with a data block containing the fields you’d like to set on the task.
-
.create_in_workspace(client, workspace: required("workspace"), options: {}, **data) ⇒ Object
Creating a new task is as easy as POSTing to the ‘/tasks` endpoint with a data block containing the fields you’d like to set on the task.
-
.find_all(client, assignee: nil, project: nil, section: nil, workspace: nil, completed_since: nil, modified_since: nil, per_page: 20, options: {}) ⇒ Object
Returns the compact task records for some filtered set of tasks.
-
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete task record for a single task.
-
.find_by_project(client, projectId: required("projectId"), per_page: 20, options: {}) ⇒ Object
Returns the compact task records for all tasks within the given project, ordered by their priority within the project.
-
.find_by_section(client, section: required("section"), per_page: 20, options: {}) ⇒ Object
Board view only: Returns the compact section records for all tasks within the given section.
-
.find_by_tag(client, tag: required("tag"), per_page: 20, options: {}) ⇒ Object
Returns the compact task records for all tasks with the given tag.
-
.plural_name ⇒ Object
Returns the plural name of the resource.
-
.search(client, workspace: required("workspace"), per_page: 20, options: {}) ⇒ Object
The search endpoint allows you to build complex queries to find and fetch exactly the data you need from Asana.
Instance Method Summary collapse
-
#add_comment(text: required("text"), options: {}, **data) ⇒ Object
Adds a comment to a task.
-
#add_dependencies(dependencies: required("dependencies"), options: {}, **data) ⇒ Object
Marks a set of tasks as dependencies of this task, if they are not already dependencies.
-
#add_dependents(dependents: required("dependents"), options: {}, **data) ⇒ Object
Marks a set of tasks as dependents of this task, if they are not already dependents.
-
#add_followers(followers: required("followers"), options: {}, **data) ⇒ Object
Adds each of the specified followers to the task, if they are not already following.
-
#add_project(project: required("project"), insert_after: nil, insert_before: nil, section: nil, options: {}, **data) ⇒ Object
Adds the task to the specified project, in the optional location specified.
-
#add_subtask(options: {}, **data) ⇒ Object
Creates a new subtask and adds it to the parent task.
-
#add_tag(tag: required("tag"), options: {}, **data) ⇒ Object
Adds a tag to a task.
-
#delete ⇒ Object
A specific, existing task can be deleted by making a DELETE request on the URL for that task.
-
#remove_dependencies(dependencies: required("dependencies"), options: {}, **data) ⇒ Object
Unlinks a set of dependencies from this task.
-
#remove_dependents(dependents: required("dependents"), options: {}, **data) ⇒ Object
Unlinks a set of dependents from this task.
-
#remove_followers(followers: required("followers"), options: {}, **data) ⇒ Object
Removes each of the specified followers from the task if they are following.
-
#remove_project(project: required("project"), options: {}, **data) ⇒ Object
Removes the task from the specified project.
-
#remove_tag(tag: required("tag"), options: {}, **data) ⇒ Object
Removes a tag from the task.
-
#set_parent(parent: required("parent"), insert_after: nil, insert_before: nil, options: {}, **data) ⇒ Object
Changes the parent of a task.
-
#stories(per_page: 20, options: {}) ⇒ Object
Returns a compact representation of all of the stories on the task.
-
#subtasks(per_page: 20, options: {}) ⇒ Object
Returns a compact representation of all of the subtasks of a task.
-
#update(options: {}, **data) ⇒ Object
A specific, existing task can be updated by making a PUT request on the URL for that task.
Methods included from EventSubscription
Methods included from AttachmentUploading
Methods inherited from Resource
inherited, #initialize, #method_missing, #refresh, #respond_to_missing?, #to_h, #to_s
Methods included from ResponseHelper
Constructor Details
This class inherits a constructor from Asana::Resources::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Asana::Resources::Resource
Instance Attribute Details
#assignee ⇒ Object (readonly)
19 20 21 |
# File 'lib/asana/resources/task.rb', line 19 def assignee @assignee end |
#assignee_status ⇒ Object (readonly)
21 22 23 |
# File 'lib/asana/resources/task.rb', line 21 def assignee_status @assignee_status end |
#completed ⇒ Object (readonly)
25 26 27 |
# File 'lib/asana/resources/task.rb', line 25 def completed @completed end |
#completed_at ⇒ Object (readonly)
27 28 29 |
# File 'lib/asana/resources/task.rb', line 27 def completed_at @completed_at end |
#created_at ⇒ Object (readonly)
23 24 25 |
# File 'lib/asana/resources/task.rb', line 23 def created_at @created_at end |
#custom_fields ⇒ Object (readonly)
29 30 31 |
# File 'lib/asana/resources/task.rb', line 29 def custom_fields @custom_fields end |
#dependencies(options: {}) ⇒ Object (readonly)
Returns the compact representations of all of the dependencies of a task.
233 234 235 |
# File 'lib/asana/resources/task.rb', line 233 def dependencies @dependencies end |
#dependents(options: {}) ⇒ Object (readonly)
Returns the compact representations of all of the dependents of a task.
241 242 243 |
# File 'lib/asana/resources/task.rb', line 241 def dependents @dependents end |
#due_at ⇒ Object (readonly)
37 38 39 |
# File 'lib/asana/resources/task.rb', line 37 def due_at @due_at end |
#due_on ⇒ Object (readonly)
35 36 37 |
# File 'lib/asana/resources/task.rb', line 35 def due_on @due_on end |
#external ⇒ Object (readonly)
39 40 41 |
# File 'lib/asana/resources/task.rb', line 39 def external @external end |
#followers ⇒ Object (readonly)
41 42 43 |
# File 'lib/asana/resources/task.rb', line 41 def followers @followers end |
#hearted ⇒ Object (readonly)
DEPRECATED: prefer “liked”
44 45 46 |
# File 'lib/asana/resources/task.rb', line 44 def hearted @hearted end |
#hearts ⇒ Object (readonly)
DEPRECATED: prefer “likes”
47 48 49 |
# File 'lib/asana/resources/task.rb', line 47 def hearts @hearts end |
#id ⇒ Object (readonly)
17 18 19 |
# File 'lib/asana/resources/task.rb', line 17 def id @id end |
#liked ⇒ Object (readonly)
49 50 51 |
# File 'lib/asana/resources/task.rb', line 49 def liked @liked end |
#likes ⇒ Object (readonly)
51 52 53 |
# File 'lib/asana/resources/task.rb', line 51 def likes @likes end |
#memberships ⇒ Object (readonly)
72 73 74 |
# File 'lib/asana/resources/task.rb', line 72 def memberships @memberships end |
#modified_at ⇒ Object (readonly)
53 54 55 |
# File 'lib/asana/resources/task.rb', line 53 def modified_at @modified_at end |
#name ⇒ Object (readonly)
55 56 57 |
# File 'lib/asana/resources/task.rb', line 55 def name @name end |
#notes ⇒ Object (readonly)
57 58 59 |
# File 'lib/asana/resources/task.rb', line 57 def notes @notes end |
#num_hearts ⇒ Object (readonly)
DEPRECATED: prefer “num_likes”
60 61 62 |
# File 'lib/asana/resources/task.rb', line 60 def num_hearts @num_hearts end |
#num_likes ⇒ Object (readonly)
62 63 64 |
# File 'lib/asana/resources/task.rb', line 62 def num_likes @num_likes end |
#parent ⇒ Object (readonly)
66 67 68 |
# File 'lib/asana/resources/task.rb', line 66 def parent @parent end |
#projects(per_page: 20, options: {}) ⇒ Object (readonly)
Returns a compact representation of all of the projects the task is in.
314 315 316 |
# File 'lib/asana/resources/task.rb', line 314 def projects @projects end |
#start_on ⇒ Object (readonly)
68 69 70 |
# File 'lib/asana/resources/task.rb', line 68 def start_on @start_on end |
#tags(per_page: 20, options: {}) ⇒ Object (readonly)
Returns a compact representation of all of the tags the task has.
368 369 370 |
# File 'lib/asana/resources/task.rb', line 368 def @tags end |
#workspace ⇒ Object (readonly)
70 71 72 |
# File 'lib/asana/resources/task.rb', line 70 def workspace @workspace end |
Class Method Details
.create(client, workspace: nil, options: {}, **data) ⇒ Object
Creating a new task is as easy as POSTing to the ‘/tasks` endpoint with a data block containing the fields you’d like to set on the task. Any unspecified fields will take on default values.
Every task is required to be created in a specific workspace, and this workspace cannot be changed once set. The workspace need not be set explicitly if you specify ‘projects` or a `parent` task instead.
‘projects` can be a comma separated list of projects, or just a single project the task should belong to.
96 97 98 99 |
# File 'lib/asana/resources/task.rb', line 96 def create(client, workspace: nil, options: {}, **data) with_params = data.merge(workspace: workspace).reject { |_,v| v.nil? || Array(v).empty? } self.new(parse(client.post("/tasks", body: with_params, options: )).first, client: client) end |
.create_in_workspace(client, workspace: required("workspace"), options: {}, **data) ⇒ Object
Creating a new task is as easy as POSTing to the ‘/tasks` endpoint with a data block containing the fields you’d like to set on the task. Any unspecified fields will take on default values.
Every task is required to be created in a specific workspace, and this workspace cannot be changed once set. The workspace need not be set explicitly if you specify a ‘project` or a `parent` task instead.
112 113 114 115 |
# File 'lib/asana/resources/task.rb', line 112 def create_in_workspace(client, workspace: required("workspace"), options: {}, **data) self.new(parse(client.post("/workspaces/#{workspace}/tasks", body: data, options: )).first, client: client) end |
.find_all(client, assignee: nil, project: nil, section: nil, workspace: nil, completed_since: nil, modified_since: nil, per_page: 20, options: {}) ⇒ Object
Returns the compact task records for some filtered set of tasks. Use one or more of the parameters provided to filter the tasks returned. You must specify a ‘project` or `tag` if you do not specify `assignee` and `workspace`.
186 187 188 189 |
# File 'lib/asana/resources/task.rb', line 186 def find_all(client, assignee: nil, project: nil, section: nil, workspace: nil, completed_since: nil, modified_since: nil, per_page: 20, options: {}) params = { assignee: assignee, project: project, section: section, workspace: workspace, completed_since: completed_since, modified_since: modified_since, limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/tasks", params: params, options: )), type: self, client: client) end |
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete task record for a single task.
121 122 123 124 |
# File 'lib/asana/resources/task.rb', line 121 def find_by_id(client, id, options: {}) self.new(parse(client.get("/tasks/#{id}", options: )).first, client: client) end |
.find_by_project(client, projectId: required("projectId"), per_page: 20, options: {}) ⇒ Object
Returns the compact task records for all tasks within the given project, ordered by their priority within the project.
132 133 134 135 |
# File 'lib/asana/resources/task.rb', line 132 def find_by_project(client, projectId: required("projectId"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/projects/#{projectId}/tasks", params: params, options: )), type: self, client: client) end |
.find_by_section(client, section: required("section"), per_page: 20, options: {}) ⇒ Object
Board view only: Returns the compact section records for all tasks within the given section.
152 153 154 155 |
# File 'lib/asana/resources/task.rb', line 152 def find_by_section(client, section: required("section"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/sections/#{section}/tasks", params: params, options: )), type: self, client: client) end |
.find_by_tag(client, tag: required("tag"), per_page: 20, options: {}) ⇒ Object
Returns the compact task records for all tasks with the given tag.
142 143 144 145 |
# File 'lib/asana/resources/task.rb', line 142 def find_by_tag(client, tag: required("tag"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/tags/#{tag}/tasks", params: params, options: )), type: self, client: client) end |
.plural_name ⇒ Object
Returns the plural name of the resource.
78 79 80 |
# File 'lib/asana/resources/task.rb', line 78 def plural_name 'tasks' end |
.search(client, workspace: required("workspace"), per_page: 20, options: {}) ⇒ Object
The search endpoint allows you to build complex queries to find and fetch exactly the data you need from Asana. For a more comprehensive description of all the query parameters and limitations of this endpoint, see our [long-form documentation](/developers/documentation/getting-started/search-api) for this feature.
196 197 198 199 |
# File 'lib/asana/resources/task.rb', line 196 def search(client, workspace: required("workspace"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/workspaces/#{workspace}/tasks/search", params: params, options: )), type: Resource, client: client) end |
Instance Method Details
#add_comment(text: required("text"), options: {}, **data) ⇒ Object
Adds a comment to a task. The comment will be authored by the currently authenticated user, and timestamped when the server receives the request.
449 450 451 452 |
# File 'lib/asana/resources/task.rb', line 449 def add_comment(text: required("text"), options: {}, **data) with_params = data.merge(text: text).reject { |_,v| v.nil? || Array(v).empty? } Story.new(parse(client.post("/tasks/#{id}/stories", body: with_params, options: )).first, client: client) end |
#add_dependencies(dependencies: required("dependencies"), options: {}, **data) ⇒ Object
Marks a set of tasks as dependencies of this task, if they are not already dependencies. *A task can have at most 15 dependencies.*
252 253 254 255 |
# File 'lib/asana/resources/task.rb', line 252 def add_dependencies(dependencies: required("dependencies"), options: {}, **data) with_params = data.merge(dependencies: dependencies).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/tasks/#{id}/addDependencies", body: with_params, options: )).first, client: client) end |
#add_dependents(dependents: required("dependents"), options: {}, **data) ⇒ Object
Marks a set of tasks as dependents of this task, if they are not already dependents. *A task can have at most 30 dependents.*
263 264 265 266 |
# File 'lib/asana/resources/task.rb', line 263 def add_dependents(dependents: required("dependents"), options: {}, **data) with_params = data.merge(dependents: dependents).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/tasks/#{id}/addDependents", body: with_params, options: )).first, client: client) end |
#add_followers(followers: required("followers"), options: {}, **data) ⇒ Object
Adds each of the specified followers to the task, if they are not already following. Returns the complete, updated record for the affected task.
294 295 296 297 |
# File 'lib/asana/resources/task.rb', line 294 def add_followers(followers: required("followers"), options: {}, **data) with_params = data.merge(followers: followers).reject { |_,v| v.nil? || Array(v).empty? } refresh_with(parse(client.post("/tasks/#{id}/addFollowers", body: with_params, options: )).first) end |
#add_project(project: required("project"), insert_after: nil, insert_before: nil, section: nil, options: {}, **data) ⇒ Object
Adds the task to the specified project, in the optional location specified. If no location arguments are given, the task will be added to the end of the project.
‘addProject` can also be used to reorder a task within a project or section that already contains it.
At most one of ‘insert_before`, `insert_after`, or `section` should be specified. Inserting into a section in an non-order-dependent way can be done by specifying `section`, otherwise, to insert within a section in a particular place, specify `insert_before` or `insert_after` and a task within the section to anchor the position of this task.
346 347 348 349 |
# File 'lib/asana/resources/task.rb', line 346 def add_project(project: required("project"), insert_after: nil, insert_before: nil, section: nil, options: {}, **data) with_params = data.merge(project: project, insert_after: insert_after, insert_before: insert_before, section: section).reject { |_,v| v.nil? || Array(v).empty? } client.post("/tasks/#{id}/addProject", body: with_params, options: ) && true end |
#add_subtask(options: {}, **data) ⇒ Object
Creates a new subtask and adds it to the parent task. Returns the full record for the newly created subtask.
407 408 409 410 |
# File 'lib/asana/resources/task.rb', line 407 def add_subtask(options: {}, **data) self.class.new(parse(client.post("/tasks/#{id}/subtasks", body: data, options: )).first, client: client) end |
#add_tag(tag: required("tag"), options: {}, **data) ⇒ Object
Adds a tag to a task. Returns an empty data block.
378 379 380 381 |
# File 'lib/asana/resources/task.rb', line 378 def add_tag(tag: required("tag"), options: {}, **data) with_params = data.merge(tag: tag).reject { |_,v| v.nil? || Array(v).empty? } client.post("/tasks/#{id}/addTag", body: with_params, options: ) && true end |
#delete ⇒ Object
A specific, existing task can be deleted by making a DELETE request on the URL for that task. Deleted tasks go into the “trash” of the user making the delete request. Tasks can be recovered from the trash within a period of 30 days; afterward they are completely removed from the system.
225 226 227 228 |
# File 'lib/asana/resources/task.rb', line 225 def delete() client.delete("/tasks/#{id}") && true end |
#remove_dependencies(dependencies: required("dependencies"), options: {}, **data) ⇒ Object
Unlinks a set of dependencies from this task.
273 274 275 276 |
# File 'lib/asana/resources/task.rb', line 273 def remove_dependencies(dependencies: required("dependencies"), options: {}, **data) with_params = data.merge(dependencies: dependencies).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/tasks/#{id}/removeDependencies", body: with_params, options: )).first, client: client) end |
#remove_dependents(dependents: required("dependents"), options: {}, **data) ⇒ Object
Unlinks a set of dependents from this task.
283 284 285 286 |
# File 'lib/asana/resources/task.rb', line 283 def remove_dependents(dependents: required("dependents"), options: {}, **data) with_params = data.merge(dependents: dependents).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/tasks/#{id}/removeDependents", body: with_params, options: )).first, client: client) end |
#remove_followers(followers: required("followers"), options: {}, **data) ⇒ Object
Removes each of the specified followers from the task if they are following. Returns the complete, updated record for the affected task.
305 306 307 308 |
# File 'lib/asana/resources/task.rb', line 305 def remove_followers(followers: required("followers"), options: {}, **data) with_params = data.merge(followers: followers).reject { |_,v| v.nil? || Array(v).empty? } refresh_with(parse(client.post("/tasks/#{id}/removeFollowers", body: with_params, options: )).first) end |
#remove_project(project: required("project"), options: {}, **data) ⇒ Object
Removes the task from the specified project. The task will still exist in the system, but it will not be in the project anymore.
359 360 361 362 |
# File 'lib/asana/resources/task.rb', line 359 def remove_project(project: required("project"), options: {}, **data) with_params = data.merge(project: project).reject { |_,v| v.nil? || Array(v).empty? } client.post("/tasks/#{id}/removeProject", body: with_params, options: ) && true end |
#remove_tag(tag: required("tag"), options: {}, **data) ⇒ Object
Removes a tag from the task. Returns an empty data block.
388 389 390 391 |
# File 'lib/asana/resources/task.rb', line 388 def remove_tag(tag: required("tag"), options: {}, **data) with_params = data.merge(tag: tag).reject { |_,v| v.nil? || Array(v).empty? } client.post("/tasks/#{id}/removeTag", body: with_params, options: ) && true end |
#set_parent(parent: required("parent"), insert_after: nil, insert_before: nil, options: {}, **data) ⇒ Object
Changes the parent of a task. Each task may only be a subtask of a single parent, or no parent task at all. Returns an empty data block. When using ‘insert_before` and `insert_after`, at most one of those two options can be specified, and they must already be subtasks of the parent.
426 427 428 429 |
# File 'lib/asana/resources/task.rb', line 426 def set_parent(parent: required("parent"), insert_after: nil, insert_before: nil, options: {}, **data) with_params = data.merge(parent: parent, insert_after: insert_after, insert_before: insert_before).reject { |_,v| v.nil? || Array(v).empty? } client.post("/tasks/#{id}/setParent", body: with_params, options: ) && true end |
#stories(per_page: 20, options: {}) ⇒ Object
Returns a compact representation of all of the stories on the task.
435 436 437 438 |
# File 'lib/asana/resources/task.rb', line 435 def stories(per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/tasks/#{id}/stories", params: params, options: )), type: Story, client: client) end |
#subtasks(per_page: 20, options: {}) ⇒ Object
Returns a compact representation of all of the subtasks of a task.
397 398 399 400 |
# File 'lib/asana/resources/task.rb', line 397 def subtasks(per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/tasks/#{id}/subtasks", params: params, options: )), type: self.class, client: client) end |
#update(options: {}, **data) ⇒ Object
A specific, existing task can be updated by making a PUT request on the URL for that task. Only the fields provided in the ‘data` block will be updated; any unspecified fields will remain unchanged.
When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the task.
214 215 216 217 |
# File 'lib/asana/resources/task.rb', line 214 def update(options: {}, **data) refresh_with(parse(client.put("/tasks/#{id}", body: data, options: )).first) end |