Class: Asana::Resources::Section

Inherits:
SectionsBase show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SectionsBase

add_task_for_section, create_section_for_project, delete_section, get_section, get_sections_for_project, inherited, insert_section_for_project, update_section

Methods inherited from Resource

#initialize, #method_missing, #refresh, #respond_to_missing?, #to_h, #to_s

Methods included from ResponseHelper

#parse

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_atObject (readonly)



19
20
21
# File 'lib/asana/resources/section.rb', line 19

def created_at
  @created_at
end

#gidObject (readonly)



11
12
13
# File 'lib/asana/resources/section.rb', line 11

def gid
  @gid
end

#nameObject (readonly)



15
16
17
# File 'lib/asana/resources/section.rb', line 15

def name
  @name
end

#projectObject (readonly)



17
18
19
# File 'lib/asana/resources/section.rb', line 17

def project
  @project
end

#resource_typeObject (readonly)



13
14
15
# File 'lib/asana/resources/section.rb', line 13

def resource_type
  @resource_type
end

Class Method Details

.create_in_project(client, project: required("project"), name: required("name"), options: {}, **data) ⇒ Object

Creates a new section in a project.

Parameters:

  • Returns

    the full record of the newly created section.

  • project (Gid) (defaults to: required("project"))

    The project to create the section in

  • name (String) (defaults to: required("name"))

    The text to be displayed as the section name. This cannot be an empty string.

  • options (Hash) (defaults to: {})

    the request I/O options.

  • data (Hash)

    the attributes to post.



35
36
37
38
# File 'lib/asana/resources/section.rb', line 35

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: options)).first, client: client)
end

.find_by_id(client, id, options: {}) ⇒ Object

Returns the complete record for a single section.

Parameters:

  • id (Gid)

    The section to get.

  • options (Hash) (defaults to: {})

    the request I/O options.



54
55
56
57
# File 'lib/asana/resources/section.rb', line 54

def find_by_id(client, id, options: {})

  self.new(parse(client.get("/sections/#{gid}", options: 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.

Parameters:

  • project (Gid) (defaults to: required("project"))

    The project to get sections from.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

  • options (Hash) (defaults to: {})

    the request I/O options.



45
46
47
48
# File 'lib/asana/resources/section.rb', line 45

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: options)), type: self, client: client)
end

.plural_nameObject

Returns the plural name of the resource.



23
24
25
# File 'lib/asana/resources/section.rb', line 23

def plural_name
  'sections'
end

Instance Method Details

#add_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).

Parameters:

  • insert_before (Gid) (defaults to: nil)

    Insert the given task immediately before the task specified by this parameter. Cannot be provided together with ‘insert_after`.

  • insert_after (Gid) (defaults to: nil)

    Insert the given task immediately after the task specified by this parameter. Cannot be provided together with ‘insert_before`.

  • options (Hash) (defaults to: {})

    the request I/O options.

  • data (Hash)

    the attributes to post.



101
102
103
104
# File 'lib/asana/resources/section.rb', line 101

def add_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/#{gid}/addTask", body: with_params, options: options)).first, client: client)
end

#deleteObject

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.

Returns:

  • an empty data block.



86
87
88
89
# File 'lib/asana/resources/section.rb', line 86

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.

Parameters:

  • Returns

    an empty data block.

  • project (Gid) (defaults to: required("project"))

    The project in which to reorder the given section

  • before_section (Gid) (defaults to: nil)

    Insert the given section immediately before the section specified by this parameter.

  • after_section (Gid) (defaults to: nil)

    Insert the given section immediately after the section specified by this parameter.

  • options (Hash) (defaults to: {})

    the request I/O options.

  • data (Hash)

    the attributes to post.



120
121
122
123
# File 'lib/asana/resources/section.rb', line 120

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: 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.

Parameters:

  • Returns

    the complete updated section record.

  • options (Hash) (defaults to: {})

    the request I/O options.

  • data (Hash)

    the attributes to post.



73
74
75
76
# File 'lib/asana/resources/section.rb', line 73

def update(options: {}, **data)

  refresh_with(parse(client.put("/sections/#{gid}", body: data, options: options)).first)
end