Class: Asana::Resources::Tag

Inherits:
TagsBase show all
Defined in:
lib/asana/resources/tag.rb

Overview

A tag is a label that can be attached to any task in Asana. It exists in a single workspace or organization.

Tags have some metadata associated with them, but it is possible that we will simplify them in the future so it is not encouraged to rely too heavily on it. Unlike projects, tags do not provide any ordering on the tasks they are associated with.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TagsBase

create_tag, create_tag_for_workspace, delete_tag, get_tag, get_tags, get_tags_for_task, get_tags_for_workspace, inherited, update_tag

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

#colorObject (readonly)


25
26
27
# File 'lib/asana/resources/tag.rb', line 25

def color
  @color
end

#created_atObject (readonly)


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

def created_at
  @created_at
end

#followersObject (readonly)


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

def followers
  @followers
end

#gidObject (readonly)


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

def gid
  @gid
end

#nameObject (readonly)


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

def name
  @name
end

#resource_typeObject (readonly)


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

def resource_type
  @resource_type
end

#workspaceObject (readonly)


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

def workspace
  @workspace
end

Class Method Details

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

Creates a new tag in a workspace or organization.

Every tag 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.

Parameters:

  • Returns

    the full record of the newly created tag.

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

    The workspace or organization to create the tag in.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.


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

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

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

Creates a new tag in a workspace or organization.

Every tag 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.

Parameters:

  • Returns

    the full record of the newly created tag.

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

    The workspace or organization to create the tag in.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.


64
65
66
67
# File 'lib/asana/resources/tag.rb', line 64

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

  self.new(parse(client.post("/workspaces/#{workspace}/tags", 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 tag records for some filtered set of tags. Use one or more of the parameters provided to filter the tags returned.

Parameters:

  • workspace (Gid) (defaults to: nil)

    The workspace or organization to filter tags on.

  • team (Gid) (defaults to: nil)

    The team to filter tags on.

  • archived (Boolean) (defaults to: nil)

    Only return tags 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.


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

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("/tags", params: params, options: options)), type: self, client: client)
end

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

Returns the complete tag record for a single tag.

Parameters:

  • id (Gid)

    The tag to get.

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

    the request I/O options.


73
74
75
76
# File 'lib/asana/resources/tag.rb', line 73

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

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

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

Returns the compact tag records for all tags in the workspace.

Parameters:

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

    The workspace or organization to find tags in.

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.


98
99
100
101
# File 'lib/asana/resources/tag.rb', line 98

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}/tags", params: params, options: options)), type: self, client: client)
end

.plural_nameObject

Returns the plural name of the resource.


31
32
33
# File 'lib/asana/resources/tag.rb', line 31

def plural_name
  'tags'
end

Instance Method Details

#deleteObject

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

Returns:

  • an empty data record.


124
125
126
127
# File 'lib/asana/resources/tag.rb', line 124

def delete()

  client.delete("/tags/#{gid}") && true
end

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

Returns the compact task records for all tasks with the given tag. Tasks can have more than one tag at a time.

Parameters:

  • per_page (Integer) (defaults to: 20)

    the number of records to fetch per page.

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

    the request I/O options.


134
135
136
137
# File 'lib/asana/resources/tag.rb', line 134

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

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

Updates the properties of a tag. 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 tag record.

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

    the request I/O options.

  • data (Hash)

    the attributes to post.


115
116
117
118
# File 'lib/asana/resources/tag.rb', line 115

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

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