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
search(str, root_doc_page_ids, space, label)
click to toggle source
# File lib/supportal/confluence.rb, line 41 def search(str, root_doc_page_ids, space, label) root_page_cql = root_doc_page_ids.map { |root_page| "(container=#{root_page} OR ancestor=#{root_page})" }.join(" OR ") path = '/rest/api/search?limit=10&expand=version&cql=' cql = CGI.escape("text~\"#{str}\" AND (space=#{space} OR label=\"#{label}\") AND (((#{root_page_cql}) AND (type=blogpost OR type=page OR type=comment)) OR (type=\"ac:com.atlassian.confluence.plugins.confluence-questions:question\" OR type=\"ac:com.atlassian.confluence.plugins.confluence-questions:answer\"))") body = Supportal::Request.get_json(@host + path + cql, @user, @pass) if body.dig('results') return body['results'].map do |result| { title: highlight_filter(result['title']), link: @host + result['url'], date: result['lastModified'], type: content_type_filter(result['content']['type']) } end end @logger.error body.inspect return false end