class ConfluenceSoap
Constants
- Page
Attributes
client[R]
token[R]
user[R]
Public Class Methods
new(url, user, password, opts = {})
click to toggle source
# File lib/confluence-soap.rb, line 27 def initialize(url, user, password, opts = {}) opts = opts.merge(wsdl: url) @user = user @password = password @client = Savon.client(opts) do convert_request_keys_to :lower_camelcase end @token = login end
Public Instance Methods
add_label_by_name(label, page_id)
click to toggle source
# File lib/confluence-soap.rb, line 116 def add_label_by_name(label, page_id) response = execute do client.call(:add_label_by_name, auth_message({in1: label, in2: page_id})) end parse_response(:add_label_by_name, response) end
convert_wiki_to_storage_format(text)
click to toggle source
# File lib/confluence-soap.rb, line 89 def convert_wiki_to_storage_format(text) response = execute do client.call(:convert_wiki_to_storage_format, auth_message({in1: text})) end parse_response(:convert_wiki_to_storage_format, response) end
get_children(page_id)
click to toggle source
# File lib/confluence-soap.rb, line 63 def get_children(page_id) response = execute do client.call(:get_children, auth_message({in1: page_id})) end pages = parse_array_response(:get_children, response) pages.map { |page| Page.from_hash(page) } end
get_page(page_id)
click to toggle source
# File lib/confluence-soap.rb, line 55 def get_page(page_id) response = execute do client.call(:get_page, auth_message({in1: page_id})) end Page.from_hash(parse_response(:get_page, response)) end
get_pages(space)
click to toggle source
# File lib/confluence-soap.rb, line 46 def get_pages(space) response = execute do client.call(:get_pages, auth_message({in1: space})) end pages = parse_array_response(:get_pages, response) pages.map { |page| Page.from_hash(page) } end
has_user?(user)
click to toggle source
# File lib/confluence-soap.rb, line 133 def has_user?(user) response = execute do client.call(:has_user, auth_message({in1: user})) end parse_response(:has_user, response) end
login()
click to toggle source
# File lib/confluence-soap.rb, line 37 def login response = client.call(:login, message: {in0: @user, in1: @password}) @token = parse_response(:login, response) end
logout()
click to toggle source
# File lib/confluence-soap.rb, line 42 def logout client.call(:logout, message: {in0: @token}) if @token end
remove_label_by_name(label, page_id)
click to toggle source
# File lib/confluence-soap.rb, line 124 def remove_label_by_name(label, page_id) response = execute do client.call(:remove_label_by_name, auth_message({in1: label, in2: page_id})) end parse_response(:remove_label_by_name, response) end
remove_page(page_id)
click to toggle source
# File lib/confluence-soap.rb, line 96 def remove_page(page_id) response = execute do client.call(:remove_page, auth_message({in1: page_id})) end parse_response(:remove_page, response) end
search(term, criteria = {})
click to toggle source
# File lib/confluence-soap.rb, line 104 def search(term, criteria = {}) limit = criteria.delete(:limit) || 20 criteria = criteria.map { |k, v| {key: k, value: v} } response = execute do client.call(:search, auth_message({in1: term, in2: {item: criteria}, in3: limit})) end pages = parse_array_response(:search, response) pages.map { |page| Page.from_hash(page) } end
store_page(page)
click to toggle source
# File lib/confluence-soap.rb, line 72 def store_page(page) response = execute do client.call(:store_page, auth_message({in1: page.to_soap})) end Page.from_hash(parse_response(:store_page, response)) end
update_page(page, options = {minorEdit: true})
click to toggle source
# File lib/confluence-soap.rb, line 80 def update_page(page, options = {minorEdit: true}) response = execute do client.call(:update_page, auth_message({in1: page.to_soap, in2: options })) end Page.from_hash(parse_response(:update_page, response)) end
Private Instance Methods
auth_message(params = {})
click to toggle source
# File lib/confluence-soap.rb, line 186 def auth_message(params = {}) {message: {in0: @token}.merge(params)} end
execute() { || ... }
click to toggle source
# File lib/confluence-soap.rb, line 143 def execute if block_given? yield else tag_errors { raise StandardError.new('requires a block') } end rescue Exception => e if invalid_session?(e) reconnect # @note necessary for catching an invalid session, and then a # Savon::SOAPFault on the same request tag_errors { yield e } else tag_errors { raise e } end end
invalid_session?(exception)
click to toggle source
# File lib/confluence-soap.rb, line 160 def invalid_session?(exception) if exception.respond_to?(:to_hash) fault = exception.to_hash.fetch(:fault) { {} } fault[:faultstring] =~ /InvalidSessionException/ end end
parse_array_response(method, response)
click to toggle source
# File lib/confluence-soap.rb, line 179 def parse_array_response(method, response) parsed_response = parse_response(method, response)["#{method}_return".to_sym] || [] parsed_response.respond_to?(:to_hash) ? [parsed_response] : parsed_response end
parse_response(method, response)
click to toggle source
# File lib/confluence-soap.rb, line 190 def parse_response method, response response.body["#{method}_response".to_sym]["#{method}_return".to_sym] end
reconnect()
click to toggle source
# File lib/confluence-soap.rb, line 175 def reconnect @token = login end
tag_errors() { || ... }
click to toggle source
# File lib/confluence-soap.rb, line 168 def tag_errors yield rescue Exception => e e.extend(ConfluenceSoap::Error) raise end