Class: Asana::Task

Inherits:
Resource
  • Object
show all
Defined in:
lib/asana/resources/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

check_prefix_options, custom_method_collection_url, #method_not_allowed, parent_resources, prefix, prefix_options, prefix_source, #to_json

Class Method Details

.all_by_project(*args) ⇒ Object



4
5
6
7
# File 'lib/asana/resources/task.rb', line 4

def self.all_by_project(*args)
  parent_resources :project
  all(*args)
end

.all_by_tag(*args) ⇒ Object



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

def self.all_by_tag(*args)
  parent_resources :tag
  all(*args)
end

.all_by_workspace(*args) ⇒ Object



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

def self.all_by_workspace(*args)
  parent_resources :workspace
  all(*args)
end

Instance Method Details

#add_project(project_id) ⇒ Object



33
34
35
36
37
38
# File 'lib/asana/resources/task.rb', line 33

def add_project(project_id)
  path = "#{self.id}/addProject"
  resource = Resource.new({:project => project_id})
  Task.post(path, nil, resource.to_json)
  self
end

#add_tag(tag_id) ⇒ Object



40
41
42
43
44
45
# File 'lib/asana/resources/task.rb', line 40

def add_tag(tag_id)
  path = "#{self.id}/addTag"
  resource = Resource.new({:tag => tag_id})
  Task.post(path, nil, resource.to_json)
  self
end

#create_story(*args) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/asana/resources/task.rb', line 47

def create_story(*args)
  path = "#{self.id}/stories"
  options = { :task => self.id }
  story = Story.new(options.merge(args.first))
  response = Task.post(path, nil, story.to_json)
  Story.new(connection.format.decode(response.body))
end

#create_subtask(*args) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/asana/resources/task.rb', line 59

def create_subtask(*args)
  path = "#{self.id}/subtasks"
  options = { :task => self.id }
  task = Task.new(options.merge(args.first))
  response = Task.post(path, nil, task.to_json)
  Task.new(connection.format.decode(response.body).merge parent: self)
end

#modify(modified_fields) ⇒ Object



19
20
21
22
23
# File 'lib/asana/resources/task.rb', line 19

def modify(modified_fields)
  resource = Resource.new(modified_fields)
  response = Task.put(self.id, nil, resource.to_json)
  Task.new(connection.format.decode(response.body))
end

#projectsObject



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

def projects
  Project.all_by_task(:params => { :task_id => self.id })
end

#storiesObject



55
56
57
# File 'lib/asana/resources/task.rb', line 55

def stories
  Story.all_by_task(:params => { :task_id => self.id })
end

#subtasksObject



67
68
69
70
# File 'lib/asana/resources/task.rb', line 67

def subtasks
  path = "#{self.id}/subtasks"
  Task.get(path, nil).map { |subtask| Task.new(subtask.merge(parent: self)) }
end

#tagsObject



29
30
31
# File 'lib/asana/resources/task.rb', line 29

def tags
  Tag.all_by_task(:params => { :task_id => self.id })
end