Class: Asana::Resources::User

Inherits:
UsersBase show all
Defined in:
lib/asana/resources/user.rb

Overview

A user object represents an account in Asana that can be given access to various workspaces, projects, and tasks.

Like other objects in the system, users are referred to by numerical IDs. However, the special string identifier ‘me` can be used anywhere a user ID is accepted, to refer to the current authenticated user.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UsersBase

get_favorites_for_user, get_user, get_users, get_users_for_team, get_users_for_workspace, inherited

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

#emailObject (readonly)



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

def email
  @email
end

#gidObject (readonly)



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

def gid
  @gid
end

#nameObject (readonly)



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

def name
  @name
end

#photoObject (readonly)



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

def photo
  @photo
end

#resource_typeObject (readonly)



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

def resource_type
  @resource_type
end

#workspacesObject (readonly)



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

def workspaces
  @workspaces
end

Class Method Details

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

Returns the user records for all users in all workspaces and organizations accessible to the authenticated user. Accepts an optional workspace ID parameter.

Parameters:

  • workspace (Id) (defaults to: nil)

    The workspace or organization to filter users on.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



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

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

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

Returns the full user record for the single user with the provided ID.

Parameters:

  • id (String)

    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.



47
48
49
50
# File 'lib/asana/resources/user.rb', line 47

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

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

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

Returns the user records for all users in the specified workspace or organization.

Parameters:

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

    The workspace in which to get users.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.



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

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

.me(client, options: {}) ⇒ Object

Returns the full user record for the currently authenticated user.

Parameters:

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

    the request I/O options.



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

def me(client, options: {})

  Resource.new(parse(client.get("/users/me", options: options)).first, client: client)
end

.plural_nameObject

Returns the plural name of the resource.



28
29
30
# File 'lib/asana/resources/user.rb', line 28

def plural_name
  'users'
end

Instance Method Details

#get_user_favorites(workspace: required("workspace"), resource_type: required("resource_type"), options: {}) ⇒ Object

Returns all of a user’s favorites in the given workspace, of the given type. Results are given in order (The same order as Asana’s sidebar).

Parameters:

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

    The workspace in which to get favorites.

  • resource_type (Enum) (defaults to: required("resource_type"))

    The resource type of favorites to be returned.

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

    the request I/O options.



82
83
84
85
# File 'lib/asana/resources/user.rb', line 82

def get_user_favorites(workspace: required("workspace"), resource_type: required("resource_type"), options: {})
  params = { workspace: workspace, resource_type: resource_type }.reject { |_,v| v.nil? || Array(v).empty? }
  Collection.new(parse(client.get("/users/#{gid}/favorites", params: params, options: options)), type: Resource, client: client)
end