class Supportal::Confluence

Public Class Methods

new(user, pass, instance) click to toggle source
# File lib/supportal/confluence.rb, line 5
def initialize(user, pass, instance)
  @logger = Supportal::MicrosLogger.create(STDOUT)
  @logger.level = Logger::INFO
  @host = instance
  @user = user
  @pass = pass
end

Public Instance Methods

content_type_filter(type) click to toggle source
# File lib/supportal/confluence.rb, line 18
def content_type_filter(type)
  type.sub(/com\.atlassian\.confluence\.plugins\.confluence\-questions:.*/, 'question')
end
fetch_latest_blog_posts(limit, space) click to toggle source
# File lib/supportal/confluence.rb, line 26
def fetch_latest_blog_posts(limit, space)
  trim_to = 300 # Trim body of blog post to first X characters.
  path = '/rest/api/content/search?cql='
  cql = 'space=' + space + '+AND+type=blogpost+order+by+created+desc&limit=' + limit.to_i.to_s + '&expand=body.export_view,version'
  posts = Supportal::Request.get_json(@host + path + cql, @user, @pass)
  posts['results'].map do |post|
    {
      heading: highlight_filter(post['title']),
      body: strip_tags(post['body']['export_view']['value'])[0, trim_to] + '...',
      link: @host + post['_links']['webui'],
      date: post['version']['when']
    }
  end
end
highlight_filter(str) click to toggle source
# File lib/supportal/confluence.rb, line 22
def highlight_filter(str)
  strip_tags(str).gsub(/@@@hl@@@/, '<strong>').gsub(/@@@endhl@@@/, '</strong>')
end
strip_tags(str) click to toggle source
# File lib/supportal/confluence.rb, line 13
def strip_tags(str)
  # TODO: Do this properly.
  str.gsub(/<\/?[^>]*>/, ' ')
end