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

#delete!, get, object_symbol, #object_symbol

Class Method Details

.all(status = nil) ⇒ Array<LimdeskApi::Ticket>

Gets tickets from LimdeskAPI

Returns:



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

def self.all(status = nil)
  LimdeskApi.get_all(object_symbol, status: status).map { |obj| new obj }
end

.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)


91
92
93
94
95
96
97
98
99
100
101
# File 'lib/limdesk_api/ticket.rb', line 91

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)


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/limdesk_api/ticket.rb', line 57

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:



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

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

#reopenBoolean

Reopens a closed ticket

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
# File 'lib/limdesk_api/ticket.rb', line 74

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