Module: ClioClient::Api::Listable

Instance Method Summary collapse

Instance Method Details

#first(params = {}) ⇒ Object



6
7
8
9
# File 'lib/clio_client/api/listable.rb', line 6

def first(params = {})
  params[:limit] = 1
  list(params).first
end

#list(params = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/clio_client/api/listable.rb', line 11

def list(params = {})
  begin
    response = session.get(end_point_url, params)
    @pagination_details = {last_query: params, records: 0, next_offset: response["next_offset"], 
      total_records: response["total_records"]
    }
    @pagination_details[:records] += response["records"] || 0
    response[plural_resource].collect{ |r| data_item(r) }
  rescue ClioClient::UnknownResponse
    []
  end
end

#next_pageObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/clio_client/api/listable.rb', line 24

def next_page
  if more_pages?
    params = @pagination_details[:last_query].merge(:offset => @pagination_details[:next_offset])
    response = session.get(end_point_url, params)
    @pagination_details[:next_offset] = response["next_offset"]
    @pagination_details[:records] += response["records"] || 0
    response[plural_resource].collect{ |r| data_item(r) }
  else
    @pagination_details = nil
    []
  end
end