Class: LimdeskApi::Ticket

Inherits:
LimdeskObject show all
Defined in:
lib/limdesk_api/ticket.rb

Overview

Client’s ticket

Constant Summary collapse

CLOSE_TYPES =

map close reason symbols to LimdeskAPI’s ids

{
  rejected: 2,
  resolved: 1
}
MEDIA_TYPES =

map media symbols to LimdeskAPI’s ids

{
  mail: 1,
  chat: 2,
  phone: 3,
  other: 4
}
ANSWER_TYPES =

map answer symbols to LimdeskAPI’s ids

{
  pub: 0,
  priv: 1
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LimdeskObject

all, #delete!, get, object_symbol, #object_symbol

Class Method Details

.create(params) ⇒ LimdeskApi::Ticket

Creates a new Ticket

Parameters:

  • params (Hash)

    the options to create a ticket with

Options Hash (params):

  • :reported_by (Symbol)

    media :mail, :chat, :phone, :other

  • :title (String)

    ticket’s title

  • :content (String)

    ticket’s content

  • :client_id (Integer)

    ticket’s client id

Returns:



31
32
33
34
35
# File 'lib/limdesk_api/ticket.rb', line 31

def self.create(params)
  fail 'BadMediaType' unless Ticket::MEDIA_TYPES.keys.include?(params[:reported_by])
  params['reportedBy'] = Ticket::MEDIA_TYPES[params.delete(:reported_by)]
  super
end

Instance Method Details

#answer(params) ⇒ Boolean

Answeres a ticket

Parameters:

  • params (Hash)

    the options to create a answer with

Options Hash (params):

  • :answer_type (Symbol)

    :priv comment or a :pub answer

  • :content (String)

    answer or content body

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/limdesk_api/ticket.rb', line 84

def answer(params)
  fail 'BadAnswerType' unless Ticket::ANSWER_TYPES.keys.include?(params[:answer_type])
  params['type'] = Ticket::ANSWER_TYPES[params.delete(:answer_type)]
  response = LimdeskApi.post_simple(
    id: number,
    object: :ticket,
    action: :answer,
    params: params)
  refresh!
  response
end

#close(params) ⇒ Boolean

Closes a ticket

Parameters:

  • params (Hash)

    the options to colose ticket with

Options Hash (params):

  • :type (Symbol)

    :rejected or :resolved

  • :content (String)

    comment before closing

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/limdesk_api/ticket.rb', line 50

def close(params)
  fail 'BadCloseType' unless Ticket::CLOSE_TYPES.keys.include?(params[:type])
  fail 'NoContentGiven' unless params[:content]
  response = LimdeskApi.put(
    id: self['number'],
    object: :ticket,
    action: :close,
    params: {
      content: params[:content],
      type: Ticket::CLOSE_TYPES[params[:type]] })
  refresh!
  response
end

#refresh!LimdeskApi::Ticket

Refreshes the object from the server

Returns:



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

def refresh!
  marshal_load(Ticket.get(self['number']).marshal_dump)
end

#reopenBoolean

Reopens a closed ticket

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
# File 'lib/limdesk_api/ticket.rb', line 67

def reopen
  response = LimdeskApi.put(
    id: number,
    object: :ticket,
    action: :reopen,
    params: {})
  refresh!
  response
end