Class: TaskMapper::Provider::Kanbanpad::Ticket

Inherits:
Base::Ticket
  • Object
show all
Defined in:
lib/provider/ticket.rb

Overview

Ticket class for taskmapper-kanbanpad

Constant Summary collapse

API =
KanbanpadAPI::TaskList
STEP_API =
KanbanpadAPI::Step
TASK_COMMENT_API =
KanbanpadAPI::TaskCommentCreator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Ticket

Returns a new instance of Ticket.



10
11
12
13
14
15
16
17
# File 'lib/provider/ticket.rb', line 10

def initialize(*args)
  case args.first
  when Hash then super args.first
  when KanbanpadAPI::Task then super args.first.to_ticket_hash
  when KanbanpadAPI::TaskList then super args.first.to_ticket_hash
  else raise ArgumentError.new
  end
end

Class Method Details

.create(attributes) ⇒ Object



61
62
63
64
# File 'lib/provider/ticket.rb', line 61

def self.create(attributes)
  ticket = self.new(attributes)
  ticket if ticket.save
end

.find_by_attributes(project_id, attributes = {}) ⇒ Object



66
67
68
# File 'lib/provider/ticket.rb', line 66

def self.find_by_attributes(project_id, attributes = {})
  search_by_attribute(search(project_id), attributes)
end

.search(project_id, options = {}, limit = 1000) ⇒ Object



70
71
72
73
74
# File 'lib/provider/ticket.rb', line 70

def self.search(project_id, options = {}, limit = 1000)
  API.find(:all, :params => {:project_id => project_id, :backlog => 'yes', :finished => 'yes'}).collect do |task|
    self.new task
  end
end

Instance Method Details

#assigneeObject



33
34
35
# File 'lib/provider/ticket.rb', line 33

def assignee
  self[:assignee].first.blank? ? 'Nobody' : self[:assignee].first
end

#commentObject

TODO?



89
90
91
92
# File 'lib/provider/ticket.rb', line 89

def comment
  warn 'Kanbanpad does not allow find by id of comments. Perhaps you should leave feedback to request it?'
  nil
end

#comment!(*options) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/provider/ticket.rb', line 94

def comment!(*options)
  if options.first.is_a? Hash
    options.first.merge!(:project_id => self.project_id,
                         :task_id => self.id,
                         :step_id => self.step_id)

    task_comment = TASK_COMMENT_API.new(options.first)
    task_comment.save
    comment = Comment.new(task_comment.attributes.merge :ticket_id => id)
  end
end

#created_atObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/provider/ticket.rb', line 41

def created_at
  if self[:created_at].blank?
    Time.parse('2010-03-25 3:06:34') #kanbanpad used to not track the created_at
  else
    begin
      Time.parse(self[:created_at])
    rescue
      self[:created_at]
    end
  end
end

#descriptionObject



29
30
31
# File 'lib/provider/ticket.rb', line 29

def description
  self.note
end

#new?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/provider/ticket.rb', line 57

def new?
  project_id.nil? && step_id.nil?
end

#priorityObject



19
20
21
# File 'lib/provider/ticket.rb', line 19

def priority
  self.urgent ? "Urgent" : "Not Urgent"
end

#project_idObject



37
38
39
# File 'lib/provider/ticket.rb', line 37

def project_id
  self.project_slug
end

#saveObject



53
54
55
# File 'lib/provider/ticket.rb', line 53

def save
  new? ? to_issue.save : update
end

#statusObject



23
24
25
26
27
# File 'lib/provider/ticket.rb', line 23

def status
  return "Finished" if self.finished
  return "Backlog" if self.backlog
  self.wip? ? "#{step_name} - In-Progress" : "#{step_name} - Queue"
end

#updated_atObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/provider/ticket.rb', line 76

def updated_at
  if self[:updated_at].blank?
    Time.parse('2010-03-25 3:06:34') #kanbanpad used to not track the updated_at
  else
    begin
      Time.parse(self[:updated_at])
    rescue
      self[:updated_at]
    end
  end
end