confluencer 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/confluencer.gemspec +5 -2
- data/lib/confluence/bookmark.rb +19 -7
- data/lib/confluence/page.rb +49 -26
- data/lib/confluence/space.rb +18 -0
- data/lib/confluence/user.rb +19 -0
- data/lib/confluencer.rb +1 -0
- data/spec/confluence/bookmark_spec.rb +18 -0
- data/spec/confluence/page_spec.rb +58 -6
- data/spec/confluence/space_spec.rb +13 -0
- data/spec/confluence/user_spec.rb +24 -0
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/confluencer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{confluencer}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gabor Ratky"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-14}
|
13
13
|
s.description = %q{ActiveRecord-like classes to access Confluence through XMLRPC.}
|
14
14
|
s.email = %q{rgabo@rgabostyle.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/confluence/record.rb",
|
36
36
|
"lib/confluence/session.rb",
|
37
37
|
"lib/confluence/space.rb",
|
38
|
+
"lib/confluence/user.rb",
|
38
39
|
"lib/confluencer.rb",
|
39
40
|
"script/console",
|
40
41
|
"script/console_init.rb",
|
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
|
|
45
46
|
"spec/confluence/record_spec.rb",
|
46
47
|
"spec/confluence/session_spec.rb",
|
47
48
|
"spec/confluence/space_spec.rb",
|
49
|
+
"spec/confluence/user_spec.rb",
|
48
50
|
"spec/confluencer_spec.rb",
|
49
51
|
"spec/spec.opts",
|
50
52
|
"spec/spec_helper.rb"
|
@@ -61,6 +63,7 @@ Gem::Specification.new do |s|
|
|
61
63
|
"spec/confluence/record_spec.rb",
|
62
64
|
"spec/confluence/session_spec.rb",
|
63
65
|
"spec/confluence/space_spec.rb",
|
66
|
+
"spec/confluence/user_spec.rb",
|
64
67
|
"spec/confluencer_spec.rb",
|
65
68
|
"spec/spec_helper.rb"
|
66
69
|
]
|
data/lib/confluence/bookmark.rb
CHANGED
@@ -2,13 +2,28 @@ module Confluence
|
|
2
2
|
class Bookmark < Page
|
3
3
|
attr_accessor :bookmark_url, :description
|
4
4
|
|
5
|
+
BOOKMARK_REGEXP = /\{bookmark.*\}[^\{]*\{bookmark\}/
|
6
|
+
BOOKMARK_URL_REGEXP = /\{bookmark:url=([^\}]+)\}/
|
7
|
+
DESCRIPTION_REGEXP = /\{bookmark.*\}([^\{]*)\{bookmark\}/
|
8
|
+
|
5
9
|
def initialize(hash)
|
6
|
-
# set and delete bookmark_url and description
|
10
|
+
# set and delete bookmark_url and description coming from hash
|
7
11
|
@bookmark_url = hash.delete :bookmark_url
|
8
12
|
@description = hash.delete :description
|
9
13
|
|
10
14
|
# initialize page
|
11
15
|
super(hash)
|
16
|
+
|
17
|
+
if content
|
18
|
+
# if no bookmark_url from hash, initialize from content
|
19
|
+
unless @bookmark_url
|
20
|
+
@bookmark_url = content[BOOKMARK_URL_REGEXP, 1]
|
21
|
+
@description = content[DESCRIPTION_REGEXP, 1]
|
22
|
+
end
|
23
|
+
|
24
|
+
# remove {bookmark} macro from content
|
25
|
+
content.gsub!(BOOKMARK_REGEXP, "")
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
def [](attr)
|
@@ -40,11 +55,8 @@ module Confluence
|
|
40
55
|
def to_hash
|
41
56
|
page_hash = super
|
42
57
|
|
43
|
-
|
44
|
-
|
45
|
-
else
|
46
|
-
page_hash["content"] = bookmark_content
|
47
|
-
end
|
58
|
+
page_hash["content"] << "\n" unless page_hash["content"].empty?
|
59
|
+
page_hash["content"] << bookmark_content
|
48
60
|
|
49
61
|
page_hash
|
50
62
|
end
|
@@ -58,7 +70,7 @@ module Confluence
|
|
58
70
|
def self.find_criteria(args)
|
59
71
|
result = super(args) || begin
|
60
72
|
if args.key? :space
|
61
|
-
space = Space.find :
|
73
|
+
space = Space.find :key => args[:space]
|
62
74
|
space.bookmarks
|
63
75
|
end
|
64
76
|
end
|
data/lib/confluence/page.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
module Confluence
|
2
2
|
class Page < Record
|
3
3
|
class Details < Hash
|
4
|
+
REGEXP = /\{details:label=([^\}]+)\}([^\{}]*)\{details\}/m
|
5
|
+
PAIR_REGEXP = /([^:]+):([^\n]+)/m
|
6
|
+
|
4
7
|
attr_reader :label
|
5
8
|
|
6
|
-
def initialize(
|
7
|
-
@label = label
|
9
|
+
def initialize(args)
|
10
|
+
@label = args[:label]
|
11
|
+
|
12
|
+
parse(args[:content])
|
8
13
|
end
|
9
14
|
|
10
15
|
def to_s
|
@@ -12,14 +17,48 @@ module Confluence
|
|
12
17
|
content = "{details:label=#{label}}\n"
|
13
18
|
|
14
19
|
each_pair do |key, value|
|
15
|
-
content << "#{key}
|
20
|
+
content << "#{key}:#{value}\n"
|
16
21
|
end
|
17
22
|
|
18
23
|
# end of details macro
|
19
|
-
content << "{details}"
|
24
|
+
content << "{details}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse(content)
|
30
|
+
if content && content =~ REGEXP
|
31
|
+
# match label and the key/value pairs
|
32
|
+
@label, pairs = content.match(REGEXP).captures
|
33
|
+
|
34
|
+
pairs.strip.lines.each do |line|
|
35
|
+
if line =~ PAIR_REGEXP
|
36
|
+
self[$1.to_sym] = $2.strip
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
|
43
|
+
class DetailsCollection < Hash
|
44
|
+
def initialize(content)
|
45
|
+
if content
|
46
|
+
content.gsub!(Details::REGEXP) do |content|
|
47
|
+
self[$1.to_sym] = Details.new(:content => content)
|
48
|
+
""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def [](key)
|
54
|
+
super(key) or self[key] = Details.new(:label => key)
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
values.join("\n")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
23
62
|
extend Findable
|
24
63
|
|
25
64
|
record_attr_accessor :id => :page_id
|
@@ -29,26 +68,14 @@ module Confluence
|
|
29
68
|
record_attr_accessor :created, :modified, :version
|
30
69
|
record_attr_accessor :url
|
31
70
|
|
71
|
+
attr_accessor :details
|
72
|
+
|
32
73
|
def initialize(hash)
|
33
74
|
super(hash)
|
34
75
|
|
35
|
-
@details =
|
36
|
-
end
|
37
|
-
|
38
|
-
def details(label = :all)
|
39
|
-
return @details if label == :all
|
40
|
-
|
41
|
-
unless result = @details.find {|d| d.label == label}
|
42
|
-
@details << (result = Details.new(label))
|
43
|
-
end
|
44
|
-
|
45
|
-
result
|
76
|
+
@details = DetailsCollection.new(content)
|
46
77
|
end
|
47
|
-
|
48
|
-
def details=(value)
|
49
|
-
@details = value
|
50
|
-
end
|
51
|
-
|
78
|
+
|
52
79
|
def children(klass = self.class)
|
53
80
|
children = client.getChildren(page_id)
|
54
81
|
children.collect { |child| klass.find(:id => child["id"]) } if children
|
@@ -86,10 +113,10 @@ module Confluence
|
|
86
113
|
record_hash = super
|
87
114
|
|
88
115
|
# always include content in hash
|
89
|
-
record_hash[
|
116
|
+
record_hash["content"] ||= ""
|
90
117
|
|
91
118
|
# prepend details sections before content
|
92
|
-
record_hash[
|
119
|
+
record_hash["content"].insert(0, details.to_s)
|
93
120
|
|
94
121
|
# result
|
95
122
|
record_hash
|
@@ -97,10 +124,6 @@ module Confluence
|
|
97
124
|
|
98
125
|
private
|
99
126
|
|
100
|
-
def details_content
|
101
|
-
@details.join("\n") unless @details.empty?
|
102
|
-
end
|
103
|
-
|
104
127
|
def self.find_all
|
105
128
|
raise ArgumentError, "Cannot find all pages, find by id or title instead."
|
106
129
|
end
|
data/lib/confluence/space.rb
CHANGED
@@ -26,6 +26,24 @@ module Confluence
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def get_page(args)
|
30
|
+
args[:parent_title] ||= "Home"
|
31
|
+
|
32
|
+
# check if page already exists
|
33
|
+
find_page(args) or begin
|
34
|
+
# page does not exist yet, create it
|
35
|
+
page = Confluence::Page.new :space => self.key, :title => args[:title]
|
36
|
+
|
37
|
+
# look for the parent by title, set parentId if found
|
38
|
+
if parent_page = find_page(:title => args[:parent_title])
|
39
|
+
page.parent_id = parent_page.page_id
|
40
|
+
end
|
41
|
+
|
42
|
+
# store the page
|
43
|
+
page.store
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
29
47
|
private
|
30
48
|
|
31
49
|
def self.find_all
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Confluence
|
2
|
+
class User < Record
|
3
|
+
extend Findable
|
4
|
+
|
5
|
+
record_attr_accessor :name, :fullname, :email, :url
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.find_all
|
10
|
+
client.getActiveUsers(true).collect { |name| User.find :name => name }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find_criteria(args)
|
14
|
+
if args.key? :name
|
15
|
+
User.new(client.getUser(args[:name]))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/confluencer.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
3
|
describe Confluence::Bookmark do
|
4
|
+
include SessionHelperMethods
|
5
|
+
|
4
6
|
it "should initialize bookmark_url and description from hash" do
|
5
7
|
bookmark = Confluence::Bookmark.new :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home'
|
6
8
|
|
@@ -8,6 +10,15 @@ describe Confluence::Bookmark do
|
|
8
10
|
bookmark.description.should == 'Home sweet home'
|
9
11
|
end
|
10
12
|
|
13
|
+
it "should initialize bookmark_url and descrition from content" do
|
14
|
+
bookmark = Confluence::Bookmark.new "content" => "{bookmark:url=http://github.com/rgabo/confluencer}Home sweet home{bookmark}"
|
15
|
+
|
16
|
+
bookmark.bookmark_url.should == 'http://github.com/rgabo/confluencer'
|
17
|
+
bookmark.description.should == 'Home sweet home'
|
18
|
+
|
19
|
+
bookmark.content.should_not include "bookmark"
|
20
|
+
end
|
21
|
+
|
11
22
|
it "should get and set bookmark_url and description using #[]" do
|
12
23
|
bookmark = Confluence::Bookmark.new :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home'
|
13
24
|
|
@@ -32,4 +43,11 @@ describe Confluence::Bookmark do
|
|
32
43
|
bookmark.to_hash.key?('description').should be_false
|
33
44
|
bookmark.to_hash.key?('title').should be_true
|
34
45
|
end
|
46
|
+
|
47
|
+
it "should find bookmarks by space" do
|
48
|
+
new_session do
|
49
|
+
bookmarks = Confluence::Bookmark.find :space => "confluencer"
|
50
|
+
bookmarks.should_not be_empty
|
51
|
+
end
|
52
|
+
end
|
35
53
|
end
|
@@ -1,5 +1,50 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
+
describe Confluence::Page::Details do
|
4
|
+
it "should initialize with a label" do
|
5
|
+
details = Confluence::Page::Details.new :label => :confluencer
|
6
|
+
details.label.should == :confluencer
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return {details} macro" do
|
10
|
+
details = Confluence::Page::Details.new :label => :confluencer
|
11
|
+
details[:creator] = "rgabo"
|
12
|
+
|
13
|
+
details.to_s.should == <<-DETAILS
|
14
|
+
{details:label=confluencer}
|
15
|
+
creator:rgabo
|
16
|
+
{details}
|
17
|
+
DETAILS
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should initialize with macro content" do
|
21
|
+
details = Confluence::Page::Details.new :content => <<-DETAILS
|
22
|
+
{details:label=confluencer}
|
23
|
+
creator:rgabo
|
24
|
+
{details}
|
25
|
+
DETAILS
|
26
|
+
|
27
|
+
details.label.should == "confluencer"
|
28
|
+
details[:creator].should == "rgabo"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Confluence::Page::DetailsCollection do
|
33
|
+
it "should scan content for details" do
|
34
|
+
hash = Confluence::Page::DetailsCollection.new <<-CONTENT
|
35
|
+
{details:label=confluencer}
|
36
|
+
creator:rgabo
|
37
|
+
{details}
|
38
|
+
|
39
|
+
{details:label=ruby}
|
40
|
+
creator=matz
|
41
|
+
{details}
|
42
|
+
CONTENT
|
43
|
+
|
44
|
+
hash.should include(:confluencer)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
3
48
|
describe Confluence::Page do
|
4
49
|
include SessionHelperMethods
|
5
50
|
|
@@ -94,27 +139,34 @@ describe Confluence::Page do
|
|
94
139
|
page = store_test_page
|
95
140
|
|
96
141
|
# set :creator in {details:label=bender} to 'rgabo'
|
97
|
-
page.details
|
142
|
+
page.details[:confluencer][:creator] = 'rgabo'
|
98
143
|
|
99
|
-
page.details
|
144
|
+
page.details[:confluencer][:creator].should == 'rgabo'
|
100
145
|
end
|
101
146
|
|
102
147
|
it "should include metadata in content of the page" do
|
103
148
|
page = store_test_page
|
104
149
|
|
105
150
|
# set :creator in {details:label=bender} to 'rgabo'
|
106
|
-
page.details
|
151
|
+
page.details[:confluencer][:creator] = 'rgabo'
|
107
152
|
|
108
|
-
page.to_hash['content'].should include("{details:label=confluencer}\ncreator
|
153
|
+
page.to_hash['content'].should include("{details:label=confluencer}\ncreator:rgabo\n{details}")
|
109
154
|
end
|
110
155
|
|
111
156
|
it "should copy metadata from one page to another" do
|
112
157
|
page = create_test_page
|
113
|
-
page.details
|
158
|
+
page.details[:confluencer][:creator] = 'rgabo'
|
114
159
|
|
115
160
|
new_page = create_test_page
|
116
161
|
new_page.details = page.details
|
117
162
|
|
118
|
-
new_page.details
|
163
|
+
new_page.details[:confluencer][:creator].should == 'rgabo'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should parse metadata from content" do
|
167
|
+
page = Confluence::Page.new "content" => "{details:label=confluencer}\ncreator:rgabo\n{details}\nh3. Some other content"
|
168
|
+
|
169
|
+
page.details[:confluencer][:creator].should == "rgabo"
|
119
170
|
end
|
120
171
|
end
|
172
|
+
|
@@ -46,4 +46,17 @@ describe Confluence::Space do
|
|
46
46
|
bookmark.remove
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
it "should get a page and create if it does not exist" do
|
51
|
+
new_session do
|
52
|
+
# get page with random name
|
53
|
+
random_page = test_space.get_page :title => "RandomPage #{rand(10000)}"
|
54
|
+
|
55
|
+
random_page.should_not be_nil
|
56
|
+
random_page.space == test_space.key
|
57
|
+
|
58
|
+
# remove random_page afterwards
|
59
|
+
random_page.remove
|
60
|
+
end
|
61
|
+
end
|
49
62
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe Confluence::User do
|
4
|
+
include SessionHelperMethods
|
5
|
+
|
6
|
+
it "should find all users" do
|
7
|
+
new_session do
|
8
|
+
users = Confluence::User.find :all
|
9
|
+
users.should_not be_empty
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should find a user by its name" do
|
14
|
+
new_session do
|
15
|
+
# find all users
|
16
|
+
users = Confluence::User.find :all
|
17
|
+
|
18
|
+
# find first user by name
|
19
|
+
first_user = Confluence::User.find :name => users.first.name
|
20
|
+
|
21
|
+
first_user.name.should == users.first.name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 3
|
9
|
+
version: 0.4.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gabor Ratky
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-14 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/confluence/record.rb
|
74
74
|
- lib/confluence/session.rb
|
75
75
|
- lib/confluence/space.rb
|
76
|
+
- lib/confluence/user.rb
|
76
77
|
- lib/confluencer.rb
|
77
78
|
- script/console
|
78
79
|
- script/console_init.rb
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- spec/confluence/record_spec.rb
|
84
85
|
- spec/confluence/session_spec.rb
|
85
86
|
- spec/confluence/space_spec.rb
|
87
|
+
- spec/confluence/user_spec.rb
|
86
88
|
- spec/confluencer_spec.rb
|
87
89
|
- spec/spec.opts
|
88
90
|
- spec/spec_helper.rb
|
@@ -123,5 +125,6 @@ test_files:
|
|
123
125
|
- spec/confluence/record_spec.rb
|
124
126
|
- spec/confluence/session_spec.rb
|
125
127
|
- spec/confluence/space_spec.rb
|
128
|
+
- spec/confluence/user_spec.rb
|
126
129
|
- spec/confluencer_spec.rb
|
127
130
|
- spec/spec_helper.rb
|