Class: Connectwise::Ticket

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/connectwise/ticket.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#defined_attributes, included, #initialize, #persisted?, #to_h

Instance Attribute Details

#boardObject

Returns the value of attribute board.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def board
  @board
end

#closed_flagObject

Returns the value of attribute closed_flag.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def closed_flag
  @closed_flag
end

#companyObject

Returns the value of attribute company.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def company
  @company
end

#company_idObject

Returns the value of attribute company_id.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def company_id
  @company_id
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def id
  @id
end

#impactObject

Returns the value of attribute impact.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def impact
  @impact
end

#member_idObject

Returns the value of attribute member_id.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def member_id
  @member_id
end

#member_rec_idObject

Returns the value of attribute member_rec_id.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def member_rec_id
  @member_rec_id
end

#notesObject

Returns the value of attribute notes.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def notes
  @notes
end

#priorityObject

Returns the value of attribute priority.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def priority
  @priority
end

#problem_descriptionObject

Returns the value of attribute problem_description.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def problem_description
  @problem_description
end

#remote_internal_company_nameObject

Returns the value of attribute remote_internal_company_name.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def remote_internal_company_name
  @remote_internal_company_name
end

#resolutionObject

Returns the value of attribute resolution.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def resolution
  @resolution
end

#severityObject

Returns the value of attribute severity.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def severity
  @severity
end

#site_nameObject

Returns the value of attribute site_name.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def site_name
  @site_name
end

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def source
  @source
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def status
  @status
end

#status_nameObject

Returns the value of attribute status_name.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def status_name
  @status_name
end

#summaryObject

Returns the value of attribute summary.



7
8
9
# File 'lib/connectwise/ticket.rb', line 7

def summary
  @summary
end

Class Method Details

.find(connection, id) ⇒ Object

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



11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



21
22
23
24
25
# 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

Instance Method Details

#add_note(msg, **options) ⇒ Object



43
44
45
46
# 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

#destroyObject



38
39
40
41
# 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

#saveObject



31
32
33
34
35
36
# 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