Class: TicketMaster::Provider::Lighthouse::Ticket

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

Overview

Ticket class for ticketmaster-lighthouse

Due to the way Lighthouse stores tickets, we actually end up creating a new ticket version every time we edit tickets. Their api FAQ states these attributes as the only editable ones(?):

  • title

  • body - follows the same formatting rules.

  • state - Can be any one of these: new, open, resolved, hold, invalid. Optional, set to open by default for new tickets.

  • assigned-user-id - optional

  • milestone-id - optional

  • tag - space or comma delimited list of tags

We had to remap things a bit since lighthouse doesn’t name things as ticketmaster specifies.

  • id => number (read-only)

  • status => state

  • resolution => ticket.latest_body

  • description => ticket.original_body (setting a new description creates a new body)

  • assignee => assigned_user_name (read-only)

  • requestor => creator_name (read-only)

  • project_id => prefix_options

  • priority

  • title

  • created_at

  • updated_at

Constant Summary collapse

API =
::Lighthouse::Ticket
@@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.



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

def prefix_options
  @prefix_options
end

Class Method Details

.create(options) ⇒ Object



125
126
127
128
129
130
# File 'lib/provider/ticket.rb', line 125

def create(options)
  super translate options,
    :description => :body,
    :status => :state,
    :assignee => :assigned_user_id
end

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

Lighthouse limits us to a 100 ticket limit per page… Since the paging sucks…we probably want to store this rather than do a call each time



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/provider/ticket.rb', line 134

def search(project_id, options = {}, limit = 1000)
  page = 1
  tickets = ::Lighthouse::Ticket.find(:all, :params => {:project_id => project_id, :limit => 100, :page => page})
  result = []
  while tickets.length > 0 and page <= 3 #limit to page 3 since lighthouse is so slow...
    result += tickets.collect { |ticket| self.new ticket }
    page += 1
    tickets = ::Lighthouse::Ticket.find(:all, :params => {:project_id => project_id, :limit => 100, :page => page})
  end
  search_by_attribute(result, options, limit)
end

Instance Method Details

#assigneeObject

Get the assigned person’s name



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

def assignee
  self.assigned_user_name
end

#body=(bod) ⇒ Object

Set the body



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

def body=(bod)
  @system_data[:client].body = nil
  super(bod)
end

#close(resolution = 'resolved') ⇒ Object

The closer



116
117
118
119
120
121
# File 'lib/provider/ticket.rb', line 116

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

#descriptionObject

Get the description, mapped to original_body



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

def description
  self.original_body
end

#description=(desc) ⇒ Object

Set the description, mapped to body, which actually does a comment



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

def description=(desc)
  self.body = desc
end

#idObject

This is to get the ticket id We can’t set ids, so there’s no ‘id=’ method.



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

def id
  @system_data[:client].number
end

#project_idObject

Get the project id



83
84
85
# File 'lib/provider/ticket.rb', line 83

def project_id
  prefix_options[:project_id]
end

#requestorObject

Get the requestor’s name



78
79
80
# File 'lib/provider/ticket.rb', line 78

def requestor
  self.creator_name
end

#resolutionObject

Get the resolution, mapped to latest_body



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

def resolution
  self.latest_body
end

#resolution=(res) ⇒ Object

Set the resolution…also sets state to resolved



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

def resolution=(res)
  state = 'resolved'
  self.body = res
end

#saveObject

Gotta unset the body attribute…otherwise every save ends up using that body



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/provider/ticket.rb', line 103

def save
#        self.tag = @tags.reduce([]) do |mem, t|
#          t = "\"#{t}\"" if t.include?(' ')
#          mem << t
#        end.join(' ') if @tags
  @system_data[:client].attributes.delete('versions')
  result = super
  body = nil
  @system_data[:client].body = nil
  result
end

#statusObject

This is to get the status, mapped to state



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

def status
  state
end

#status=(stat) ⇒ Object

This is to set the status, mapped to state



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

def status=(stat)
  stat = state unless @@allowed_states.include?(stat)
  self.state = stat
end

#tagsObject

Tags, a little helper for the ticket tagging



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

def tags
  return @tags if @tags
  tagz = self.tag.split(/([\w\d]+)|"([\w \d]+)"/)
  tagz.delete(' ')
  tagz.delete('')
  @tags = tagz
end