Class: Asana::Resources::Team

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

#descriptionObject (readonly)



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

def description
  @description
end

#gidObject (readonly)



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

def gid
  @gid
end

#html_descriptionObject (readonly)



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

def html_description
  @html_description
end

#idObject (readonly)



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

def id
  @id
end

#nameObject (readonly)



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

def name
  @name
end

#organizationObject (readonly)



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

def organization
  @organization
end

#resource_typeObject (readonly)



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

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.



36
37
38
39
# File 'lib/asana/resources/team.rb', line 36

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.



48
49
50
51
# File 'lib/asana/resources/team.rb', line 48

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.



62
63
64
65
# File 'lib/asana/resources/team.rb', line 62

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.



27
28
29
# File 'lib/asana/resources/team.rb', line 27

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.



88
89
90
91
# File 'lib/asana/resources/team.rb', line 88

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.



102
103
104
105
# File 'lib/asana/resources/team.rb', line 102

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.



72
73
74
75
# File 'lib/asana/resources/team.rb', line 72

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