Class: TicketMaster::Provider::Trac::Ticket

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

Overview

Ticket class for ticketmaster-yoursystem

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Ticket

declare needed overloaded methods here



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/provider/ticket.rb', line 9

def initialize(*object)
  if object.first
    args = object
    object = args.shift
    project_id = args.shift
    unless object.is_a? Hash
      @system_data = {:client => object}
      hash = {:id => object.id,
        :severity => object.severity,
        :milestone => object.milestone,
        :status => object.status,
        :type => object.type, 
        :priority => object.priority,
        :version => object.version,
        :reporter => object.reporter,
        :owner => object.owner,
        :cc => object.cc,
        :summary => object.summary,
        :assignee => object.owner,
        :requestor => object.reporter,
        :title => object.summary,
        :project_id => project_id,
        :description => object.description,
        :keywords => object.keywords,
        :created_at => object.created_at,
        :updated_at => object.updated_at}
    else
      hash = object
    end
    super(hash)
  end
end

Class Method Details

.create(*options) ⇒ Object



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

def self.create(*options)
  mandatory = options.shift
  attributes = {}
  attributes ||= options.shift
  trac = TicketMaster::Provider::Trac.api
  begin
    self.find_by_id trac[:trac].tickets.create(mandatory[:summary], mandatory[:description], attributes)
  rescue
    self
  end
end

.find(project_id, *options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/provider/ticket.rb', line 57

def self.find(project_id, *options)
  mode = options[0].first
  trac = TicketMaster::Provider::Trac.api
  if options[0].empty?
    self.find_all(project_id, trac[:trac].tickets.list)
  elsif mode.is_a? Array
    self.find_all(project_id, mode)
  elsif mode.is_a? Hash
    self.find_all(project_id, trac[:trac].tickets.query(mode))
  end
end

.find_all(project_id, tickets) ⇒ Object



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

def self.find_all(project_id, tickets)
  tickets.collect do |ticket_id| 
    self.find_by_id(ticket_id, project_id) 
  end
end

.find_by_id(id, project_id) ⇒ Object



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

def self.find_by_id(id, project_id)
  trac = TicketMaster::Provider::Trac.api
  retryable(:tries => 10) do 
    self.new trac[:trac].tickets.get(id), project_id
  end
end

Instance Method Details

#comment(*options) ⇒ Object



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

def comment(*options)
  if options.empty?
    TicketMaster::Provider::Trac::Comment.new
  elsif options.first.is_a? Fixnum
    Comment.find_by_id(self.project_id, self.id, options.first)  
  elsif options.first.is_a? Hash
    Comment.find_by_attributes(self.project_id, self.id, options.first).first
  end
end

#comment!Object



101
102
103
104
# File 'lib/provider/ticket.rb', line 101

def comment!
  warn "Trac doesn't support creation of comments"
  [] 
end

#comments(*options) ⇒ Object



87
88
89
# File 'lib/provider/ticket.rb', line 87

def comments(*options)
  Comment.find(self.project_id, self.id, options)
end

#created_atObject



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

def created_at
  normalize_datetime(self[:created_at]) 
end

#updated_atObject



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

def updated_at
  normalize_datetime(self[:updated_at])
end