confluence-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .*.swp
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ out.txt
6
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in confluence-client.gemspec
4
+ gemspec
data/HISTORY ADDED
@@ -0,0 +1,3 @@
1
+ 2011-04-01 v0.0.1
2
+ - Initial prototype release.
3
+
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = Confluence::Client - Ruby client for the Confluence XML::RPC API.
2
+
3
+ == Usage
4
+
5
+ Confluence::Client.new(url) do |confluence|
6
+
7
+ # Login
8
+ confluence.login(user, pass)
9
+
10
+ # Logout
11
+ confluence.logout
12
+
13
+ end
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "confluence-client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "confluence-client"
7
+ s.version = Confluence::Client::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Blair Christensen']
10
+ s.email = ['blair.christensen@gmail.com']
11
+ s.homepage = 'https://github.com/blairc/confluence-client'
12
+ s.summary = %q{Ruby client for the Confluence XML::RPC API}
13
+ s.description = %q{Ruby client for the Confluence XML::RPC API}
14
+
15
+ s.rubyforge_project = "confluence-client"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency( %q<rspec>, [ ">=2.5.0" ] )
23
+ end
@@ -0,0 +1,5 @@
1
+ module Confluence
2
+ class Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,86 @@
1
+ require 'xmlrpc/client'
2
+
3
+ module Confluence # :nodoc:
4
+ # = Confluence::Client - Ruby client for the Confluence XML::RPC API.
5
+ #
6
+ # == Usage
7
+ #
8
+ # Confluence::Client.new(url) do |confluence|
9
+ #
10
+ # # Login
11
+ # confluence.login(user, pass)
12
+ #
13
+ # # Logout
14
+ # confluence.logout
15
+ #
16
+ # end
17
+ class Client
18
+
19
+ # Error message from last request (if any).
20
+ attr_reader :error
21
+ # Security token.
22
+ attr_reader :token
23
+
24
+ # Create new Confluence client.
25
+ #
26
+ # Params:
27
+ # +url+:: Base URL for the Confluence XML/RPC API. 'rpc/xmlrpc' appended if not present.
28
+ def initialize(url)
29
+ raise ArgumentError if url.nil? || url.empty?
30
+ url += '/rpc/xmlrpc' unless url =~ /\/rpc\/xmlrpc$/
31
+ @server = XMLRPC::Client.new2(url)
32
+ @server.timeout = 305 # XXX
33
+ @confluence = @server.proxy_async('confluence1') # XXX
34
+
35
+ @error = nil
36
+ @password = nil
37
+ @token = nil
38
+ @user = nil
39
+
40
+ yield self if block_given?
41
+ end
42
+
43
+ # Was there an error on the last request?
44
+ def error?
45
+ !ok?
46
+ end
47
+
48
+ # Login to the Confluence XML/RPC API.
49
+ def login(user, password)
50
+ raise ArgumentError if user.nil? || password.nil?
51
+ @user, @password = user, password
52
+ begin
53
+ @token = @confluence.login(@user, @password)
54
+ @error = nil
55
+ rescue XMLRPC::FaultException => e
56
+ @error = e.faultString
57
+ rescue => e
58
+ @error = e.message
59
+ end
60
+ return ok?
61
+ end
62
+
63
+ def method_missing(method_name, *args)
64
+ unless @token
65
+ @error = "not authenticated"
66
+ return false
67
+ end
68
+ begin
69
+ @error = nil
70
+ return @confluence.send( method_name, *( [@token] + args ) )
71
+ rescue XMLRPC::FaultException => e
72
+ @error = e.faultString
73
+ rescue Exception => e
74
+ @error = e.message
75
+ end
76
+ return ok?
77
+ end
78
+
79
+ # Was the last request successful?
80
+ def ok?
81
+ @error.nil?
82
+ end
83
+
84
+ end # class Client
85
+ end # module Confluence
86
+
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Confluence" do
4
+
5
+ before(:each) do
6
+ @url = 'http://example.org'
7
+ @user = 'user'
8
+ @pass = 'password'
9
+ end
10
+
11
+
12
+ describe "Client initialization" do
13
+
14
+ context "with no arguments" do
15
+ it "should raise ArgumentError" do
16
+ lambda { Confluence::Client.new }.should raise_error(ArgumentError)
17
+ end
18
+ end
19
+
20
+ context "with one argument" do
21
+
22
+ context "that is invalid" do
23
+ it "should raise ArgumentError when nil" do
24
+ lambda { Confluence::Client.new(nil) }.should raise_error(ArgumentError)
25
+ end
26
+ it "should raise ArgumentError when blank" do
27
+ lambda { Confluence::Client.new('') }.should raise_error(ArgumentError)
28
+ end
29
+ end
30
+
31
+ context "that is string" do
32
+ it "should raise RuntimeError when not a URL" do
33
+ lambda { Confluence::Client.new(@user) }.should raise_error(RuntimeError, 'Wrong URI as parameter!' )
34
+ end
35
+ it "should not raise errors when given URL" do
36
+ lambda { Confluence::Client.new(@url) }.should_not raise_error
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+
45
+ describe "Client#login" do
46
+
47
+ before(:each) do
48
+ @confluence = Confluence::Client.new(@url)
49
+ end
50
+
51
+ context "with invalid arguments" do
52
+ it "should raise ArgumentError with no arguments" do
53
+ lambda { @confluence.login() }.should raise_error(ArgumentError)
54
+ end
55
+ it "should raise ArgumentError with not enough arguments" do
56
+ lambda { @confluence.login(@user) }.should raise_error(ArgumentError)
57
+ end
58
+ it "should raise ArgumentError with too many arguments" do
59
+ lambda { @confluence.login(@user, @pass, @pass) }.should raise_error(ArgumentError)
60
+ end
61
+ it "should raise ArgumentError when :user is nil" do
62
+ lambda { @confluence.login(nil, @pass) }.should raise_error(ArgumentError)
63
+ end
64
+ it "should raise ArgumentError when :password is nil" do
65
+ lambda { @confluence.login(@user, nil) }.should raise_error(ArgumentError)
66
+ end
67
+ end
68
+
69
+ context "with successful login" do
70
+ it "should return security token" do
71
+ token = 'some security token'
72
+ @confluence.stub(:login).with(@user, @pass) { token }
73
+ @confluence.login(@user, @pass).should be(token)
74
+ end
75
+ end
76
+
77
+ # TODO Pointless test
78
+ context "with unsuccessful login" do
79
+ it "should raise XMLRPC::FaultException" do
80
+ @confluence.should_receive(:login).with(@user, @pass).and_raise( XMLRPC::FaultException.new(:faultCode, :faultString) )
81
+ lambda { @confluence.login(@user, @pass) }.should raise_error(XMLRPC::FaultException)
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,2 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'lib', 'confluence-client' )
2
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confluence-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Blair Christensen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-04-01 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &2157279640 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2157279640
26
+ description: Ruby client for the Confluence XML::RPC API
27
+ email:
28
+ - blair.christensen@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - HISTORY
36
+ - README.rdoc
37
+ - Rakefile
38
+ - confluence-client.gemspec
39
+ - lib/confluence-client.rb
40
+ - lib/confluence-client/version.rb
41
+ - spec/confluence_spec.rb
42
+ - spec/spec_helper.rb
43
+ has_rdoc: true
44
+ homepage: https://github.com/blairc/confluence-client
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: confluence-client
64
+ rubygems_version: 1.6.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Ruby client for the Confluence XML::RPC API
68
+ test_files:
69
+ - spec/confluence_spec.rb
70
+ - spec/spec_helper.rb