Class: Asana::Resources::Project

Inherits:
Resource
  • Object
show all
Includes:
EventSubscription
Defined in:
lib/asana/resources/project.rb

Overview

A project represents a prioritized list of tasks in Asana. It exists in a single workspace or organization and is accessible to a subset of users in that workspace or organization, depending on its permissions.

Projects in organizations are shared with a single team. You cannot currently change the team of a project via the API. Non-organization workspaces do not have teams and so you should not specify the team of project in a regular workspace.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EventSubscription

#events

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

#idObject (readonly)



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

def id
  @id
end

Class Method Details

.create(client, workspace: required("workspace"), team: nil, options: {}, **data) ⇒ Object

Creates a new project in a workspace or team.

Every project is required to be created in a specific workspace or organization, and this cannot be changed once set. Note that you can use the ‘workspace` parameter regardless of whether or not it is an organization.

If the workspace for your project is an organization, you must also supply a ‘team` to share the project with.

Parameters:

  • Returns

    the full record of the newly created project.

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

    The workspace or organization to create the project in.

  • team (Id) (defaults to: nil)

    If creating in an organization, the specific team to create the

  • project

    in.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



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

def create(client, workspace: required("workspace"), team: nil, options: {}, **data)
  with_params = data.merge(workspace: workspace, team: team).reject { |_,v| v.nil? || Array(v).empty? }
  self.new(parse(client.post("/projects", body: with_params, options: options)).first, client: client)
end

.create_in_team(client, team: required("team"), options: {}, **data) ⇒ Object

Creates a project shared with the given team.

Parameters:

  • Returns

    the full record of the newly created project.

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

    The team to create the project in.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



70
71
72
73
# File 'lib/asana/resources/project.rb', line 70

def create_in_team(client, team: required("team"), options: {}, **data)

  self.new(parse(client.post("/teams/#{team}/projects", body: data, options: options)).first, client: client)
end

.create_in_workspace(client, workspace: required("workspace"), options: {}, **data) ⇒ Object

If the workspace for your project is an organization, you must also supply a ‘team` to share the project with.

Parameters:

  • Returns

    the full record of the newly created project.

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

    The workspace or organization to create the project in.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



58
59
60
61
# File 'lib/asana/resources/project.rb', line 58

def create_in_workspace(client, workspace: required("workspace"), options: {}, **data)

  self.new(parse(client.post("/workspaces/#{workspace}/projects", body: data, options: options)).first, client: client)
end

.find_all(client, workspace: nil, team: nil, archived: nil, per_page: 20, options: {}) ⇒ Object

Returns the compact project records for some filtered set of projects. Use one or more of the parameters provided to filter the projects returned.

Parameters:

  • workspace (Id) (defaults to: nil)

    The workspace or organization to filter projects on.

  • team (Id) (defaults to: nil)

    The team to filter projects on.

  • archived (Boolean) (defaults to: nil)

    Only return projects whose ‘archived` field takes on the value of

  • this

    parameter.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



94
95
96
97
# File 'lib/asana/resources/project.rb', line 94

def find_all(client, workspace: nil, team: nil, archived: nil, per_page: 20, options: {})
  params = { workspace: workspace, team: team, archived: archived, limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/projects", params: params, options: options)), type: self, client: client)
end

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

Returns the complete project record for a single project.

Parameters:

  • id (Id)

    The project to get.

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

    the request I/O options.



79
80
81
82
# File 'lib/asana/resources/project.rb', line 79

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

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

.find_by_team(client, team: required("team"), archived: nil, per_page: 20, options: {}) ⇒ Object

Returns the compact project records for all projects in the team.

Parameters:

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

    The team to find projects in.

  • archived (Boolean) (defaults to: nil)

    Only return projects whose ‘archived` field takes on the value of

  • this

    parameter.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



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

def find_by_team(client, team: required("team"), archived: nil, per_page: 20, options: {})
  params = { archived: archived, limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/teams/#{team}/projects", params: params, options: options)), type: self, client: client)
end

.find_by_workspace(client, workspace: required("workspace"), archived: nil, per_page: 20, options: {}) ⇒ Object

Returns the compact project records for all projects in the workspace.

Parameters:

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

    The workspace or organization to find projects in.

  • archived (Boolean) (defaults to: nil)

    Only return projects whose ‘archived` field takes on the value of

  • this

    parameter.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



107
108
109
110
# File 'lib/asana/resources/project.rb', line 107

def find_by_workspace(client, workspace: required("workspace"), archived: nil, per_page: 20, options: {})
  params = { archived: archived, limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/workspaces/#{workspace}/projects", 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/project.rb', line 23

def plural_name
  'projects'
end

Instance Method Details

#deleteObject

A specific, existing project can be deleted by making a DELETE request on the URL for that project.

Returns:

  • an empty data record.



147
148
149
150
# File 'lib/asana/resources/project.rb', line 147

def delete()

  client.delete("/projects/#{id}") && true
end

#update(options: {}, **data) ⇒ Object

A specific, existing project 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.

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 project record.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



138
139
140
141
# File 'lib/asana/resources/project.rb', line 138

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

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