Class: TicketMaster::Provider::Kanbanpad::Ticket

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

Overview

Ticket class for ticketmaster-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(*object) ⇒ Ticket

Returns a new instance of Ticket.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/provider/ticket.rb', line 10

def initialize(*object)
  if object.first
    object = object.first
    @system_data = {:client => object}
    unless object.is_? Hash
      hash = {:id => object.id,
              :finished => object.finished,
              :title => object.title,
              :backlog => object.backlog,
              :assigned_to => object.assigned_to,
              :wip => object.wip,
              :project_slug => object.project_slug,
              :step_id => object.step_id,
              :urgent => object.urgent}
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.create(*options) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/provider/ticket.rb', line 65

def self.create(*options)
  if options.first.is_a? Hash
    options.first.merge!(:assigned_to => options.first.delete(:assignee),
                         :note => options.first[:description])
    task = API.new(options.first)
    task.save
    ticket = self.new task
  end
end

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



80
81
82
# File 'lib/provider/ticket.rb', line 80

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

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



84
85
86
87
88
# File 'lib/provider/ticket.rb', line 84

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

Instance Method Details

#assigneeObject



45
46
47
# File 'lib/provider/ticket.rb', line 45

def assignee
  self.assigned_to.blank? ? 'Nobody' : self.assigned_to.first
end

#commentObject

TODO?



103
104
105
106
# File 'lib/provider/ticket.rb', line 103

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



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/provider/ticket.rb', line 108

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



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/provider/ticket.rb', line 53

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



41
42
43
# File 'lib/provider/ticket.rb', line 41

def description
  self.note
end

#priorityObject



31
32
33
# File 'lib/provider/ticket.rb', line 31

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

#project_idObject



49
50
51
# File 'lib/provider/ticket.rb', line 49

def project_id
  self.project_slug
end

#saveObject



75
76
77
78
# File 'lib/provider/ticket.rb', line 75

def save
  task = KanbanpadAPI::TaskList.find(:all, :params => {:project_id => self.project_id}).select { |task| task.id == self.id }.first
  task.update_attributes(:title => self.title, :project_id => self.project_id)
end

#statusObject



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

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

#updated_atObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/provider/ticket.rb', line 90

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