Class: Supportal::Confluence
- Inherits:
-
Object
- Object
- Supportal::Confluence
- Defined in:
- lib/supportal/confluence.rb
Instance Method Summary collapse
- #content_type_filter(type) ⇒ Object
- #fetch_latest_blog_posts(limit, space) ⇒ Object
- #highlight_filter(str) ⇒ Object
-
#initialize(user, pass, instance) ⇒ Confluence
constructor
A new instance of Confluence.
- #search(str, root_doc_page_ids, space, label) ⇒ Object
- #strip_tags(str) ⇒ Object
Constructor Details
#initialize(user, pass, instance) ⇒ Confluence
Returns a new instance of Confluence.
5 6 7 8 9 10 11 |
# 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 |
Instance Method Details
#content_type_filter(type) ⇒ Object
18 19 20 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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: (post['body']['export_view']['value'])[0, trim_to] + '...', link: @host + post['_links']['webui'], date: post['version']['when'] } end end |
#highlight_filter(str) ⇒ Object
22 23 24 |
# File 'lib/supportal/confluence.rb', line 22 def highlight_filter(str) (str).gsub(/@@@hl@@@/, '<strong>').gsub(/@@@endhl@@@/, '</strong>') end |
#search(str, root_doc_page_ids, space, label) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
#strip_tags(str) ⇒ Object
13 14 15 16 |
# File 'lib/supportal/confluence.rb', line 13 def (str) # TODO: Do this properly. str.gsub(/<\/?[^>]*>/, ' ') end |