Class: Confluence::Client
- Inherits:
-
Object
- Object
- Confluence::Client
- Defined in:
- lib/confluence/client.rb
Overview
A useful helper for running Confluence XML-RPC from Ruby. Takes care of adding the token to each method call (so you can call server.getSpaces() instead of server.getSpaces(token)).
Usage:
client = Confluence::Client.new(:url => "confluence.atlassian.com") client.login("user", "password") p client.getSpaces
Constant Summary
- PREFIX =
"confluence1"- XMLRPC_SUFFIX =
"/rpc/xmlrpc"
Instance Attribute Summary (collapse)
-
- (Object) token
readonly
Returns the value of attribute token.
-
- (Object) url
readonly
Returns the value of attribute url.
-
- (Object) username
readonly
Returns the value of attribute username.
Instance Method Summary (collapse)
-
- (Boolean) has_token?
Returns true, if the client has a session token.
-
- (Client) initialize(arguments = {})
constructor
Initializes a new client with the given arguments.
-
- (Object) login(username, password)
Logs in and returns the newly acquired session token.
-
- (Object) logout
Logs out and invalidates the session token.
-
- (Object) method_missing(method_name, *args)
Translates every call into XMLRPC calls.
Constructor Details
- (Client) initialize(arguments = {})
Initializes a new client with the given arguments.
Parameters
arguments<Hash> |
Described below. |
Arguments
:url - The url of the Confluence instance. The trailing '/rpc/xmlrpc' path is optional. :token - An existing session token to reuse.
32 33 34 35 36 37 38 |
# File 'lib/confluence/client.rb', line 32 def initialize(arguments = {}) @url = arguments[:url] @token = arguments[:token] Log4r::MDC.put('token', @token || 'nil') log.info "initialized client (:url => #{@url}, :token => #{@token || 'nil'})" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_name, *args)
Translates every call into XMLRPC calls.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/confluence/client.rb', line 79 def method_missing(method_name, *args) handle_fault do if args.empty? log.debug "#{method_name}" else log.debug "#{method_name}(#{(args.collect {|a| a.inspect}).join(', ')})" end begin result = proxy.send(method_name, *([@token] + args)) log.debug(result.inspect) result rescue EOFError => e log.warn "Could not complete XMLRPC call, retrying... Error: #{e.inspect}" retry end end end |
Instance Attribute Details
- (Object) token (readonly)
Returns the value of attribute token
21 22 23 |
# File 'lib/confluence/client.rb', line 21 def token @token end |
- (Object) url (readonly)
Returns the value of attribute url
21 22 23 |
# File 'lib/confluence/client.rb', line 21 def url @url end |
- (Object) username (readonly)
Returns the value of attribute username
21 22 23 |
# File 'lib/confluence/client.rb', line 21 def username @username end |
Instance Method Details
- (Boolean) has_token?
Returns true, if the client has a session token.
42 43 44 |
# File 'lib/confluence/client.rb', line 42 def has_token? !@token.nil? end |
- (Object) login(username, password)
Logs in and returns the newly acquired session token.
Parameters
username<String> |
The username. |
password<String> |
The password. |
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/confluence/client.rb', line 52 def login(username, password) handle_fault do if @token = proxy.login(username, password) Log4r::MDC.put('token', @token) log.info "logged in as '#{username}' and acquired token." @username = username @password = password end end @token end |
- (Object) logout
Logs out and invalidates the session token.
68 69 70 71 72 73 74 75 |
# File 'lib/confluence/client.rb', line 68 def logout handle_fault do @token = nil if @token and result = proxy.logout(@token) log.info "logged out" Log4r::MDC.put('token', 'nil') result end end |