class Connectwise::Ticket

Attributes

board[RW]
closed_flag[RW]
company[RW]
company_id[RW]
id[RW]
impact[RW]
member_id[RW]
member_rec_id[RW]
notes[RW]
priority[RW]
problem_description[RW]
remote_internal_company_name[RW]
resolution[RW]
severity[RW]
site_name[RW]
source[RW]
status[RW]
status_name[RW]
summary[RW]

Public Class Methods

find(connection, id) click to toggle source

TODO - The use of SrServiceRecid and TicketNumber instead of id - may want to configure these

but this is so inconsistent for tickets that it may not be worth it unless other calls do the same thing
# File lib/connectwise/ticket.rb, line 11
def self.find(connection, id)
  if (attrs = connection.call(cw_api_name, "get_#{cw_api_name}".to_sym, {ticketNumber: id}))
    self.new(connection, find_transform(attrs))
  else
    fail RecordNotFound
  end
rescue ConnectionError
  raise RecordNotFound
end
parse(connection, params) click to toggle source
# File lib/connectwise/ticket.rb, line 21
def self.parse(connection, params)
  resp = JSON.parse(params.keys.first)
  ticket_info = JSON.parse(resp['Entity'])
  self.new(connection, id: params[:id], summary: ticket_info['Summary'], closed_flag: ticket_info['ClosedFlag'], severity: ticket_info['Severity'], company_id: ticket_info['CompanyId'], member_id: ticket_info['memberId'])
end

Private Class Methods

find_transform(attrs) click to toggle source
# File lib/connectwise/ticket.rb, line 49
def self.find_transform(attrs)
  attrs[:id] = attrs.delete(:ticket_number) || attrs.delete(:sr_service_rec_id)
  notes = normalize_find_response(attrs[:detail_notes]) + normalize_find_response(attrs[:internal_notes]) + normalize_find_response(attrs[:resolution_notes])
  attrs[:notes] = notes.compact.map do |note|
    TicketNote.new(@connection, **note)
  end
  attrs
end
save_transform(attrs) click to toggle source
# File lib/connectwise/ticket.rb, line 58
def self.save_transform(attrs)
  attrs[:id] = attrs.delete(:ticket_number)
  attrs[:company] = OpenStruct.new id: attrs.delete(:company_rec_id)
  attrs
end

Public Instance Methods

add_note(msg, **options) click to toggle source
# File lib/connectwise/ticket.rb, line 43
def add_note(msg, **options)
  note = TicketNote.new(connection, {note: msg, ticket: self}.merge(options))
  note.save
end
destroy() click to toggle source
# File lib/connectwise/ticket.rb, line 38
def destroy
  connection.call self.class.cw_api_name, "delete_#{self.class.cw_api_name}".to_sym, {ticketNumber: id}
  self
end
save() click to toggle source
# File lib/connectwise/ticket.rb, line 31
def save
  return false unless @company
  attrs = {companyId: @company.company_id, 'serviceTicket' => to_cw_h}
  attrs = connection.call self.class.cw_api_name, "add_or_update_#{self.class.cw_api_name}_via_company_id".to_sym, attrs
  self.class.new(connection, self.class.save_transform(attrs))
end

Private Instance Methods

to_cw_h() click to toggle source
Calls superclass method Connectwise::Model#to_cw_h
# File lib/connectwise/ticket.rb, line 64
def to_cw_h
  attrs = super
  attrs.delete('Company')
  attrs['TicketNumber'] = attrs[:id] || 0
  attrs
end