class Asciidoctor::Confluence::Publisher
Constants
- SUCCESSFUL_CREATE_RESULT
- SUCCESSFUL_UPDATE_RESULT
Public Class Methods
new(options)
click to toggle source
# File lib/asciidoctor/confluence.rb, line 17 def initialize(options) @confluence_options = options[:confluence] @asciidoctor_options = options @asciidoctor_options[:to_file] = false @asciidoctor_options[:header_footer] = false if (options[:input_files].is_a? ::Array) && (options[:input_files].length == 1) @input_file = options[:input_files][0] else @input_file = options[:input_files] end end
Public Instance Methods
get_action_string()
click to toggle source
# File lib/asciidoctor/confluence.rb, line 59 def get_action_string @confluence_options[:update] ? action = 'updated' : action = 'created' action end
publish()
click to toggle source
# File lib/asciidoctor/confluence.rb, line 30 def publish document = Asciidoctor.convert_file @input_file, @asciidoctor_options page = Page.new @confluence_options[:space_key], @confluence_options[:title], document, @confluence_options[:page_id] api = ConfluenceAPI.new @confluence_options, page begin response = api.create_or_update_page @confluence_options[:update], @confluence_options[:page_id] response_body = JSON.parse response.body if response.success? url = response_body['_links']['base']+response_body['_links']['webui'] if @confluence_options[:update] $stdout.puts SUCCESSFUL_UPDATE_RESULT + url else $stdout.puts SUCCESSFUL_CREATE_RESULT + url end return 0 else action = get_action_string show_error action, response_body['message'] return 1 end rescue Exception => e show_error get_action_string, e.message end return 0 end
show_error(action, message)
click to toggle source
# File lib/asciidoctor/confluence.rb, line 64 def show_error(action, message) $stderr.puts "An error occurred, the page has not been #{action} because:\n#{message}" end