module ClioClient::Api::Listable

Public Instance Methods

first(params = {}) click to toggle source
# File lib/clio_client/api/listable.rb, line 6
def first(params = {})
  params[:limit] = 1
  list(params).first
end
list(params = {}) click to toggle source
# 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_page() click to toggle source
# 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

Private Instance Methods

more_pages?() click to toggle source
# File lib/clio_client/api/listable.rb, line 38
def more_pages?
  if @pagination_details         
    @pagination_details[:records] < @pagination_details[:total_records]
  end
end