Class: TicketMaster::Provider::Pivotal::Ticket

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

Overview

Ticket class for ticketmaster-pivotal

  • id

  • status

  • priority

  • title => name

  • resolution

  • created_at

  • updated_at

  • description => text

  • assignee

  • requestor

  • project_id (prefix_options)

Constant Summary collapse

API =
PivotalAPI::Story
@@allowed_states =
['new', 'open', 'resolved', 'hold', 'invalid']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#prefix_optionsObject

Returns the value of attribute prefix_options.



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

def prefix_options
  @prefix_options
end

Class Method Details

.create(options) ⇒ Object



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

def create(options)
  super translate options, {:title => :name, 
                            :requestor => :requested_by,
                            :status => :current_state, 
                            :estimate => :priority,
                            :assignee => :owned_by}
end

.filter(attributes = {}) ⇒ Object



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

def filter(attributes = {})
  filter = ""
  attributes.each_pair do |key, value|
    filter << "#{key}:#{value} "
  end
  filter.strip!
end

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



80
81
82
83
84
85
86
87
88
89
# File 'lib/provider/ticket.rb', line 80

def find_by_attributes(project_id, attributes = {})
  date_to_search = attributes[:updated_at] || attributes[:created_at]
  tickets = []
  unless date_to_search.nil?
    tickets = search_by_datefields(project_id, date_to_search)
  else
    tickets += API.find(:all, :params => {:project_id => project_id, :filter => filter(attributes)}).map { |xticket| self.new xticket }
  end
  tickets.flatten
end

Instance Method Details

#assigneeObject



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

def assignee
  self.owned_by
end

#close(resolution = 'resolved') ⇒ Object

The closer



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

def close(resolution = 'resolved')
  resolution = 'resolved' unless @@allowed_states.include?(resolution)
  ticket = PivotalAPI::Ticket.find(self.id, :params => {:project_id => self.prefix_options[:project_id]})
  ticket.state = resolution
  ticket.save
end

#comment!(*options) ⇒ Object



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

def comment!(*options)
  Comment.create(self.project_id, self.id, options.first)
end

#destroy(*options) ⇒ Object



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

def destroy(*options)
  @system_data[:client].destroy.is_a?(Net::HTTPOK)
end

#priorityObject



55
56
57
# File 'lib/provider/ticket.rb', line 55

def priority
  self.estimate
end

#project_idObject



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

def project_id
  self.prefix_options[:project_id]
end

#requestorObject



39
40
41
# File 'lib/provider/ticket.rb', line 39

def requestor
  self.requested_by
end

#resolutionObject



59
60
61
# File 'lib/provider/ticket.rb', line 59

def resolution
  self.current_state
end

#save(*options) ⇒ Object

The saver



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

def save(*options)
  pt_ticket = @system_data[:client]
  self.keys.each do |key|
    pt_ticket.send(key + '=', self.send(key)) if self.send(key) != pt_ticket.send(key)
  end
  pt_ticket.save
end

#statusObject



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

def status
  self.current_state
end

#titleObject



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

def title
  self.name
end

#title=(title) ⇒ Object



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

def title=(title)
  self.name=title
end