class ConfluenceHelper::WikiPage

Public Class Methods

new(spacekey, title) click to toggle source
# File lib/confluence_helper.rb, line 168
def initialize(spacekey, title)
  @spacekey, @title = spacekey, title
end

Public Instance Methods

attachment(title) click to toggle source
# File lib/confluence_helper.rb, line 176
def attachment(title)
  page = query_rest_api( url , {expand:"children.attachment"})
  results = page.body["children"]["attachment"]["results"]
  result = results.find{|x| x["title"] == title}
  attachment_url = "#{ENVied.CONSTASH_URL}#{result["_links"]["download"]}"
  query_rest_api(attachment_url, options = {}).body
end
to_nodes(mode=:text) click to toggle source
# File lib/confluence_helper.rb, line 172
def to_nodes(mode=:text)
  parse_wiki_table(doc, mode)
end

Private Instance Methods

doc() click to toggle source
# File lib/confluence_helper.rb, line 190
def doc
  @doc ||= get_page_body()
end
get_page_body() click to toggle source
# File lib/confluence_helper.rb, line 194
def get_page_body()
  page = query_rest_api( url , {expand:"body.export_view"} )
  return Nokogiri::HTML( page.body["body"]["export_view"]["value"] )
end
parse_wiki_table(doc, mode=:text) click to toggle source
# File lib/confluence_helper.rb, line 199
def parse_wiki_table(doc, mode=:text)
  rows = doc.xpath("//table/tbody/tr")
  headers =  rows.xpath("th").map{|n| n.content}
  rows = rows - rows.xpath("th/..")
  documents = rows.map{ | row | row_to_hash(row, headers, mode) }  #convert to hashes
  if headers.include?("ID")
    documents.each_with_object({}){|doc, o| o[doc["ID"].to_i] = doc } # index by id
  else
    documents
  end
end
row_to_hash(row, headers, mode = :text) click to toggle source
# File lib/confluence_helper.rb, line 211
def row_to_hash(row, headers, mode = :text)
  row.xpath( "td" ).
    to_a.
      each.
        with_index.
        with_object( {} ) { | (cell , index) , row_hash | 
          row_hash[ headers[ index ] ] = 
            (mode == :text ? cell.content : cell.inner_html).gsub( /\u00A0/,"" )
        }
end
url() click to toggle source
# File lib/confluence_helper.rb, line 186
def url
  @url ||= get_url(@spacekey, @title)
end