Class: Asana::Resources::Team

Inherits:
TeamsBase show all
Defined in:
lib/asana/resources/team.rb

Overview

A team is used to group related projects and people together within an organization. Each project in an organization is associated with a team.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TeamsBase

add_user_for_team, create_team, get_team, get_teams_for_user, get_teams_for_workspace, inherited, remove_user_for_team, update_team

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

#descriptionObject (readonly)



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

def description
  @description
end

#gidObject (readonly)



10
11
12
# File 'lib/asana/resources/team.rb', line 10

def gid
  @gid
end

#html_descriptionObject (readonly)



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

def html_description
  @html_description
end

#nameObject (readonly)



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

def name
  @name
end

#organizationObject (readonly)



20
21
22
# File 'lib/asana/resources/team.rb', line 20

def organization
  @organization
end

#resource_typeObject (readonly)



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

def resource_type
  @resource_type
end

Class Method Details

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

Returns the full record for a single team.

Parameters:

  • id (Id)

    Globally unique identifier for the team.

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

    the request I/O options.



33
34
35
36
# File 'lib/asana/resources/team.rb', line 33

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

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

.find_by_organization(client, organization: required("organization"), per_page: 20, options: {}) ⇒ Object

Returns the compact records for all teams in the organization visible to the authorized user.

Parameters:

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

    Globally unique identifier for the workspace or organization.

  • 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/team.rb', line 45

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

.find_by_user(client, user: required("user"), organization: nil, per_page: 20, options: {}) ⇒ Object

Returns the compact records for all teams to which user is assigned.

Parameters:

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

    An identifier for the user. Can be one of an email address,

  • the

    globally unique identifier for the user, or the keyword ‘me`

  • to

    indicate the current user making the request.

  • organization (Id) (defaults to: nil)

    The workspace or organization to filter teams on.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



59
60
61
62
# File 'lib/asana/resources/team.rb', line 59

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

.plural_nameObject

Returns the plural name of the resource.



24
25
26
# File 'lib/asana/resources/team.rb', line 24

def plural_name
  'teams'
end

Instance Method Details

#add_user(user: required("user"), options: {}, **data) ⇒ Object

The user making this call must be a member of the team in order to add others. The user to add must exist in the same organization as the team in order to be added. The user to add can be referenced by their globally unique user ID or their email address.

Parameters:

  • Returns

    the full user record for the added user.

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

    An identifier for the user. Can be one of an email address,

  • the

    globally unique identifier for the user, or the keyword ‘me`

  • to

    indicate the current user making the request.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



85
86
87
88
# File 'lib/asana/resources/team.rb', line 85

def add_user(user: required("user"), options: {}, **data)
  with_params = data.merge(user: user).reject { |_,v| v.nil? || Array(v).empty? }
  User.new(parse(client.post("/teams/#{gid}/addUser", body: with_params, options: options)).first, client: client)
end

#remove_user(user: required("user"), options: {}, **data) ⇒ Object

The user to remove can be referenced by their globally unique user ID or their email address. Removes the user from the specified team. Returns an empty data record.

Parameters:

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

    An identifier for the user. Can be one of an email address,

  • the

    globally unique identifier for the user, or the keyword ‘me`

  • to

    indicate the current user making the request.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.



99
100
101
102
# File 'lib/asana/resources/team.rb', line 99

def remove_user(user: required("user"), options: {}, **data)
  with_params = data.merge(user: user).reject { |_,v| v.nil? || Array(v).empty? }
  client.post("/teams/#{gid}/removeUser", body: with_params, options: options) && true
end

#users(per_page: 20, options: {}) ⇒ Object

Returns the compact records for all users that are members of the team.

Parameters:

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



69
70
71
72
# File 'lib/asana/resources/team.rb', line 69

def users(per_page: 20, options: {})
  params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/teams/#{gid}/users", params: params, options: options)), type: User, client: client)
end