Sha256: c0f3e810445cf8a71a73f727c406968c68f5d1e2e4e6c77b116116ffc273be1d

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Notion
  # The List object is an intermediate object that helps with pagination.
  #
  # https://developers.notion.com/reference/pagination
  class List
    # An array of endpoint-dependent objects
    # @return [Array<Notion::User>]
    # @return [Array<Notion::Database>]
    # @return [Array<Notion::Page>]
    # @return [Array<Notion::Block>]
    attr_reader :data

    # Used to retrieve the next page of results by passing the value as the
    # start_cursor parameter to the same endpoint.
    # @return [nil] if has_more is true.
    # @return [string] if has_more is false.
    attr_reader :next_cursor

    # When the response includes the end of the list, false. Otherwise, true.
    # @return [boolean]
    attr_reader :has_more

    def initialize(response_body)
      @data = response_body["results"].map do |d|
        get_model(d["object"]).new(d)
      end

      @next_cursor = response_body["next_cursor"]
      @has_more = response_body["has_more"]
    end

    private

    def get_model(object_name)
      case object_name
      when "block"
        Block
      when "database"
        Database
      when "page"
        Page
      when "user"
        User
      else
        raise NotionError.new("unimplemented object type")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notion-sdk-ruby-0.6.1 lib/notion-sdk-ruby/models/list.rb
notion-sdk-ruby-0.6.0 lib/notion-sdk-ruby/models/list.rb