class Cubscout::List

the List class is the base class for any collection of objects retrieved from the Helpscout API. it's an Enumerable that can iterate over each of it's items.

Helpscout API V2 is paginated and will return at max 50 items for each collection endpoint. The List class allows to query the page status.

Attributes

collection_name[R]
object_class[R]
raw_payload[R]

Public Class Methods

new(raw_payload, collection_name, object_class) click to toggle source
# File lib/cubscout/list.rb, line 10
def initialize(raw_payload, collection_name, object_class)
  @raw_payload = raw_payload
  @collection_name = collection_name
  @object_class = object_class
end

Public Instance Methods

each(&block) click to toggle source
# File lib/cubscout/list.rb, line 46
def each(&block)
  items.each(&block)
end
items() click to toggle source

array of objects Object retrieved from the API's collection endpoint.

# File lib/cubscout/list.rb, line 37
def items
  Array(raw_payload.dig("_embedded", collection_name)).map { |item| object_class.new(item) }
end
number_of_pages() click to toggle source

total number of pages available

# File lib/cubscout/list.rb, line 27
def number_of_pages
  raw_payload.dig("page", "totalPages")
end
page() click to toggle source

current page number

# File lib/cubscout/list.rb, line 17
def page
  raw_payload.dig("page", "number")
end
page_size() click to toggle source

number of items in the current page. Should be the same as number of items, but sometimes it's not (assumption: it's a bug in helpscout)

# File lib/cubscout/list.rb, line 22
def page_size
  raw_payload.dig("page", "size")
end
size() click to toggle source

number of items

# File lib/cubscout/list.rb, line 42
def size
  items.size
end
total_size() click to toggle source

total number of items available

# File lib/cubscout/list.rb, line 32
def total_size
  raw_payload.dig("page", "totalElements")
end