Class: ConfluenceSoap

Inherits:
Object
  • Object
show all
Defined in:
lib/confluence-soap.rb

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, user, password) ⇒ ConfluenceSoap

Returns a new instance of ConfluenceSoap.



19
20
21
22
23
24
25
26
# File 'lib/confluence-soap.rb', line 19

def initialize url, user, password
  @user = user
  @password = password
  @client = Savon.client(wsdl: url) do
    convert_request_keys_to :lower_camelcase
  end
  @token = (user, password)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/confluence-soap.rb', line 4

def client
  @client
end

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/confluence-soap.rb', line 4

def token
  @token
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/confluence-soap.rb', line 4

def user
  @user
end

Instance Method Details

#add_label_by_name(label, page_id) ⇒ Object



81
82
83
84
85
86
# File 'lib/confluence-soap.rb', line 81

def add_label_by_name(label, page_id)
  response =
    @client.call(:add_label_by_name, auth_message({in1: label, in2: page_id}))

  parse_response(:add_label_by_name, response)
end

#execute(&block) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/confluence-soap.rb', line 101

def execute &block
  yield self
  rescue Savon::SOAPFault => e
    if e.to_hash[:fault][:faultstring] =~ /InvalidSessionException/
      reconnect
      yield e
    else
      raise e
    end
end

#get_children(page_id) ⇒ Object



48
49
50
51
52
# File 'lib/confluence-soap.rb', line 48

def get_children page_id
  response = @client.call :get_children, auth_message({in1: page_id})
  pages = parse_array_response :get_children, response
  pages.map { |page| Page.from_hash(page) }
end

#get_page(page_id) ⇒ Object



43
44
45
46
# File 'lib/confluence-soap.rb', line 43

def get_page page_id
  response = @client.call :get_page, auth_message({in1: page_id})
  Page.from_hash parse_response :get_page, response
end

#get_pages(space) ⇒ Object



37
38
39
40
41
# File 'lib/confluence-soap.rb', line 37

def get_pages space
  response = @client.call :get_pages, auth_message({in1: space})
  pages = parse_array_response :get_pages, response
  pages.map { |page| Page.from_hash(page) }
end

#has_user(user) ⇒ Object



96
97
98
99
# File 'lib/confluence-soap.rb', line 96

def has_user user
  response = @client.call(:has_user, auth_message({in1: user}))
  parse_response(:has_user, response)
end

#login(user, password) ⇒ Object



28
29
30
31
# File 'lib/confluence-soap.rb', line 28

def  user, password
  response = @client.call :login, message: {in0: user, in1: password}
  @token = response.body[:login_response][:login_return]
end

#logoutObject



33
34
35
# File 'lib/confluence-soap.rb', line 33

def logout
  @client.call :logout, message: {in0: @token} if @token
end

#remove_label_by_name(label, page_id) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/confluence-soap.rb', line 88

def remove_label_by_name(label, page_id)
  response =
    @client.call(:remove_label_by_name,
                 auth_message({in1: label, in2: page_id}))

  parse_response(:remove_label_by_name, response)
end

#remove_page(page_id) ⇒ Object



66
67
68
69
# File 'lib/confluence-soap.rb', line 66

def remove_page page_id
  response = @client.call :remove_page, auth_message({in1: page_id})
  Page.from_hash parse_response :remove_page, response
end

#search(term, criteria = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/confluence-soap.rb', line 71

def search(term, criteria = {})
  limit    = criteria.delete(:limit) || 20
  criteria = criteria.map { |k, v| {key: k, value: v} }
  response =
    @client.call(:search,
                 auth_message({in1: term, in2: {item: criteria}, in3: limit}))
  pages = parse_array_response :search, response
  pages.map { |page| Page.from_hash(page) }
end

#store_page(page) ⇒ Object



54
55
56
57
# File 'lib/confluence-soap.rb', line 54

def store_page page
  response = @client.call :store_page, auth_message({in1: page.to_soap})
  Page.from_hash parse_response :store_page, response
end

#update_page(page) ⇒ Object



59
60
61
62
63
64
# File 'lib/confluence-soap.rb', line 59

def update_page page
  response =
    @client.call(:update_page,
                 auth_message({in1: page.to_soap, in2: {minorEdit: true} }))
  Page.from_hash parse_response :update_page, response
end