Class: Wikidotrb::Module::SitePageMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/wikidotrb/module/site.rb

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ SitePageMethods

Returns a new instance of SitePageMethods.



27
28
29
# File 'lib/wikidotrb/module/site.rb', line 27

def initialize(site)
  @site = site
end

Instance Method Details

#create(fullname:, title: "", source: "", comment: "", force_edit: false) ⇒ Page

Create a page

Parameters:

  • fullname (String)

    Page fullname

  • title (String) (defaults to: "")

    Page title

  • source (String) (defaults to: "")

    Page source

  • comment (String) (defaults to: "")

    Comment

  • force_edit (Boolean) (defaults to: false)

    Whether to overwrite the page if it already exists

Returns:

  • (Page)

    Created page object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wikidotrb/module/site.rb', line 54

def create(fullname:, title: "", source: "", comment: "", force_edit: false)
  Page.create_or_edit(
    site: @site,
    fullname: fullname,
    title: title,
    source: source,
    comment: comment,
    force_edit: force_edit,
    raise_on_exists: true
  )
end

#get(fullname, raise_when_not_found: true) ⇒ Page?

Get a page by its fullname

Parameters:

  • fullname (String)

    Page fullname

  • raise_when_not_found (Boolean) (defaults to: true)

    Whether to raise an exception when the page is not found

Returns:

  • (Page, nil)

    Page object or nil



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wikidotrb/module/site.rb', line 35

def get(fullname, raise_when_not_found: true)
  res = PageCollection.search_pages(@site, Wikidotrb::Module::SearchPagesQuery.new(fullname: fullname))

  if res.empty?
    raise Wikidotrb::Common::Exceptions::NotFoundException, "Page is not found: #{fullname}" if raise_when_not_found

    return nil
  end

  res.first
end