Class: Asana::Resources::Section
- Defined in:
- lib/asana/resources/section.rb
Overview
A section is a subdivision of a project that groups tasks together. It can either be a header above a list of tasks in a list view or a column in a board view of a project.
Instance Attribute Summary collapse
- #created_at ⇒ Object readonly
- #gid ⇒ Object readonly
- #id ⇒ Object readonly
- #name ⇒ Object readonly
- #project ⇒ Object readonly
- #resource_type ⇒ Object readonly
Class Method Summary collapse
-
.add_task(client, task: required("task"), insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Add a task to a specific, existing section.
-
.create_in_project(client, project: required("project"), name: required("name"), options: {}, **data) ⇒ Object
Creates a new section in a project.
-
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete record for a single section.
-
.find_by_project(client, project: required("project"), per_page: 20, options: {}) ⇒ Object
Returns the compact records for all sections in the specified project.
-
.plural_name ⇒ Object
Returns the plural name of the resource.
Instance Method Summary collapse
-
#delete ⇒ Object
A specific, existing section can be deleted by making a DELETE request on the URL for that section.
-
#insert_in_project(project: required("project"), before_section: nil, after_section: nil, options: {}, **data) ⇒ Object
Move sections relative to each other in a board view.
-
#update(options: {}, **data) ⇒ Object
A specific, existing section can be updated by making a PUT request on the URL for that project.
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
#created_at ⇒ Object (readonly)
22 23 24 |
# File 'lib/asana/resources/section.rb', line 22 def created_at @created_at end |
#gid ⇒ Object (readonly)
14 15 16 |
# File 'lib/asana/resources/section.rb', line 14 def gid @gid end |
#id ⇒ Object (readonly)
12 13 14 |
# File 'lib/asana/resources/section.rb', line 12 def id @id end |
#name ⇒ Object (readonly)
18 19 20 |
# File 'lib/asana/resources/section.rb', line 18 def name @name end |
#project ⇒ Object (readonly)
20 21 22 |
# File 'lib/asana/resources/section.rb', line 20 def project @project end |
#resource_type ⇒ Object (readonly)
16 17 18 |
# File 'lib/asana/resources/section.rb', line 16 def resource_type @resource_type end |
Class Method Details
.add_task(client, task: required("task"), insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Add a task to a specific, existing section. This will remove the task from other sections of the project.
The task will be inserted at the top of a section unless an ‘insert_before` or `insert_after` parameter is declared.
This does not work for separators (tasks with the ‘resource_subtype` of section).
73 74 75 76 |
# File 'lib/asana/resources/section.rb', line 73 def add_task(client, task: required("task"), insert_before: nil, insert_after: nil, options: {}, **data) with_params = data.merge(insert_before: insert_before, insert_after: insert_after).reject { |_,v| v.nil? || Array(v).empty? } Task.new(parse(client.post("/sections/#{task}/addTask", body: with_params, options: )).first, client: client) end |
.create_in_project(client, project: required("project"), name: required("name"), options: {}, **data) ⇒ Object
Creates a new section in a project.
38 39 40 41 |
# File 'lib/asana/resources/section.rb', line 38 def create_in_project(client, project: required("project"), name: required("name"), options: {}, **data) with_params = data.merge(name: name).reject { |_,v| v.nil? || Array(v).empty? } self.new(parse(client.post("/projects/#{project}/sections", body: with_params, options: )).first, client: client) end |
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete record for a single section.
57 58 59 60 |
# File 'lib/asana/resources/section.rb', line 57 def find_by_id(client, id, options: {}) self.new(parse(client.get("/sections/#{id}", options: )).first, client: client) end |
.find_by_project(client, project: required("project"), per_page: 20, options: {}) ⇒ Object
Returns the compact records for all sections in the specified project.
48 49 50 51 |
# File 'lib/asana/resources/section.rb', line 48 def find_by_project(client, project: required("project"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/projects/#{project}/sections", params: params, options: )), type: self, client: client) end |
.plural_name ⇒ Object
Returns the plural name of the resource.
26 27 28 |
# File 'lib/asana/resources/section.rb', line 26 def plural_name 'sections' end |
Instance Method Details
#delete ⇒ Object
A specific, existing section can be deleted by making a DELETE request on the URL for that section.
Note that sections must be empty to be deleted.
The last remaining section in a board view cannot be deleted.
105 106 107 108 |
# File 'lib/asana/resources/section.rb', line 105 def delete() client.delete("/sections/#{gid}") && true end |
#insert_in_project(project: required("project"), before_section: nil, after_section: nil, options: {}, **data) ⇒ Object
Move sections relative to each other in a board view. One of ‘before_section` or `after_section` is required.
Sections cannot be moved between projects.
At this point in time, moving sections is not supported in list views, only board views.
124 125 126 127 |
# File 'lib/asana/resources/section.rb', line 124 def insert_in_project(project: required("project"), before_section: nil, after_section: nil, options: {}, **data) with_params = data.merge(before_section: before_section, after_section: after_section).reject { |_,v| v.nil? || Array(v).empty? } client.post("/projects/#{project}/sections/insert", body: with_params, options: ) && true end |
#update(options: {}, **data) ⇒ Object
A specific, existing section can be updated by making a PUT request on the URL for that project. Only the fields provided in the ‘data` block will be updated; any unspecified fields will remain unchanged. (note that at this time, the only field that can be updated is the `name` field.)
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.
92 93 94 95 |
# File 'lib/asana/resources/section.rb', line 92 def update(options: {}, **data) refresh_with(parse(client.put("/sections/#{gid}", body: data, options: )).first) end |