Module: Notion::Api::Endpoints::Pages

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

Instance Method Summary collapse

Instance Method Details

#create_page(options = {}) ⇒ Object

Creates a new page in the specified database. Later iterations of the API will support creating pages outside databases. Note that this iteration of the API will only expose page properties, not page content, as described in the data model.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :parent (Object)

    Parent of the page, which is always going to be a database in this version of the API.

  • :properties (Object)

    Properties of this page. The schema for the page’s keys and values is described by the properties of the database this page belongs to. key string Name of a property as it appears in Notion, or property ID. value object Object containing a value specific to the property type, e.g. true.

  • :children (Object)

    An optional array of Block objects representing the Page’s content



40
41
42
43
# File 'lib/notion/api/endpoints/pages.rb', line 40

def create_page(options = {})
  throw ArgumentError.new('Required argument :parent.database_id missing') if options.dig(:parent, :database_id).nil?
  post("pages", options)
end

#page(options = {}) ⇒ Object

Retrieves a 📄Page object using the ID specified in the request path. Note that this version of the API only exposes page properties, not page content

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :page_id (id)

    Page to get info on.

  • :archived (bool)

    Set to true to retrieve an archived page; must be false or omitted to retrieve a page that has not been archived. Defaults to false.



17
18
19
20
# File 'lib/notion/api/endpoints/pages.rb', line 17

def page(options = {})
  throw ArgumentError.new('Required argument :page_id missing') if options[:page_id].nil?
  get("pages/#{options[:page_id]}")
end

#page_property_item(options = {}) ⇒ Object

Retrieves a ‘property_item` object for a given `page_id` and `property_id`. Depending on the property type, the object returned will either be a value or a paginated list of property item values.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :page_id (id)

    Page to get info on.

  • :property_id (id)

    Property to get info on.



78
79
80
81
82
# File 'lib/notion/api/endpoints/pages.rb', line 78

def page_property_item(options = {})
  throw ArgumentError.new('Required argument :page_id missing') if options[:page_id].nil?
  throw ArgumentError.new('Required argument :property_id missing') if options[:property_id].nil?
  get("pages/#{options[:page_id]}/properties/#{options[:property_id]}")
end

#update_page(options = {}) ⇒ Object

Updates a page by setting the values of any properties specified in the JSON body of the request. Properties that are not set via parameters will remain unchanged.

Note that this iteration of the API will only expose page properties, not page content, as described in the data model.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :page_id (id)

    Page to get info on.

  • :properties (Object)

    Properties of this page. The schema for the page’s keys and values is described by the properties of the database this page belongs to. key string Name of a property as it appears in Notion, or property ID. value object Object containing a value specific to the property type, e.g. true.



62
63
64
65
# File 'lib/notion/api/endpoints/pages.rb', line 62

def update_page(options = {})
  throw ArgumentError.new('Required argument :page_id missing') if options[:page_id].nil?
  patch("pages/#{options[:page_id]}", options.except(:page_id))
end