Method: Frontapp::Client#list

Defined in:
lib/frontapp/client.rb

#list(path, params = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/frontapp/client.rb', line 39

def list(path, params = {})
  items = []
  last_page = false
  query = format_query(params)
  url = "#{base_url}#{path}?#{query}"
  until last_page
    res = @headers.get(url)
    response = JSON.parse(res.to_s)
    items.concat(response["_results"]) if response["_results"]
    pagination = response["_pagination"]
    if pagination.nil? || pagination["next"].nil?
      last_page = true
    else
      url = pagination["next"]
    end
  end
  items
end