class Zaius::ListObject

Constants

OBJECT_NAME

include Zaius::APIOperations::Create

Attributes

filters[RW]

This accessor allows a `ListObject` to inherit various filters that were given to a predecessor. This allows for things like consistent limits, expansions, and predicates as a user pages through resources.

Public Class Methods

empty_list(opts = {}) click to toggle source

An empty list object. This is returned from next when we know that there isn't a next page in order to replicate the behavior of the API when it attempts to return a page beyond the last.

# File lib/zaius/list_object.rb, line 18
def self.empty_list(opts = {})
  ListObject.construct_from({ data: [] }, opts)
end
new(*args) click to toggle source
Calls superclass method
# File lib/zaius/list_object.rb, line 22
def initialize(*args)
  super
  self.filters = {}
end

Public Instance Methods

[](k) click to toggle source
Calls superclass method
# File lib/zaius/list_object.rb, line 27
def [](k)
  case k
  when String, Symbol
    super
  else
    raise ArgumentError, "You tried to access the #{k.inspect} index, but ListObject types only support String keys. (HINT: List calls return an object with a 'data' (which is the data array). You likely want to call #data[#{k.inspect}])"
  end
end
each(&blk) click to toggle source

Iterates through each resource in the page represented by the current `ListObject`.

Note that this method makes no effort to fetch a new page when it gets to the end of the current page's resources. See also auto_paging_each.

# File lib/zaius/list_object.rb, line 41
def each(&blk)
  data.each(&blk)
end
resource_url() click to toggle source
# File lib/zaius/list_object.rb, line 51
def resource_url
  url ||
    raise(ArgumentError, "List object does not contain a 'url' field.")
end
retrieve(id, opts = {}) click to toggle source
# File lib/zaius/list_object.rb, line 45
def retrieve(id, opts = {})
  id, retrieve_params = Util.normalize_id(id)
  resp, opts = request(:get, "#{resource_url}/#{CGI.escape(id)}", retrieve_params, opts)
  Util.convert_to_zaius_object(resp.data, opts)
end