Class: Forem::Services::PageService

Inherits:
BaseService show all
Defined in:
lib/forem/services/page_service.rb

Overview

Service for interacting with the Forem Pages API.

Pages are static landing pages within a Forem community. Access via Client#pages. All methods inject the client's requestor automatically so no additional configuration is required.

Examples:

client = Forem::Client.new("your-api-key")
pages = client.pages.list
page  = client.pages.retrieve(10)

See Also:

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Forem::Services::BaseService

Instance Method Details

#create(params = {}, opts = {}) ⇒ Page

Create a new static page.

Examples:

client.pages.create(
  title: "About Us",
  slug: "about",
  body_markdown: "## About\nWe are a community of developers."
)

Parameters:

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

    page attributes

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

    per-request options

Options Hash (params):

  • :title (String)

    page title

  • :slug (String)

    URL slug (must be unique)

  • :body_markdown (String)

    page body in Markdown

  • :body_html (String)

    page body in HTML (alternative to Markdown)

  • :is_top_level_path (Boolean)

    whether the page is accessible at the root path

  • :description (String)

    short description / meta tag

  • :template (String)

    page template name

Returns:

  • (Page)

    the newly created page

See Also:



56
57
58
# File 'lib/forem/services/page_service.rb', line 56

def create(params = {}, opts = {})
  Page.create(params, opts_with_requestor(opts))
end

#delete(id, opts = {}) ⇒ nil

Delete a static page.

Examples:

client.pages.delete(10)

Parameters:

  • id (Integer, String)

    the page ID to delete

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

    per-request options

Returns:

  • (nil)

    returns nil on success

See Also:



102
103
104
# File 'lib/forem/services/page_service.rb', line 102

def delete(id, opts = {})
  Page.delete(id, opts_with_requestor(opts))
end

#list(params = {}, opts = {}) ⇒ Array<Page>

List all static pages.

Examples:

client.pages.list

Parameters:

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

    query parameters

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

    per-request options

Options Hash (params):

  • :page (Integer)

    page number (default: 1)

  • :per_page (Integer)

    number of results per page

Returns:

  • (Array<Page>)

    list of static pages

See Also:



29
30
31
# File 'lib/forem/services/page_service.rb', line 29

def list(params = {}, opts = {})
  Page.list(params, opts_with_requestor(opts))
end

#retrieve(id, opts = {}) ⇒ Page

Retrieve a single static page by its numeric ID.

Examples:

client.pages.retrieve(10)

Parameters:

  • id (Integer, String)

    the page ID

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

    per-request options

Returns:

  • (Page)

    the page with the given ID

See Also:



70
71
72
# File 'lib/forem/services/page_service.rb', line 70

def retrieve(id, opts = {})
  Page.retrieve(id, opts_with_requestor(opts))
end

#update(id, params = {}, opts = {}) ⇒ Page

Update an existing static page.

Examples:

client.pages.update(10, title: "About Our Community")

Parameters:

  • id (Integer, String)

    the page ID to update

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

    page attributes to change

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

    per-request options

Options Hash (params):

  • :title (String)

    new page title

  • :body_markdown (String)

    new body in Markdown

  • :description (String)

    new description

Returns:

  • (Page)

    the updated page

See Also:



88
89
90
# File 'lib/forem/services/page_service.rb', line 88

def update(id, params = {}, opts = {})
  Page.update(id, params, opts_with_requestor(opts))
end