Class: Kanbantastic::Task
- Inherits:
-
Base
- Object
- Base
- Kanbantastic::Task
show all
- Defined in:
- lib/kanbantastic/task.rb
Constant Summary
Constants inherited
from Base
Base::RECTIFY_TIME_FOR
Instance Attribute Summary collapse
Attributes inherited from Base
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#assign_attributes, find_project_id, #get, invalid_response_error, #post, #project_id, #put, request
Constructor Details
#initialize(config, options = {}) ⇒ Task
Returns a new instance of Task.
7
8
9
10
11
12
|
# File 'lib/kanbantastic/task.rb', line 7
def initialize(config, options = {})
super(config)
assign_attributes(options)
@task_type_id = options[:task_type_id] || find_task_type_id(options[:task_type_name])
valid?
end
|
Instance Attribute Details
#column_id ⇒ Object
Returns the value of attribute column_id.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def column_id
@column_id
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def created_at
@created_at
end
|
#id ⇒ Object
Returns the value of attribute id.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def id
@id
end
|
#moved_at ⇒ Object
Returns the value of attribute moved_at.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def moved_at
@moved_at
end
|
#owner_id ⇒ Object
Returns the value of attribute owner_id.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def owner_id
@owner_id
end
|
#position ⇒ Object
Returns the value of attribute position.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def position
@position
end
|
#task_type_id ⇒ Object
Returns the value of attribute task_type_id.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def task_type_id
@task_type_id
end
|
#title ⇒ Object
Returns the value of attribute title.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def title
@title
end
|
#updated_at ⇒ Object
Returns the value of attribute updated_at.
4
5
6
|
# File 'lib/kanbantastic/task.rb', line 4
def updated_at
@updated_at
end
|
Class Method Details
.all(config) ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'lib/kanbantastic/task.rb', line 120
def self.all(config)
collection = []
response = request(:get, config, "/projects/#{config.project_id}/tasks.json")
response.each do |data|
task = self.new(config, data)
collection << task if task.valid?
end
return collection
end
|
.archived?(config, id) ⇒ Boolean
100
101
102
103
104
|
# File 'lib/kanbantastic/task.rb', line 100
def self.archived?(config, id)
response = request(:get, config, "/projects/#{config.project_id}/archive/tasks.json")
archived_task = response.select{|t| t[:id] == id}[0]
archived_task ? true : false
end
|
.create(config, params = {}) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/kanbantastic/task.rb', line 38
def self.create(config, params={})
unless params[:title] and params[:task_type_name]
raise "Kanbanery task can't be created without title and task_type_name."
end
response = request(:post, config, "/projects/#{config.project_id}/tasks.json", :body => {:task => params})
task = new(config, response)
task.valid? ? task : invalid_response_error("Unable to create task.", response)
end
|
.find(config, id) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/kanbantastic/task.rb', line 106
def self.find(config, id)
begin
response = request(:get, config, "/tasks/#{id}.json")
rescue
return nil
end
task = new(config, response)
if task.valid?
return task
else
return nil
end
end
|
Instance Method Details
#==(task) ⇒ Object
96
97
98
|
# File 'lib/kanbantastic/task.rb', line 96
def ==(task)
id == task.id
end
|
#archive ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/kanbantastic/task.rb', line 76
def archive
if Kanbantastic::Task.archived?(config, id)
return true
else
unless column.last?
raise "Kanbanery tasks can be archived only from the last column."
end
update(:location => "archive")
end
end
|
#column ⇒ Object
48
49
50
51
|
# File 'lib/kanbantastic/task.rb', line 48
def column
@columns ||= {}
@columns[column_id] ||= Kanbantastic::Column.find(config, column_id)
end
|
#find_task_type_id(task_type_name) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/kanbantastic/task.rb', line 14
def find_task_type_id(task_type_name)
@task_type_ids ||= {}
@task_type_ids[task_type_name] ||= if !task_type_name.blank?
response = get("/projects/#{project_id}/task_types.json")
task_type = response.select{|t| t[:name] == task_type_name}.first || Hash.new
task_type[:id]
end
end
|
#move_to_first_column ⇒ Object
61
62
63
64
|
# File 'lib/kanbantastic/task.rb', line 61
def move_to_first_column
column = Kanbantastic::Column.all(config).first
update(:column_id => column.id, :position => nil)
end
|
#move_to_last_column ⇒ Object
71
72
73
74
|
# File 'lib/kanbantastic/task.rb', line 71
def move_to_last_column
column = Kanbantastic::Column.all(config).last
update(:column_id => column.id, :position => nil)
end
|
#move_to_next_column ⇒ Object
53
54
55
|
# File 'lib/kanbantastic/task.rb', line 53
def move_to_next_column
update(:location => 'next_column')
end
|
#move_to_previous_column ⇒ Object
57
58
59
|
# File 'lib/kanbantastic/task.rb', line 57
def move_to_previous_column
update(:location => 'prev_column')
end
|
#move_to_second_column ⇒ Object
66
67
68
69
|
# File 'lib/kanbantastic/task.rb', line 66
def move_to_second_column
column = Kanbantastic::Column.all(config)[1]
update(:column_id => column.id, :position => nil)
end
|
#owner ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/kanbantastic/task.rb', line 88
def owner
@owner ||= if owner_id
response = get("/projects/#{project_id}/users.json")
user = response.select{|r| r[:id] == owner_id}[0]
Kanbantastic::User.new("#{user[:first_name]} #{user[:last_name]}", user[:email], user[:gravatar_url])
end
end
|
#update(params = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/kanbantastic/task.rb', line 23
def update(params={})
params[:owner_id] ||= self.owner_id
begin
response = put("/tasks/#{id}.json", :body => {:task => params})
rescue Exception => e
self.class.invalid_response_error("Unable to update task. #{e.message}", response)
end
if response[:id]
assign_attributes(response)
return valid?
else
self.class.invalid_response_error("Unable to update task.", response)
end
end
|