Class: Asana::Resources::Section

Inherits:
Resource
  • Object
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 Resource

inherited, #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)



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

def created_at
  @created_at
end

#idObject (readonly)



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

def id
  @id
end

#nameObject (readonly)



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

def name
  @name
end

#projectObject (readonly)



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

def project
  @project
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 (Id) (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.



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

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 (Id)

    The section to get.

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

    the request I/O options.



52
53
54
55
# File 'lib/asana/resources/section.rb', line 52

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

  self.new(parse(client.get("/sections/#{id}", options: options)).first, client: client)
end

.find_by_project(client, project: required("project"), options: {}) ⇒ Object

Returns the compact records for all sections in the specified project.

Parameters:

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

    The project to get sections from.

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

    the request I/O options.



43
44
45
46
# File 'lib/asana/resources/section.rb', line 43

def find_by_project(client, project: required("project"), options: {})

  self.new(parse(client.get("/projects/#{project}/sections", options: options)).first, client: client)
end

.plural_nameObject

Returns the plural name of the resource.



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

def plural_name
  'sections'
end

Instance Method Details

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



84
85
86
87
# File 'lib/asana/resources/section.rb', line 84

def delete()

  client.delete("/sections/#{id}") && 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 (Id) (defaults to: required("project"))

    The project in which to reorder the given section

  • before_section (Id) (defaults to: nil)

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

  • after_section (Id) (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.



103
104
105
106
# File 'lib/asana/resources/section.rb', line 103

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.



71
72
73
74
# File 'lib/asana/resources/section.rb', line 71

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

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