Module: Supportbee::Client::Tickets

Included in:
Supportbee::Client
Defined in:
lib/supportbee/client/tickets.rb

Instance Method Summary collapse

Instance Method Details

#ticket(id) ⇒ Object



29
30
31
32
# File 'lib/supportbee/client/tickets.rb', line 29

def ticket(id)
  response = @conn.get "/tickets/#{id}.json"
  JSON.parse(response.body)
end

#tickets(extra_parameters = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/supportbee/client/tickets.rb', line 5

def tickets(extra_parameters = {})
  # Default parameters according to 
  # https://developers.supportbee.com/api
  if extra_parameters['archived'].nil?
    extra_parameters['archived'] = false
  end
  if extra_parameters['spam'].nil?
    extra_parameters['spam'] = false
  end
  if extra_parameters['trash'].nil?
    extra_parameters['trash'] = false
  end
  tickets = index('tickets', extra_parameters) 
  # Dirty trick to avoid getting wrong tickets in case the API doesn't
  # honor some parameters
  known_filters = ['spam', 'trash', 'archived']
  filters = extra_parameters.select do |p| 
    known_filters.include?(p)
  end
  tickets.select do |t|
    !filters.map {|k,v| t[k].to_s == v.to_s}.include?(false)
  end
end