Module: Notion::Api::Endpoints::Comments

Included in:
Notion::Api::Endpoints
Defined in:
lib/notion/api/endpoints/comments.rb

Instance Method Summary collapse

Instance Method Details

#create_comment(options = {}) ⇒ Object

Creates a comment in a page or existing discussion thread.

There are two locations you can add a new comment to:
  - A page
  - An existing discussion thread
If the intention is to add a new comment to a page, a parent object
must be provided in the body params. Alternatively, if a new comment
is being added to an existing discussion thread, the discussion_id string
must be provided in the body params. Exactly one of these parameters must be provided.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :parent (Object)

    A page parent. Either this or a discussion_id is required (not both).

  • :discussion_id (UUID)

    A UUID identifier for a discussion thread. Either this or a parent object is required (not both).

  • :rich_text (Object)

    A rich text object.



51
52
53
54
55
56
57
# File 'lib/notion/api/endpoints/comments.rb', line 51

def create_comment(options = {})
  if options.dig(:parent, :page_id).nil? && options[:discussion_id].nil?
    throw ArgumentError.new('Required argument :page_id or :discussion_id missing')
  end
  throw ArgumentError.new('Required argument :rich_text missing') if options[:rich_text].nil?
  post('comments', options)
end

#retrieve_comments(options = {}) ⇒ Object

Retrieves a list of un-resolved Comment objects from a page or block.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :block_id (id)

    Block or page id to fetch comments for.

  • :start_cursor (start_cursor)

    If supplied, this endpoint will return a page of results starting after the cursor provided. If not supplied, this endpoint will return the first page of results.

  • :page_size (page_size)

    The number of items from the full list desired in the response. Maximum: 100



22
23
24
25
26
27
28
29
30
31
# File 'lib/notion/api/endpoints/comments.rb', line 22

def retrieve_comments(options = {})
  throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
  if block_given?
    Pagination::Cursor.new(self, :retrieve_comments, options).each do |page|
      yield page
    end
  else
    get('comments', options)
  end
end