Class: Confluence::Connector

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connector

Returns a new instance of Connector.



10
11
12
13
14
15
16
# File 'lib/confluence/confluence_connector.rb', line 10

def initialize(options = {})
  load_confluence_config
  @url ||= options[:url]
  @username = options[:username] || @username
  @password = options[:password] || @password
  @default_service = options[:service] || 'confluence1'
end

Instance Attribute Details

#admin_proxy_passwordObject

Returns the value of attribute admin_proxy_password.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def admin_proxy_password
  @admin_proxy_password
end

#admin_proxy_usernameObject

Returns the value of attribute admin_proxy_username.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def admin_proxy_username
  @admin_proxy_username
end

#default_serviceObject

Returns the value of attribute default_service.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def default_service
  @default_service
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def password
  @password
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def url
  @url
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/confluence/confluence_connector.rb', line 7

def username
  @username
end

Class Method Details

.through_admin_proxyObject

The given block will be executed using another account, as set in the confluence.yml file under admin_proxy_username and admin_proxy_password. This is useful when you want to execute some function that requires admin privileges. You will of course have to set up a corresponding account on your Confluence server with administrative rights.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/confluence/confluence_connector.rb', line 47

def self.through_admin_proxy
  super_connector = Confluence::Connector.new
  
  raise "Cannot execute through_admin_proxy because the admin_proxy_username has not been set." unless super_connector.admin_proxy_username
  raise "Cannot execute through_admin_proxy because the admin_proxy_password has not been set." unless super_connector.admin_proxy_password
  
  super_connector.username = super_connector.admin_proxy_username
  super_connector.password = super_connector.admin_proxy_password
  
  normal_connector = Confluence::RemoteDataObject.connector
  Confluence::RemoteDataObject.connector = super_connector
  
  yield
  
  Confluence::RemoteDataObject.connector = normal_connector
end

Instance Method Details

#connect(service = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/confluence/confluence_connector.rb', line 18

def connect(service = nil)
  unless url and username and password and service || default_service
    raise "Cannot get Confluence::RPC instance because the confluence url, username, password, or service have not been set"
  end
  
  rpc = Confluence::RPC.new(url, service || default_service)
  rpc.(username, password)

  return rpc
end

#load_confluence_configObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/confluence/confluence_connector.rb', line 29

def load_confluence_config
  conf_path = File.expand_path("~/.confluence.yml")
  conf = if File.exist?(conf_path)
           YAML.load_file(conf_path)
         else
           {}
         end
  @url = conf['url'] || conf[:url]
  @default_service = conf['service'] || conf[:service]
  @username = conf['username'] || conf[:username]
  @password = conf['password'] || conf[:password]
  @admin_proxy_username = conf['admin_proxy_username'] || conf[:admin_proxy_username]
  @admin_proxy_password = conf['admin_proxy_password'] || conf[:admin_proxy_password]
end