Module: Supercast::Operations::List

Included in:
Creator, DataList, Episode, Invite, Role, Subscriber, UsageAlert
Defined in:
lib/supercast/operations/list.rb

Instance Method Summary collapse

Instance Method Details

#list(filters = {}, opts = {}) ⇒ Object

Lists an API resource

Attributes

  • filters - A hash of filters to pass to the API

  • opts - A Hash of additional options (separate from the params / object values) to be added to the request.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/supercast/operations/list.rb', line 13

def list(filters = {}, opts = {})
  opts = Util.normalize_opts(opts)

  resp, opts = request(:get, resource_url, filters, opts)
  obj = DataList.construct_from({
                                  data: resp.data,
                                  page: resp.http_headers['x-page'].to_i,
                                  per_page: resp.http_headers['x-per-page'].to_i,
                                  total: resp.http_headers['x-total'].to_i
                                }, opts)

  # set filters so that we can fetch the same limit, expansions, and
  # predicates when accessing the next and previous pages
  #
  # just for general cleanliness, remove any paging options
  obj.filters = filters.dup
  obj.filters.delete(:ending_before)
  obj.filters.delete(:starting_after)

  obj
end