Method: RT_Client#list

Defined in:
rt_client.rb

#list(*params) ⇒ Object

Get a list of tickets matching some criteria. Takes a string Ticket-SQL query and an optional “order by” parameter. The order by is an RT field, prefix it with + for ascending or - for descending. Returns a nested array of arrays containing [ticket number, subject] The outer array is in the order requested.

hash = rt.list(:query => "Queue = 'Sales'")
hash = rt.list("Queue='Sales'")
hash = rt.list(:query => "Queue = 'Sales'", :order => "-Id")
hash = rt.list("Queue='Sales'","-Id")


373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'rt_client.rb', line 373

def list(*params)
  query = params[0]
  order = ""
  if params.size > 1
    order = params[1]
  end
  if params[0].class == Hash
    params = params[0]
    query = params[:query] if params.has_key? :query
    order = params[:order] if params.has_key? :order
  end
  reply = []
  resp = @site["search/ticket/?query=#{URI.escape(query)}&orderby=#{order}&format=s"].get
  raise "Invalid query (#{query})" if resp =~ /Invalid query/
  resp = resp.split("\n") # convert to array of lines
  resp.each do |line|
    f = line.match(/^(\d+):\s*(.*)/)
    reply.push [f[1],f[2]] if f.class == MatchData
  end
  reply
end